I think this covers it. I took this out of a more complicated piece of code but it looks correct.
A. create a byte array
B. Listen for stream byte events
C. Add bytes to array
D. Convert to string when finished
This assumes you've created your roMessage objects, and you've created your UDP receiver and you're listening to that message object. Those parts you still have to do.
1. First, create Byte Array somehwere in your script:
response = CreateObject("roByteArray")
response_bytes_left = 20
2. Here we check to see if it's a streambyte event, which is what you receive whether you're listening over serial or ethernet. Now, we're listening for events.
event = wait(0, p)
if type(event) = "roStreamByteEvent" then
response.Push(event.GetInt()) 'adds the new byte to the byte array
response_bytes_left = response_bytes_left - 1
if response_bytes_left = 0 then
print response.HexString() 'converts byte array to string and prints results
rem Checks if we've received the total # of expected bytes, and then prints if we have.
else if type(event) = "roStreamEndEvent" then
print "closed connection"
print response.HexString() 'converts byte array to string and prints
rem This bit of code checks if the event received is the end of stream event, and if it is, then it moves to process the array as well.
The byte array object calls the ToHexSTring() function to covert the bytes in the array and returns a string. In this case, it was printed. But, you could say:
ByteString$ = response.HexString()
If ByteString$ = "my expected reply" then