Skip to main content
Submitted by ngomez on Thu, 01/07/2016 - 12:07

Hello, im writing an application in c++ to move and track the motor repetitively. I have two threads running, both are using the same GCon gHandle instance.

FIRST THREAD moves the motor B by calling GCmd(gHandle, PA, motorStep), PT (Position tracking is enabled) so i set a new motor position every ~40ms, while SECCOND THREAD repeatedly queries the same motor B for its current position GCmd(gHandle, TP, buffer).

I tested each THREAD and they run fine when executed separately, however when both of these threads run in parallel, the call to move motor GCmd(gHandle, PA, motorStep) hangs indefinitely.

Is there any way to handle multithread access to the same motor axis, something similar to Mutex, from Galils API side?

Thank you very much.

Comments 1

troym_galil on 01/07/2016 - 15:35

You can solve this issue by using a different approach. I would suggest you utilize the DataRecord with the DR method. In your GOpen() function you would subscribe to the DataRecord. One of your threads would wait for the DataRecord with GRecord() and the other would send the command and response traffic with your Position Tracking mode.

See the x_grecord.cpp in the examples folder of the gclib installation for example usage of GRecord().