B4J Question my jserial problem

sot bel

Member
Hello

I try to read string messages from serial port but messages comes splited.

Here is the code

-------------------------------------------------------------------------
Sub Process_Globals
Private sp As Serial
Private astream As AsyncStreams
End Sub

Sub AppStart (Form1 As Form, Args() As String)

sp.Initialize("sp")

Log(sp.ListPorts)

sp.Open("COM3") '*** COM PORT ***
sp.SetParams(9600, 8, 1, 0) '*** BAUD RATE ***

astream.Initialize(sp.GetInputStream, sp.GetOutputStream, "astream")

End Sub

Sub AStream_NewData (Buffer() As Byte)

Dim LogHeader As String = DateTime.Now & " " & Buffer.Length & " :"

Dim LogBytes As String = ""
For I = 0 To Buffer.Length - 1
LogBytes = LogBytes & " " & Buffer(I)
Next


Dim LogString As String = BytesToString(Buffer, 0, Buffer.Length, "UTF8")

Log(LogString)
End Sub


------------------------------------------------------------------------
log window
-------------



Temperature for the device
1 (index 0) is: 28.12
Requesti
ng temperatures...
DONE
Temperature for the device
1 (index 0) is: 28.12
Requesti
ng temperatures...
DONE
Temperature for the device
1 (index 0) is: 28.00
Requesti
ng temperatures...
DONE
Temperature for the device
1 (index 0) is: 28.12
Requesti
ng temperatures...
DONE
Temperature for the device
1 (index 0) is: 28.19
Requesti
ng temperatures...
DONE
Temperature for the device
1 (index 0) is: 28.06
Requesti
ng temperatures...

-----------------------------------------------------------------------------------
what i expect
----------------


Dallas Temperature IC Control Library Demo
Requesting temperatures...DONE
Temperature for the device 1 (index 0) is: 28.25
Requesting temperatures...DONE
Temperature for the device 1 (index 0) is: 28.25
Requesting temperatures...DONE
Temperature for the device 1 (index 0) is: 28.25
Requesting temperatures...DONE
Temperature for the device 1 (index 0) is: 28.25
Requesting temperatures...DONE
Temperature for the device 1 (index 0) is: 28.25
Requesting temperatures...DONE
Temperature for the device 1 (index 0) is: 28.25
Requesting temperatures...DONE
Temperature for the device 1 (index 0) is: 28.06
Requesting temperatures...DONE
Temperature for the device 1 (index 0) is: 28.06
Requesting temperatures...DONE
Temperature for the device 1 (index 0) is: 28.06
Requesting temperatures...DONE
Temperature for the device 1 (index 0) is: 28.06
Requesting temperatures...DONE
Temperature for the device 1 (index 0) is: 28.19
Requesting temperatures...DONE
Temperature for the device 1 (index 0) is: 28.19
Requesting temperatures...DONE
 
This always happens with serial comms. This has been discussed several times on this forum. You just have to deal with it. Tip - if there is a known delimiter to the message use AsyncStreamsText. You might have to change the terminating character but it will deal with putting the data together.
 
Upvote 0
Back
Top