15,911,715 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 10701701 (Top 17 by date)
Member 10701701
16-Apr-14 10:39am
View
should have been by
Member 10701701
16-Apr-14 9:34am
View
Thanks for the info Nevjc
Member 10701701
16-Apr-14 6:47am
View
Thanks for that I will give it a try
Nevjc
Member 10701701
16-Apr-14 6:44am
View
Hi idle63. Yes you are correct it hangs while closing the serial port. It yellows out str2 As String = sp.Readline. It does work about 10% of the time unless I slow down the Data Rate coming in to the serial port and then the percentage of reliablility goes up.
Does that help? Nevjc
Member 10701701
16-Apr-14 5:08am
View
Thank you F.Xaver. The original software only had one temperature display with one readline and it still hung with the speed of the stream. I added the second read and I originally tried the substring code but it wouldnt work. The mid routine was the only one that did.
I will give it another try.
Thanks for the help Nevjc
Member 10701701
16-Apr-14 5:03am
View
Thanks for the links Sergey. At this stage this is a very basic prototype I am working on and I am trying to get it to a reasonable point that my friend can run it as proof of concept. If that is sucessful then i would need the code written professionally buy someone like your self. I started the project in the analog domain and only recently decided to use computor to read results and I have just got hooked into trying to get it to work but the code is to complicated for me. I am happy with the operation at the moment it would be nice just to sort a couple of the niggles out. Thanks again Nevjc
Member 10701701
12-Apr-14 8:41am
View
Thank you for the info. I just thought there might be a simple way in tweaking the current code but not as simple as just adding a formula. I tried the obvious but it purly returns an instantanious figure not a continious stream as required. Thank you for your suggestions I guess I need to get down to some serious reading.
Regards Nevjc
Member 10701701
11-Apr-14 12:57pm
View
Thanks for your reply. Sorry I am a complete novice and picked this code up from the internet and tweaked it a little to get what I wanted it to do. I dont really understand your suggestions.
thanks anyway Nevjc
Member 10701701
11-Apr-14 12:54pm
View
Hi Wes
I tried the simple way but it dosnt work. It only returns an instataneous conversion not the continuous string that I need.
Thanks Nevjc
Member 10701701
9-Apr-14 9:14am
View
Thank you Bernhard that has sorted it.
Member 10701701
27-Mar-14 14:32pm
View
Hi added 1 substring as per suggestion. Code works 20% of the time and displays number but comes up with the folowing error
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
My altered code
Delegate Sub myMethodDelegate(ByVal text As String)
Dim myDelegate As New myMethodDelegate(AddressOf ProcessReading)
Private Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles sp.DataReceived
Dim onestr As String = sp.ReadLine()
Dim twostr As String
twostr = onestr.Substring(0, 4)
Invoke(myDelegate, onestr)
End Sub
Sub ProcessReading(ByVal input As String)
If IsNumeric(input) Then
temperature = CDbl(input)
picTherm.Refresh()
Label1.Text = CDbl(input)
Label2.Text = CDbl(input) * 2
End If
End Sub
Member 10701701
27-Mar-14 10:41am
View
It appears okay now
Nevjc
Member 10701701
27-Mar-14 10:34am
View
Deleted
Hi this is the complete code that draws a temperature display. I only put the relevant part in my first post.
Regards Nevjc
Imports System.Drawing.Drawing2D
Imports System.IO.Ports
Public Class Form1
Dim bmp As Bitmap = New Bitmap(100, 600)
Dim temperature1 As Double = 10
Dim WithEvents sp As New SerialPort
Private Sub picTherm_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picTherm.Paint
Dim g As Graphics = Graphics.FromImage(bmp)
g.Clear(Color.White)
' fill temperature
If temperature1 > 100 Then temperature1 = 100
If temperature1 < 0 Then temperature1 = 0
g.FillRectangle(Brushes.Red, 48, 550 - CInt(temperature1 * 5), 4, CInt(temperature1 * 5))
'draw scale
g.DrawLine(Pens.Black, 45, 550, 45, 50)
' minor ticks
For i As Integer = 50 To 550 Step 5
g.DrawLine(Pens.Black, 45, i, 48, i)
Next
'major ticks
Dim f As Font = New Font("Verdana", 8, FontStyle.Regular)
Dim scale As Integer
For i As Integer = 550 To 50 Step -25
g.DrawLine(Pens.Black, 45, i, 55, i)
scale = (550 - i) / 5
g.DrawString(Str(scale), f, Brushes.Black, 10, i - 8)
Next
picTherm.Image = bmp
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
End Sub
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
Try
sp.BaudRate = "9600"
sp.PortName = "COM5"
sp.Open()
If sp.IsOpen Then
btnConnect.Visible = False
btnDisconnect.Visible = True
End If
Catch
sp.Close()
End Try
End Sub
Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
Try
sp.Close()
btnConnect.Visible = True
btnDisconnect.Visible = False
Exit Sub
Catch
MessageBox.Show("Some kind of problem.")
End Try
End Sub
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If sp.IsOpen() Then
MessageBox.Show("Disconnect before closing")
e.Cancel = True
End If
End Sub
Delegate Sub myMethodDelegate(ByVal text As String)
Dim myDelegate As New myMethodDelegate(AddressOf ProcessReading)
Private Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles sp.DataReceived
Dim str As String = sp.ReadLine()
Invoke(myDelegate, Str)
End Sub
Sub ProcessReading(ByVal input As String)
If IsNumeric(Input) Then
temperature1 = CDbl(input)
picTherm.Refresh()
Label1.Text = CDbl(input)
Label2.Text = CDbl(input) * 2
Label3.Text = CDbl(input) / 2
End If
End Sub
End Class
Member 10701701
27-Mar-14 10:26am
View
Thanks for that I will give it a go.
Thanks for the help Nevjc
Member 10701701
27-Mar-14 7:55am
View
Hi,
I added : sp.ReadLine() to the readline but it did not work continuosly it seems to read the second string occasionaly or otherwise blank.
Thanks for the help.
Member 10701701
27-Mar-14 5:57am
View
Hi,
Thanks for your comment. I have to admit I am a complete novice at this and I am using Visual Basic 2010 Express. I would appreciate any help. The two streams of code come off an Arduino board to a USB port and are shown by the serial monitor in the following form
67.7 51.2
67.6 51.3
Thank you for your help
Nevjc
Member 10701701
27-Mar-14 5:55am
View
Hi,
Thanks for your comment. I have to admit I am a complete novice at this and do not know visual basic code. I would appreciate any help. The two streams of code come off an Arduino board to a USB port and are shown by the serial monitor in the following form
67.7 51.2
67.6 51.3
Thank you for your help
Nevjc
Show More