LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

the output string in RS232

Dear,

My labview6 VISA code is controlling a equipment by RS232.
In first running of the code, output characters were read incorrectly. If the desired result is "12345-678", the appeared string is "345-678123" with some offset.

I don't know why the string is moved inconsistently.
(Maybe, I guess it comes from a remained string in buffer.)
I used VISA buffer flushing routine but it was useless.
Could you recommand any skills to read the string correctly?
0 Kudos
Message 1 of 6
(3,375 Views)
In assume you are using serial VISA

The normal sequence of RS232 communications that I use is
1-Flush communication buffers both read and write
2-Write the string
3-wait for some ms (depending on the instrument used)
Then read the bytes
and I never had problems with that.
Message 2 of 6
(3,375 Views)
When possible I enable the termination characters this usually helps. (Not all equipment will provide a termination character but it would be great if it did.)
Message 3 of 6
(3,375 Views)
Very thank you for the reply.
Although I resolve my problem by using termination character, I would like to know your comment.
Could you please attach or give some example codes for flushing the buffer?
(My email is poyntor@yahoo.com)
Thank you again.
0 Kudos
Message 4 of 6
(3,375 Views)
From LabView Help:
"termination char calls for termination of the read operation. The read operation terminates when the termination char is read from the serial device. 0xA is the hex equivalent of a linefeed character (\n). Change the termination char to 0xD for message strings that terminate with a carriage return (\r). "

I usually Do not enable the termination character. Depending on the command, and what to expect to read, I read the whole available bytes and handle expected strings with proper parsing (after the command is sent, I wait for enough time before read, to make sure the device responded and outputted its data).

And I "Flush the Buffers" before I Write a command. I had an application where if I do not do that, I got er
rors (may be it was device specific).

attached is an example vi for flushing communication buffers
0 Kudos
Message 5 of 6
(3,375 Views)
Hi Dr. Imad,

You said you waited a few ms before
reading the rs232 port. How do
you code this in labview? How do
I make labview wait a few ms before
I do the reading?

Thank you,
Van
0 Kudos
Message 6 of 6
(3,375 Views)