Hi malc-c;
Hi use a function in VB, that does do the job, that you want, but you must send to VB more things;
You are sending 4 temperatures, i supose from 4 diferent sensors, 1 temperatura measure for each sensor.
So if you put something before sendig the temperatures to identify de sensor, like this for exemple;
You are Sending;
002610
002660
002680
002680
Ff you send;
S1002610
S2002660
S3002680
S4002680
The 2 first chars, are the ID of the sensor, and the 6 next chars are the temperature.
Now it's easy to separate them in VB, with the function "Mid",
On the event Data Received, you must do something like this;
Code:
Private Sub DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Dim buffer As String
buffer = SerialPort1.ReadExisting
If Mid(buffer, 1, 2) = "S1" Then
Label1.Text = Mid(buffer, 3, 6) ' label to show the temperature of 1º sensor
End If
If Mid(buffer, 1, 2) = "S2" Then
Label2.Text = Mid(buffer, 3, 6) ' label to show the temperature of 2º sensor
End If
If Mid(buffer, 1, 2) = "S3" Then
Label3.Text = Mid(buffer, 3, 6) ' label to show the temperature of 3º sensor
End If
If Mid(buffer, 1, 2) = "S4" Then
Label4.Text = Mid(buffer, 3, 6) ' label to show the temperature of 4º sensor
End If
End Sub
You can use it too in a Select case, and you should put a try....cath too.
If you don't understanding something, please tell me.
Bookmarks