LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with ComWrt and ComBreak

Hello

I try to send commands to a device via RS232, and I have got a problem with the ComWrt and ComBreak functions.
My program looks like that :
OpenComConfig (port, "", vitesse, 0, 8, 2, 512, -1);
Delay(1);

//Frame1
ComBreak (port, 3);
test = ComWrt (port, buffer1, 5);
Delay (0.01);

//Frame2
ComBreak (port, 3);
ComWrt (port, buffer2, 5);

CloseCom (port);

With this program , Frame1 contains 5 bytes. But if I comment the Delay(0.01) line, the first frame only contains 3 bytes.
What is the problem, and can I resolve it without using any delay ?

Thanks for your help !
0 Kudos
Message 1 of 5
(3,540 Views)
Hello Francky,
The CVI RS232 Input/Output functions are asynchronous in operation (note the input and output queues listed in OpenComConfig). This means that when you call ComWrt, the data is passed to another thread that dispatches the data for you -- the benefit being that if you write 1kb at 9600bps, your program does not have to wait for 1 second for the data to be written, rather it can continue to do other things such as process data and user interface events. The ComBreak function is not asynchronous, so it will interrupt data being written and send the break signal. One method to handle this would be to use GetOutQLen to monitor the output queue and wait until it is empty before calling ComBreak. Another method that requires CVI 5.5.1 or higher would be to co
nfigure the ComWrt function for synchronous operation. To do this set the Output Queue to a negative value when you call OpenComConfig.

Jeremiah Cox
Applications Engineer
National Instruments
http://www.ni.com/ask
0 Kudos
Message 2 of 5
(3,540 Views)
Jeremiah...

Is there still an issue about using the RS232 library in debug mode ? More specifically when single stepping through code when doing com reads and writes.
I seem to remember something about this a while back... Or was that what one of the patches was for... Sorry, I just forget...

Chris
0 Kudos
Message 3 of 5
(3,540 Views)
Hello Shiner,
When debugging in CVI 5.5.x and higher using the asynchronous ComRead and ComWrt functions, the thread that dispatches data is not woken up until CVI processes events. CVI versions 5.5.1 and higher now provide the ability to process these functions synchronously as mentioned in my original response above. This is the alternative to calling ProcessSystemEvents after each call while debugging.

Jeremiah Cox
Applications Engineer
National Instruments
http://www.ni.com/ask
0 Kudos
Message 4 of 5
(3,540 Views)
Thanks...

The question just stirred something in the back of my mind.

Chris
0 Kudos
Message 5 of 5
(3,540 Views)