T ThiagoRodrigues Member Licensed User Longtime User Oct 6, 2013 #1 Hello, I am using the GPS_NMEA event to collect raw NMEA strings ($GPRMC), and I have to append the string ",AUTO" at the end of it before sending it over a socket connection. Code (network code no shown): Sub GPS_NMEA (TimeStamp As Long, Sentence As String) If Sentence.Contains("$GPRMC") Then sb1.Initialize sb1.Append(Sentence).Append(",").Append("AUTO") tw.Write(sb1) tw.Flush End If End Sub When sending the sb1 string to a label, the order is correct, "AUTO" is at the end. But when sending to a TCP socket, the "AUTO" comes first. I´ve never seen this behaviour... Any ideas? Regards,
Hello, I am using the GPS_NMEA event to collect raw NMEA strings ($GPRMC), and I have to append the string ",AUTO" at the end of it before sending it over a socket connection. Code (network code no shown): Sub GPS_NMEA (TimeStamp As Long, Sentence As String) If Sentence.Contains("$GPRMC") Then sb1.Initialize sb1.Append(Sentence).Append(",").Append("AUTO") tw.Write(sb1) tw.Flush End If End Sub When sending the sb1 string to a label, the order is correct, "AUTO" is at the end. But when sending to a TCP socket, the "AUTO" comes first. I´ve never seen this behaviour... Any ideas? Regards,
JakeBullet70 Well-Known Member Licensed User Longtime User Oct 7, 2013 #2 try Code: Copy tw.write(sb1.ToString) Upvote 0
T ThiagoRodrigues Member Licensed User Longtime User Oct 7, 2013 #3 No good... Log on PC side: Received from 192.168.1.101: ',AUTO$GPRMC,,V,,,,,,,,,,N*53' Received from 192.168.1.101: ',AUTO$GPRMC,,V,,,,,,,,,,N*53' Received from 192.168.1.101: ',AUTO$GPRMC,,V,,,,,,,,,,N*53' Upvote 0
No good... Log on PC side: Received from 192.168.1.101: ',AUTO$GPRMC,,V,,,,,,,,,,N*53' Received from 192.168.1.101: ',AUTO$GPRMC,,V,,,,,,,,,,N*53' Received from 192.168.1.101: ',AUTO$GPRMC,,V,,,,,,,,,,N*53'
JakeBullet70 Well-Known Member Licensed User Longtime User Oct 7, 2013 #4 interesting... try Code: Copy dim s as string = sb1.ToString log(s) tw.write(s) that way you can tell if it is the string builder or the sending routine Upvote 0
interesting... try Code: Copy dim s as string = sb1.ToString log(s) tw.write(s) that way you can tell if it is the string builder or the sending routine
T ThiagoRodrigues Member Licensed User Longtime User Oct 7, 2013 #5 Yep, I did something similar to that previously... No success... I guess this issue is related to the GPS_NMEA event... I have used this same method of TCP sockets tranmissions several times and never seen that happening... even with GPS_LocationChanged it works... Complete code: Sub GPS_NMEA (TimeStamp As Long, Sentence As String) If Sentence.Contains("$GPRMC") Then If Socket1.Connected = False Then Socket1.Connect("192.168.1.100", 1024, 2000) Else Dim s As String tw.Initialize(Socket1.OutputStream) sb1.Initialize sb1.Append(Sentence).Append(",").Append("AUTO") s = sb1.ToString tw.WriteLine(s) lblLon.Text = s tw.Flush End If End If End Sub Sorry, it lost the indentation... Last edited: Oct 7, 2013 Upvote 0
Yep, I did something similar to that previously... No success... I guess this issue is related to the GPS_NMEA event... I have used this same method of TCP sockets tranmissions several times and never seen that happening... even with GPS_LocationChanged it works... Complete code: Sub GPS_NMEA (TimeStamp As Long, Sentence As String) If Sentence.Contains("$GPRMC") Then If Socket1.Connected = False Then Socket1.Connect("192.168.1.100", 1024, 2000) Else Dim s As String tw.Initialize(Socket1.OutputStream) sb1.Initialize sb1.Append(Sentence).Append(",").Append("AUTO") s = sb1.ToString tw.WriteLine(s) lblLon.Text = s tw.Flush End If End If End Sub Sorry, it lost the indentation...
Erel B4X founder Staff member Licensed User Longtime User Oct 7, 2013 #6 You probably see the AUTO string from the previous message. You cannot assume that the text you sent will arrive as a single "packet". See AsyncStreams tutorial for possible options. Upvote 0
You probably see the AUTO string from the previous message. You cannot assume that the text you sent will arrive as a single "packet". See AsyncStreams tutorial for possible options.
T ThiagoRodrigues Member Licensed User Longtime User Oct 16, 2013 #7 Erel, thanks for the suggestion. I tried using AsyncStreams, and no success... Received from 192.168.1.102: '$GPRMC,004400.31,V,,,,,,,161013,,,N*7B' Received from 192.168.1.102: ',AUTO' Client disconnecting: 192.168.1.102 Duration: 00:00:07 Sub GPS_NMEA (TimeStamp As Long, Sentence As String) If Sentence.Contains("$GPRMC") Then Label1.Text = Sentence s = Sentence & ",AUTO" End If End Sub Sub Button1_Click Socket1.Connect("192.168.1.100",1024,1000) End Sub Sub Socket1_Connected(Connected As Boolean)As Boolean ToastMessageShow("Connected",True) Dim buffer() As Byte AStreams.Initialize(Socket1.InputStream,Socket1.OutputStream,"Astreams") buffer = s.GetBytes("UTF8") AStreams.Write(buffer) End Sub Upvote 0
Erel, thanks for the suggestion. I tried using AsyncStreams, and no success... Received from 192.168.1.102: '$GPRMC,004400.31,V,,,,,,,161013,,,N*7B' Received from 192.168.1.102: ',AUTO' Client disconnecting: 192.168.1.102 Duration: 00:00:07 Sub GPS_NMEA (TimeStamp As Long, Sentence As String) If Sentence.Contains("$GPRMC") Then Label1.Text = Sentence s = Sentence & ",AUTO" End If End Sub Sub Button1_Click Socket1.Connect("192.168.1.100",1024,1000) End Sub Sub Socket1_Connected(Connected As Boolean)As Boolean ToastMessageShow("Connected",True) Dim buffer() As Byte AStreams.Initialize(Socket1.InputStream,Socket1.OutputStream,"Astreams") buffer = s.GetBytes("UTF8") AStreams.Write(buffer) End Sub
Erel B4X founder Staff member Licensed User Longtime User Oct 16, 2013 #8 AsyncStreams (not in prefix mode) by itself will not help. The issue you are experiencing is explained in AsyncStreams tutorial. You cannot assume that messages sent over the network will arrive as a single message. This is why you should use prefix mode if you can. In that mode every message is prefixed with its length and AsyncStreams takes care of "building" the message correctly. Upvote 0
AsyncStreams (not in prefix mode) by itself will not help. The issue you are experiencing is explained in AsyncStreams tutorial. You cannot assume that messages sent over the network will arrive as a single message. This is why you should use prefix mode if you can. In that mode every message is prefixed with its length and AsyncStreams takes care of "building" the message correctly.