LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronisation between data received through different COMports

Hello Everyone,
         I have connected 5 sensors to 5 different COM ports .A DGPS is connected to another COMport and defined a InstallComCallBack for DGPS.In the ComCallBack for DGPS i defined the InstallComCallbacks for all the 5 sensors.My intention is to write to a file that :"At a particular time the Values from the sensors r these i.e., at time 10 the Sensor1 value is this ,Sensor2 value is this upto Sensor 5. In the COMCallBack functions for the 5 sensors i'm calling the same functoin say reqdatareply() becoz the operations to be performed on the data acquired  from 5 sensors r same.The rate at which the data comes from these sensors r high i.e.,20samples/sec and from DGPS 1 packet in 1 second.Now my problem is that ,Suppose the  first COMCallback for Sensor1 got executed and in that the reqdatareply() fn got invoked and by this time the second Comcallback also got invoked and the same function reqdatareply() got executed.Now the reqdatareply()  is being called by 2 Callbacks.Same with the other 3 sensors also.In the worst case all the 5 COMCallbacks may try to attempt the fn reqdatareply() at the same time.At the end of the function reqdatareply()  i hav to save the values from these sensors.i.e., from Sensor1 to som SEnsor1.txt ,Sensor2 to Sensor2.txt.I can solve the problem if i write the code written in reqdatareply()fn in all the 5 Sensor'sCOMcallbacks but then code repetition may occur which is not a good practice.
Whether i'l be able to fill the files with the values from theDGPS and sensors.wil there b any timing problems.I'm attaching a file that will demonstrate the problem.
Please do something at the earliest,since it is a very urgent project
Regards,
     Mala
0 Kudos
Message 1 of 2
(2,723 Views)
I see no problem with what you want to do (if I understand it correctly) as long as you are not accessing global variables or using the static storage class within the function.
 
If you are only using local variables within the function (the variables are declared in the function body and you do not use the static keyword), then each time you call that function, new, unique copies of those variables are allocated on the stack and there is no collision between the various instances of the function.
 
If you use the static keyword or a global variable, the variable is allocated on the heap and only one copy exists, those are things you generally want to avoid unless you have a good reason for doing so.
 
Martin Fredrickson
Test Engineer

Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128
0 Kudos
Message 2 of 2
(2,704 Views)