Hi All,
I use the Jserial lib (v. 1.31) to read from serial port. I did a small class to do this. Nothing special, but I can't read anything, except if I place a brakpoint at some lines.
form code:
Here is the relevant class code. If I put a breakpoint one of signed line, the program can only read from serial port!
If I put a short delay without breakpoint, then can't read. No error message, just simple no read.
Can somebody experieced problem like this?
I use the Jserial lib (v. 1.31) to read from serial port. I did a small class to do this. Nothing special, but I can't read anything, except if I place a brakpoint at some lines.
form code:
B4X:
Sub Process_Globals
...
Private ser As MerlegClass
...
End Sub
Public Sub Show
...
ser.Initialize(Me)
End Sub
Private Sub btnMeresTeszt_Click
ser.setparam2(cmbComPort.Value,cmbComSpeed.Value,cmbComPar.Value,cmbProtokoll.Value)
If ser.openport() Then
Sleep(1)
ser.startmeres
wait for serial_result (receivedstr As String)
xui.MsgboxAsync("Data received" & receivedstr,"INFO")
Wait For Msgbox_Result (SResult As Int)
ser.closeport
Else
xui.MsgboxAsync("Can't open.","HIBA")
End If
End Sub
If I put a short delay without breakpoint, then can't read. No error message, just simple no read.
B4X:
public Sub openport As Boolean
If com.ListPorts.IndexOf(comparam.port) > -1 Then
If opened Then
closeport
End If
Try
'Breakpoint here
com.Open(comparam.port)
com.SetParams(comparam.speed,comparam.databit,comparam.stopbit,comparam.parity)
astream.Initialize(com.GetInputStream, com.GetOutputStream, "astream")
opened = True
Log($"${comparam.port} opened"$)
Return True
Catch
Log(LastException)
Return False
End Try
Else
Return False
End If
End Sub
public Sub startmeres
'Breakpoint here
Log($"${comparam.port} data sending"$)
Select comparam.protokoll
Case "F501"
Dim b() As Byte = Array As Byte (2,5,3)
astream.Write(b)
Case "Dollar"
astream.Write("$".GetBytes("ASCII"))
End Select
End Sub
'----------------------------------------------------------
'can't happen AStream_NewData without a brekpoint
Sub AStream_NewData (Buffer() As Byte)
Dim s As String = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
Log($"${comparam.port} data arrived ${s}"$)
If SubExists(resobj,"serial_result") Then
CallSubDelayed2(resobj,"serial_result",s)
Else
Log($"serial_result not found!"$)
End If
End Sub