12-28-2016 09:46 AM
Multithreading access to a single instrument can result in problems unless some sort of synchronization is implemented across threads to prevent a command is issued when the instrument is busy executing another one. The result of such a situation could well be the problem you are facing at present. Holding a separate VISA handle per each thread does not prevent this situation since the problem lies in the single instrument capabilities and not on the software side. There are several ways to handle this scenario: thread locks, mutexes, global volatile variablesare the most common but others can be imagined; you must be sure that each command has been acknowledged and execute before issuing the following one from the same or another thread.
12-28-2016 10:22 AM
Thanks for the answer.
I'm using a global variable to lock and unlock the instrument.
In each thread I open connection to the instrument by one special handle.
In the end of the thread I close connection.
If I'm running one thread there is no error but some times I found that closing connection fails and I have timeout error while closing .
Is there any way to require the instrument to continue reading and writing even there is timeout error.
Like ignoring this error and clearing the register ?
Thanks
12-28-2016 02:46 PM
Hi Roberto
I cannot use thread lock and unlock because in each thread I have to send commands to the DUT so if I use lock thread I'll lose time .
I'm using a global variable when this one is free one thread uses the instrument and in the end it release the variable.
Could you please give me an example of mutex uses in cvi just while making remote control to the instrument.
Thanks a lot.
12-28-2016 03:00 PM
Do not think to a thread lock as a way to block threads, think to it as an advanced global variable used to protect data or sections of code from concurrent access from multiple threads.
This help page treats thread locks and shows some simple code to esemplificate the concept.
12-29-2016 02:17 AM
Hello Roberto
Thanks for the answer.
I'll explain my code.
In one thread I call 2 function tx_test and rx_test.
In each function I send commands to the DUT to configure it (send or aquire signal) then I configure the instrument.
If I'm understanding well before configuring the instrument I have to create a lock and in the end I release it ?
And what should I do in the other threads ? Because each thread has her 2 functions tx_test and rx_test.
Thanks a lot .
12-29-2016 12:30 PM
Hello Roberto
Ill use thread lock and unlock.
If thread 1 reaches the cmtgetlock function before thread 2 does, then thread 2 suspends execution until thread 1 reaches cmt release lock.
Once the lock is released by thread 1 the second thread can then reserve ownership of the lock.
I'll put the part code of configuration the instrument in the thread lock function .
My question is what happen if the 2 threads reaches the lock at time ?
It can happen ? Does labwindows can manages this case ?
Thanks.
12-29-2016 12:57 PM
Yes, that's the way lock works: the first thread takes ownership of the lock and the others wait until the lock is available. The OS guarantees that one thread only takes the lock.
Regarding which function to protect with lock, if the configuration is constant for all threads then you can configure the instrument before launching the testing threads, next you can protect the acquisition part only. Different is the case if you need to change the configuration across threads: in that case you must protect the configuration too.
You must carefully design which part of the code to protect: keeping locked some code that do not access the instrument is a time waste, but keeping free some code that interacts with the instrument you run the risk of messing things up and block the instrument.
12-29-2016 02:10 PM
Hello Roberto
In each thread I open connection to the instrument.
Then I call tx_test in this function I send commands to the DUT and configure the instrument to measure signal. So I'll lock the part of code where I'm configuring the instrument.
Also in the rx_test function.
For each thread I havery tx and rx function to call them and in each one I have to configure the instrument differently.
So in each part code I'll make lock.
Now I'm understanding well.
Just one other thing what do you think about opening connection of the instrument I put it into a lock ?
Thank you
01-02-2017 03:49 AM
Hello Roberto.
I add to my program "Thread Lock", after several tests I lose connection to the instrument.
While I open RSVisa tester to finf resources there is no instrument, so i close CMW Firmware and I open it again then i can found resource (My instrument) and I can run test again.
Could you please help me I'm really blocked.
Thanks a lot.
01-02-2017 09:00 AM
Hello,
The error code is "3221160102" ==> connection is "The connection was interrupted"
What can be the origin of this error ?
Thanks