Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Termination character

Hi everybody

 

I want to terminate VISA read from the serial port when 65535 (FFFF) received from the transmitter.

As you know 65535 is two byte in binary and can't be allocated as termination character, but I can't allocate one byte as a termination character because the sent data contains numbers from 0 up to 4000 and the program will make a mistake with that data.

What should I do for terminate the read?

 

Thank in advance for your time..

 

0 Kudos
Message 1 of 7
(3,937 Views)

One way to do that is to read with FF as the termination character. Place the received string in a shift register. When the next read terminates, check to see if it had only one byte - the termination character. If so, then that marks the end of the message. If not, append the output of the second read to the value form the first read which is in the shift register.  The appended string will then be a complete message. Except that the very first time you may not get a complete message if the beginning was transmitted before the serial port was set to read.

 

Lynn

0 Kudos
Message 2 of 7
(3,933 Views)

What I have done in this situation is just read all of the data available on the serial port and concatinate to what was there.  Then do a search using Search/Split String for 0xFFFF.  That will split the string so you can get your message.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 7
(3,917 Views)

This can be a good alternative but the sent data may contains several "FF" and in this way the send operation will disturbs many times. This will reduce the transmition speed.

0 Kudos
Message 4 of 7
(3,903 Views)
It should not disturb the send operation. Deep down characters are still read into a buffer.
greetings from the Netherlands
0 Kudos
Message 5 of 7
(3,892 Views)

Neither proposal, mine or crossrulz, has any effect on transmission speed. Neither will have much effect on the rate at which messages are received.

 

The approach I offered will terminate a reception immediately when the FF byte is received. The time it takes to concatenate the data into the shift register is far less than the time it takes to transmit the characters. The approach by crossrulz may have fewer reads but will usually have some excess characters after the end of a message. Those become the beginning of the next message. This may result in some slight timing jitter which depends on the size of messages, transmission rate, and freqeuncy of reads.

 

If you have any control over the transmission protocol, a better way to transmit binary data is to send a byte count at the beginning of each message. Then you know how many characters to read to get a complete message. No termination character required.

 

Lynn

0 Kudos
Message 6 of 7
(3,883 Views)

johnsold wrote:

If you have any control over the transmission protocol, a better way to transmit binary data is to send a byte count at the beginning of each message. Then you know how many characters to read to get a complete message. No termination character required.


Just to add to what Lynn is saying here.  If you have any control over the tranmission protocol, what I have had a lot of success with is starting with a sync byte, then a command ID.  Based on the command ID, I know how many bytes are in the message.  We also had a CRC at the end of the message to verify that we had a valid command.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 7
(3,874 Views)