Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.

Log in or register to post/reply in the forum.

Why does my String not match my serial communication output?

whoneyc Jan 18, 2022 09:11 PM

I am trying to get a CR6 to play nice with a UMB Protocol weather station, but I am having trouble.  When I poll the sensor, the CR6 appears to not store all of the data.  I know the data are being transmitted using the terminal emulator, but only the first few bytes are stored to my String.  What is going on?

Abridged code:

Public InString As String * 128
Public UMBpoll(8) As Long 'I omitted how I form this command for brevity. Assume it is magic for the sake of this forum post.
Public SerialInCount
Public del10, del11, del12, del13 as String

SerialOpen(COMC3, 19200, 3, 100, 128, 4)
SerialInCount = SerialInBlock(COMC3,InString,128)

del5 = ASCII(Mid(InString,10,1))
del6 = ASCII(Mid(InString,11,1))
del7 = ASCII(Mid(InString,12,1))
del8 = ASCII(Mid(InString,13,1))

Everything is correct before the 12th received byte, when everything reports ASCII 0. Using the terminal emulator, I can see that the correct values are being transmitted and received, including everything from the 12th received byte on. Why is the CR6 not recording my data from the serial comms faithfully?

del10 = 16 'good
del11 = 0 'good
del12 = 0 'should be 07
del13 = 0 'should be 08

whoneyc Jan 20, 2022 08:32 PM


This was a null termination problem with the string handling.  Nothing was wrong with SerialInBlock.  Instead, the string "printing" I was using killed itself at the 11th character (which you can see in variable del11).  I solved it with a variation of this post, which exploits MoveBytes to ignore null characters.

Log in or register to post/reply in the forum.