Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

receive serial frame

Hello,

 

I am currently communication with a piece of hardware that is constantly spitting out messages. The start byte is 0x06 and the end byte is 0x03. How can I set up a loop to read this frame exactly. Currently I have to have two seperate loops, one for sending data and one for reading data. My problem is that my top loop will read in the data off the serial port but it will not start with 0x06 and I will get a partial frame. I would like to receive one byte at a time until I get one frame and then parse that complete frame. Can I use a state machine or is there something more simple. I have attached a picute of the code.Serial.PNG

0 Kudos
Message 1 of 4
(3,478 Views)

Perhaps the easiest would be to enable termination characters and set the termination character to 0x03.  Then simply wire a constant to byte count which is larger than the number of bytes in the longest frame.  The VISA Read will wait until it get an end of frame character and then return the "mess" to be parsed.  The first time through the loop you may get a partial frame.  When using termination characters, you do not use Bytes at Port. You also would not need the Wait(ms).

 

You may want to consider an event structure in the lower loop so that you only send the Command when the Joystick Gain changes.

 

Lynn

0 Kudos
Message 2 of 4
(3,475 Views)

I can do that but what if my message has a 0x03 in it? Then it will prematuraly take the message and I will get bad data. I really want to look for the start AND stop characters 0x06, 0x03. Any ideas as to how to do this?

 

Thanks

0 Kudos
Message 3 of 4
(3,463 Views)

If the 0x03 really is a STOP character, then is should not be allowed to occur in the data. That is the definition of a stop character.  If it is allowed, then how do you tell when the message has ended?

 

Some protocols have an "escape" sequence which preceeds a reserved character by another special character.  These are chosen so that they do not routinely occur in the data set as a combination.

 

Do you have a complete specification of the communication protocol?

 

Lynn

0 Kudos
Message 4 of 4
(3,461 Views)