LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

General tips about serial communication

Hi labview community,
just an updated version of the topic:
 
SITUATION:
 
I would like to get some advices about the communication between a PC with labview (I have 6.1, 7.1, 8.0 and 8.2) and a FlashRunner (= electronic device used to program firmaware of attached micro-controllers).
You pilot this FlashRunner simply sending the string "run script_file.frs" to a serial port (initialized 9600 8 N 1). Must add a carrage return char at the end. It can however receive some other commands.
When a FlashRunner command executes successfully, FlashRunner typically answers with just the > character (unless the command requires
data to be returned back — you get "data_xxx>" carriage return terminated).
When a FlashRunner command generates an error, FlashRunner answers with a four-digit hexadecimal error code followed by the ! character.
 
QUESTIONS:
 
After the initialization of the serial port, and sending the command string, i don't know if i it's more performing to poll the COM port with "byte @ serial.vi" or to use some sort of serial event (for example triggers when CR is received, then read the data...should work i think). I don't know how to use events in labview.
I wouldn't like to poll @50ms the byte at port routine and then read the data. Can you provide a general example VI?
Timeout of my application should be greater than the maximum timeout that can ever happen in the response?
 
Thanks

Message Edited by Slyfer on 03-20-2007 04:01 AM

0 Kudos
Message 1 of 5
(3,239 Views)

"Slyfer" <x@no.email> wrote in message news:1174381806759-494235@exchange.ni.com...
Hi labview community,
just an updated version of the topic:
<a href="http://forums.ni.com/ni/board/message?board.id=140&amp;message.id=14609#M14609" target="_blank">http://forums.ni.com/ni/board/message?board.id=140&amp;message.id=14609#M14609</a>
&nbsp;
SITUATION:
&nbsp;
I would like to get some advices about the communication between a PC with labview (I have 6.1, 7.1, 8.0 and 8.2) and a FlashRunner (= electronic device used to program firmaware of attached micro-controllers).You pilot this FlashRunner simply sending the string "run script_file.frs" to a serial port (initialized 9600 8 N 1). Must add a carrage return char at the end. It can however receive some other commands.When a FlashRunner command executes successfully, FlashRunner typically answers with just the &gt; character (unless the command requiresdata to be returned back ? you get "data_xxx&gt;" carriage return terminated).When a FlashRunner command generates an error, FlashRunner answers with a four-digit hexadecimal error code followed by the ! character.
&nbsp;
QUESTIONS:
&nbsp;
After the initialization of the serial port, and sending the command string, i don't know if i it's more performing to poll the COM port with "byte @ serial.vi" or to use some sort of serial event (for example triggers when CR is received, then read the data...should work i think). I don't know how to use events in labview.I wouldn't like to poll @50ms the byte at port&nbsp;routine and then read the data. Can you provide a general example VI?
Timeout of my application should be greater than the maximum timeout that can ever happen in the response?
&nbsp;
ThanksMessage Edited by Slyfer on 03-20-2007 04:01 AM



Since your data is always carriage return terminated, you are best of to initialize visa with termination characters enabled. This way, the read from serial will stop when it encounters a carriage return, and gives you the data before it. It will not be heavy on your processor load. You can also set the timeout of visa with the init serial vi.


Regards,


Wiebe.





0 Kudos
Message 2 of 5
(3,230 Views)

Ok, another question.

I set in the VISA Configure Serial Port vi:
Termination_char = carriage return (0xD)
End_Read_On_Termination_Char=True
Timeout=10sec

then i use the VISA write to buffer function to send a string to my FlashRunner device (I send also a CR at the end of the string).
Now after some ms, there will be an answer in the receive buffer of the serial port.

Is it useless to program a timeout error??? I mean acquiring the clock every cycle (50ms) and verifing that "(actual_clock) - (start_clock) > timeout" ?? In the Advance serial port (Labview example), i notice that this "error-event" happens without program anything.
Am I wrong?
Is it OK to simply use the VISA Read, granted its termination upon CR (as declared in initialization) and the integrated timeout error??

Thanks

0 Kudos
Message 3 of 5
(3,209 Views)

"Slyfer" <x@no.email> wrote in message news:1174399808488-494404@exchange.ni.com...
Ok, another question.
I set in the VISA Configure Serial Port vi:Termination_char = carriage return (0xD) End_Read_On_Termination_Char=TrueTimeout=10sec
then i use the VISA write to buffer function to send a string to my FlashRunner device (I send also a CR at the end of the string).Now after some ms, there will be an answer in the receive buffer of the serial port.
Is it useless to program a timeout error??? I mean acquiring the clock every cycle (50ms) and verifing that "(actual_clock) - (start_clock) &gt; timeout" ?? In the Advance serial port (Labview example), i notice that this "error-event" happens without program anything.Am I wrong?Is it OK to simply use the VISA Read, granted its termination upon CR (as declared in initialization) and the integrated timeout error??
Thanks



I don't understand what you mean for 100%... The timeout is useful when there is something wrong. For instance, if the device is not wired, the serial read will stop trying after 10 sec. It's the timeout for the entire message, not for each individual byte.


Regards,


Wiebe.
0 Kudos
Message 4 of 5
(3,200 Views)

Wiebe,

You are right. In the Init VISA, I set timeout, 0xD (carriage return) termination char and enable termination char.
Then I placed a Instr. Property node exactly like in the "Advance serial example" (included in labview 8), that automatically queues the termination char.
So I don't need to explicitly send the "0xD" char to the VISA Write 🙂
Also I receive the string before the termination char, so I don't need extra string computing.



As regard the timeout I meant that it's not needed to place a while loop that controls if timeout expires, because the timeout event is fired automatically by the VISA. This can be verified in the "Advance serial example" also.
All we need is just to initialize the VISA vi with a timeout.

It's so damn simple!!!! there must be something wrong!!! Smiley Happy

Message Edited by Slyfer on 03-23-2007 10:49 AM

0 Kudos
Message 5 of 5
(3,158 Views)