EMX: Is there a way to fire an event when data are received by the virtual CDC COM PORT?

Hi Everyone, my application is composed of a main loop that reads values of A/D Inputs, data from 4 COM Ports (2x NMEA, 1xIMU, 1x XBEE) and takes decision about switching on/off relay according to some user defined conditions. A C# application runs on a computer that sends some request about data values in “real timet” to my EMX. The link between the computer is the CDC with debugging functionnalities. Actually my main loop iterates in 300ms-400ms depending on the number of conditions to check but the application that runs on the computer have a timeout of 300ms (this application was designed for a previous project). In some bad cases even if I send correct data, my application on the computer put in the garbage the answer send by the EMX). The fact is that I collect requests only once in the loop and send answer as soon as possible but this is not enough.

Therefore I have two options: Threading (but sending answer needs to retrieve data and therefore I am obliged to lock an important data structure which stop other thread untill unlocking and the payload will be very big).

The other option I think is to work with event such as the one that exists for serial port as soon as data are received. Does this functionnality exists or can be implemented for the CDC?


No events from CDC.

Such a bad news!!! Is there an other mecanism that I could use?

I think threading is your only answer. But I don’t understand why the payload will be bigger when you use threading. Also, locking the other threads would be inconsequential, as you stop the ADC reads if you use events without threading.

What I suggest is that you use threading, but when the PC sends a request for data then lock the structure, copy it to a backup and unloch the structure. Then you can send the backup structure to the PC at your leasure, and the other thread can continue to take readings

Give every communication channel its own thread and use the lock keyword to synchronize everything.

Hi WouterH my first implementation was using thread and lock mechanism and despite the fact that it is easy to program, achieving good performances was not so easy, I therefore decided to use a pure sequential execution, no thread…