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)
SerialFlush(COMC3)
SerialOutBlock(COMC3,UMBpoll,32)
Delay(0,150,msec)
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))
Results:
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
Solved.
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.