NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems in syncronyzing two threads into Test Stand using a Global Variable (TestStand 4.1.1)

I have one thread that is doing TCPIP Aquisition into a Global variable defined in Teststand. And I have another thread that it supose to read it. All are in the same sequence and execution. The problem is that the aquisition thread got a lot of bytes, while the processing thread is reading always only a few. Do you know what the problem could be?

 

 

I will attach also some pictures just to be maybe more clear...

0 Kudos
Message 1 of 18
(4,938 Views)

Hi,

 

how did you sycronizse the access to the global variable in TestStand ? Are you using a Semaphore ?

Another deal could be using a queue for doing this task.

The read thread will push it a the head and the processing one will pull it from tail.

 

Hope this helps

 

juergen 

 

 

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 2 of 18
(4,921 Views)

I didn't use any semaphores. The idea is that one loop will only write the variable and the other one it will just read it. So there is no problem if I'll read it later. The problem is the teststand string that is not updated or there is a problem with it because I always can read the same amount of byes, while in the write task this global variable is continouslly updated with new data. So it is like a queue in the end, but other design.

 

I'll try a few more tests because I used previouslly this design and it works. Now there is something that is preventing the variable to be read.

0 Kudos
Message 3 of 18
(4,920 Views)

That nis a classic case of race condition:

You do not know when the variable is getting updated, therefore you cannot tell wether you are reading old or new data.

Furthermore, i hope that the string is not growing unlimitied, this would be a no-no for certain!

 

I suggest you to use a queue if you are really interested in a system with single writer/single reader.

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 4 of 18
(4,911 Views)
Anyway, the problem is that the reading thread is capable to read only a few characters and everytime looks like there are the same number of them (I see here more a string handling problem from TestStand side). And the write thread is writting always a constant number of chars, but of course more than the read thread is capable to read it. So what I suspect is the type of string (Binary or ASCII) which cannot be specified as a type for a Global String variable in TestStand, only somewhere to a parameter of a LabVIEW VI. Or am I wrong with that too? This is because my string can contains any character type including terminations of strings too.
0 Kudos
Message 5 of 18
(4,900 Views)

I am sure it is not of the case of string handling inside TS

 

It is as Norbert said: the race condition!

 

Just try your stuff without using a thread, you will see that it is working.

 

Another thing you can also use is a notifcation.

So you can communticate/sync between the threads.

 

Thread A will write the variable when it is finished it sends a notification.

While B wait for the noification. When it comes B can read from variable

 

 

Hope this helps

 

juergen   

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 6 of 18
(4,899 Views)

  I think your idea is good but I want to say about my case that if you compare the pictures with '_front', you can see that the next character that should be read is '0x00' which means in string life end of an ASCII string. Am I right or not? So this is why I suspect that is a string issue...

 The idea of using the string instead of other sync structures is that because my string contains inside timestamps which can help me to identify if I have new data and of course the size of the string which is also a good semaphore for my case. I try to keep it simple.

 

 

0 Kudos
Message 7 of 18
(4,897 Views)

But you are not checking for each character to find if it equals to "", you are checking for a string of characters.

 

regards

Ray Farmer

Message Edited by Ray Farmer on 05-05-2010 12:10 PM
Regards
Ray Farmer
0 Kudos
Message 8 of 18
(4,897 Views)
Of course I don't do it like that but seems that TestStand is doing for me. Actually I had this problem with VIs. When I pass a TestStand string as a parameter and I forgot to specify the VI parameter that is a Binary String than everything has an end to a 0x00 character. Once that you do it the Test Stand variable will become a Binary not an ASCII one. Maybe it is time to try this workarround or if there is somebody who can tell me how should I specify this into TestStand (Binary or ASCII string for a global variable). At least for numbers it is possible to specify the type.
0 Kudos
Message 9 of 18
(4,894 Views)

I wasn't looking at your Sequence, I was looking at Receive_HDL_Block.JPG. What is that VI doing (the one with number 3 on the icon and Size_in_bytes as an input) ?

 

Where in teststand are you doing any checking?

 

I don't really understand your sequence.

 

You have a sequence (running in a new thread) (why), following by another called Receiver Handler (also running in a new thread) then two more sequences which seem to do some with transmitting something (also running as new threads). You are only waiting on one of these threads (the Receiver Handler). There does seem to be any loops in TestStand, you dont seem to be bothered about the other threads that you have running. What happens when this test sequence finally does stop, what is stopping the Threads that you have running.

 

Your pictures dont really seem to fit in with your Test Sequence, such as where does Test_005.vi fit into everything

 

The whole thing is a bit of a nightmare.

 

Maybe your best bet would be to scrap the lot and start again. Only this time have a better understanding of what you what to achieve, what would be best to put into Teststand and what to put into labview. Whether you really need all those new threads running.

 

Sorry to be so blunt.

 

Regards

Ray Farmer

Regards
Ray Farmer
0 Kudos
Message 10 of 18
(4,889 Views)