LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial communication problem

I am creating two applications that have to run on two computers and they will speak among them through the serial port. For the moment I'm using only a pc and the two applications use one the COM1 and the other the COM2. Unfortunately I have noticed that among the instant in which I call the function ComWriteByte (or ComReadByte) and when indeed the buffer is read, a not negligible time passes. Increasing the complexity of the calculations (and therefore the quantity of datas to transmit and to receive), it happens that I don't succeed in correctly managing the serial communication and the programs don't work anymore (this because the delays of communication are added and at the end the functions goes time-out). How am I able to speed up the tr
ansmission? After all, I transmit only 8 bytes at a time, therefore the communication in itself (which is set to 57.600Kbs) should be very fast.
Thanks.
0 Kudos
Message 1 of 5
(2,893 Views)
You can disable the transmission buffering by putting a negative value in the Output Queue size of OpenComConfig.

As stated in the on-line help for that parameter:
"Specifies the size of the output queue for the selected port. If you specify 0, 512 is used. If you specify a value greater than 0 but less than 30, 30 is used. If you specify a negative value, the output queue will not be used and the data will be written to the port directly."

I found this very useful in some applications of mine and put it as a rule for me. As far as I know, this option is found in CVI 5.5.1 and later.

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?
0 Kudos
Message 2 of 5
(2,893 Views)
Unfortunately, I have the version 5.5 and I can't specify a negative value. To obtain the same effect I used the 'outp' function, but the problem remains...
0 Kudos
Message 3 of 5
(2,893 Views)
Are you polling the COM port or are you using callback functions for managing the serial communication?

Should your messages have a fixed termination character, you could install a callback for the serial port to be called when this character is received. This could speed up the stuff a lot. If for example your messages terminates always with an ampersand, you could use this line after opening the com:
err = InstallComCallback (com, LWRS_RXFLAG, 0, 38, comgen, 0);
The callback "comgen" will be called every time the ampersand (charcater 38) is present in the input queue.

The same can be obtaine if your messages are of foxed lenght: use the LWRS_RECEIVE flag for the event mask parameter and put the message lenght in notifyCount field.
This method can be little more difficult in case the communication is very fast since the function is triggered only after the queue lenght falls below the stated number of bytes: if your program is not fast enough to empty the input queue before new messages are received you can be in a great trouble (the callback in no more triggered and at last you'll catch an overflow error when the queue is full).


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 5
(2,893 Views)
Thank you very much for your answer. I tried to use the comcallback too, but without results. I have analyzed my problems in last 2 days and I can say that it is caused by the great quantity of communications. In other words the problem seems to be not the data rate, but the frequency of read and write. For example: inside a Maincallback I can call ComWr for 4 times and after a ComRd and the other program have to do something different for each received command. Sometimes it has to answer too. I imagine that this is a too complex communication to be done quick and simple. The solve this situation I slew down the speed of the programs (increasing the interval of a timer) and putting delay commands after the function ComWr. In this wa
y I can obtain a correct behaviour of my application. Probably, if I were a better programmer, I would have resolved more brightly the problem, but for the moment, I can be satisfied. Anyway, if you have other advices, they are welcome.. 🙂
0 Kudos
Message 5 of 5
(2,893 Views)