LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

High Speed Serial Communication Question

 

Hi,

 

  I have an application which needs to read serial messages at 50Hz (one messsage every 20ms). The messages are 100bytes in size. What will be the best method to read the data effectively? Will it be polling or using the ComCallBack function?

 

  I have tested both the polling method and the ComCallBack but the result is not satisfactory. I need to read the message ASAP once it arrives, and calculate the data rate or interval between messages. However, frequently there is a few message queue up at the port, suggesting that the program cannot read the messages fast enough. I am aware that the timing will not be accurate, but at least, I need to read the messages sufficently fast enough so that there is not more then one message at the queue at any one time. That will be good enough.

 

  I'm using a i7 8 core processor. On the task schedule most of the CPUs are mainly idle when the program runs.

 

  I have tried creating a new thread for the polling or the installcomcallback function and give it TimeCritical priority  but it doesn't help.

 

  Appreciate any advise.

 

  Thank you very much.

 

 

 

 

 

Regards

 

0 Kudos
Message 1 of 4
(4,241 Views)

50 Hz transmission should not be a problem provided the program is well structured.

 

You're not telling anything about the baud rate, but let suppose it is fast enough (>=76.2 kbaud) to be able to correctly handling the data every 20 msec, considering tx time, device reaction time and rx time (adding data management time in case of single-thread scenario).

 

Additionally, you're not telling us whether you're using VISA or the built-in RS232 library. In case of the second, try opening the port disabling the output buffer as described in the help for OpenComConfig (outputQueueSize = -1).

 

How are you handling the timeout on reception? Are you relying on ComRd timeout or did you make it other ways?

Other useful elements that can help designing the most appropriate strategy: do the response message have a termination character or are they fixed lenght?



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 4
(4,237 Views)

 

baud rate is 115200bps.

 

Using the build in RS232C library. (ComRd, ComRdTerm)

 

Just curious, how does setting the outputQueueSize affect the situation? (will try this)

 

I'm not writing any data, just need to read data as fast as possible.

 

So far, never encountered any timeout occurence.. bcoz the msg will end with 0x03, so I check the inputQ and use ComRdTerm. Tried LWRS_RECEIVE and LWRS_RXFLAG, not much different in performance.

 

So far, never miss any data. But just couldn't read fast enough. It's like, reading smoothly for a few message then a queue will start to form. As I programmed it such that it will check the inputQ and read all message before it waits for new messages, after a few rounds the queue will be cleared. But it is still on and off. Sometime the messsage queue balloon to 5k bytes, then 100B, 100B....... then 6k, 7k... then drop to 100B again..

 

I want to prevent any queue from forming. Is it possible?

 

How should I create a thread that houses the callback that ensures it can run promptly? I tried setting TimeCritical prioirty but sometimes it just cannot clear the queue fast enough. There is 8 core CPU and less than 4 threads, by right, the thread should have it's own CPU.. not sure when it slows down when other part of the program (other threads) executes or does something.

 

Thanks.

 

 

 

 

 

0 Kudos
Message 3 of 4
(4,232 Views)

If you are not writing to the port, setting outQueueSize = -1 will have no effect: it is aimed to skip the output buffer and have the program write directly to the port, thus avoiding a possible bottleneck.

 

Can you post the relevant part of the code? I mean, setting the port and reading loop.

What are you doing of data read? May there be long lasting functions that block the system? (streaming to disk or to a remote server with timeouts or so?).

 

Why are you checking the input queue? I mean, couldn't you simply iterate on ComRd with an appropriate timeout for reading (SetComTime is to be used for setting the timeout)?



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 4
(4,226 Views)