LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial port reconfiguration

Serial port reconfiguration.

My goal is to send via serial communication interface one packet of bytes with a slow baud rate (150 baud) and after this, another packet is requested with another baud rate (9600 baud).
To do this I have used this tecnique:
- Open serial port with slow baud rate
- Send the first data characters
- Close serial port
- Reopen serial port with fast baud rate
- Send the seconds data characters

All seems to works fine, but my problem is in the long time required during baud reconfiguration.
I have noticed that function ‘CloseCom(comport)’ takes a long amount of time and this time is related with baud rate.
For example with baud rate of 150 baud the CloseCom() takes about 800msec to finish its task. With 300 baud this time becomes about 400msec.

Thanks very much for any help.

Flavio

(the environment is : CVI=7.0 OS=WIN-XP)
0 Kudos
Message 1 of 8
(5,352 Views)
You could try using VISA instead of the standard RS-232 library functions. Visa permits you to reconfigure the serial port without need to close and reopen it.

Attached a standard VISA sample I modified to communicate with two instruments on the same COM port, one at 4800 and the second at 9600 baud. Apparently there is no delay while reconfiguring the com port: it has to be tested with so different speeds as yours and I don't know wether it works well if continuously reconfigured for a long time, but in my opinion it worth a try.

Hope this helps
Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 8
(5,338 Views)
Thanks for yours help,
I have just tried to run the attached program and the situation is different but the time required is steel too long:

I have done these measurements:

- switch from 9600 to 4800 takes about 30 msec
- switch from 150 baud to 4800 takes about 300 msec

When the driver try to close serial port it seems waiting for some time out. This time is not proportional with the baud period.

At 9600 baud the character t.o. is 1 msec and the driver takes 30 msec (ratio 0.033)
At 150 baud the t.o. is 66 msec and the driver takes 300 msec (ratio 0.22)


Flavio
0 Kudos
Message 3 of 8
(5,319 Views)
Just to be sure about what the program is doing... are you sure your program has finoshed sending characters when you try to reconfig the port? When using traditional RS-232 library you could wait for output to complete by adding
while (GetOutQLen (1)) {}

2nd issue, again for traditiona RS-232 library: try opening the port with negative output buffer:
error = OpenComConfig (1, "", 9600, 0, 8, 1, 512, -1);
this ensures CVI writes directly to the port and no intermediate windows buffer is used (so there should be no time spent on unpredictable tasks...). Read on-line help for OpenComConfig command for reference.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 8
(5,314 Views)
I have already tried to put one (1) in the buffer length but without any results; even with –1 and GetOutQLen (1) the delay doesn’t change.

Thank you.
Flavio
0 Kudos
Message 5 of 8
(5,313 Views)

Perhaps You should disable the serial hardware FIFO output buffer.

/Anders

0 Kudos
Message 6 of 8
(5,102 Views)

Hello,

I have the same Problem. I need a method to change very fast the Baud-rate.... (less than 100ms) I am happy about every Help for this task. I think, that CVI needs a lot of time for the change of the baudrate. This should be changed to improve the CVI environment.

 

With kind regards

Savvas Georgiadis

0 Kudos
Message 7 of 8
(4,905 Views)
The speed at which a serial port can be reconfigured is going to depend on the windows serial driver and the physical serial port hardware itself far more than CVI.  To reliably change the baud rate within 100mS could be difficult if the hardware configuration is not up to the task.  If the data stream is a constant pattern it may be easier to use something like a high speed digital I/O card to generate the serial output waveform.  If the data stream varies I would multiplex two serial ports onto the same serial bus and use some form of I/O control to switch between them.  This would also be a really good project to implement in an FPGA or FPGA based hardware.  
0 Kudos
Message 8 of 8
(4,825 Views)