LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Datasocket: Where to put the Close

Solved!
Go to solution

I am having problems with Datasockets in a much larger project. Therefore I have created this smaller project to show the problem.

 

I am using an Eurotherm PAC2500 hardware with a pressure sensor connected to module 1, channel 1. I have the Eurotherm OPC server running and am trying to read the tag "val". This is already scaled and gives me the atmospheric pressure. In the larger project, there are about 60 different values to read, each has the tag "val" but sits on a diffrent module/channel. Therefore I have a sub VI which opens a datasocket, reads the tag and should close the socket.

 

If I run the test.vi with a close in the sub VI, the first time a value is shown but then the vi freezes. Going to the OPC server and looking at the tag then causes the vi to continue, which I do not understand. If I remove the close datasocket from the sub vi, the values are updated without looking at the tag in the server. However, looking at the task manager shows that the memory comsumption of labview increases by 0.2 MB with every iteration.

 

I realise that using no close datasocket is the wrong way but where should I put the close? I am grateful for any help.

 

Regards

Mark

0 Kudos
Message 1 of 10
(670 Views)

I don't know why the read freezes, however a good practice is to open the reference before the loop and close it afterwards.

Opening without closing is wrong because it consumes LabVIEW memory and resources.

 

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 10
(649 Views)

Thanks for the info but that is what I would normally do. In this case the read2500.vi opens the datasocket, reads the value and closes the socket. There is no loop.

0 Kudos
Message 3 of 10
(642 Views)

@vtiu  ha scritto:

There is no loop.


Really? Do you know what a loop is? In your test program there is a While Loop, as common in data acquisition programs.

If you prefer, I can re-state like this: open the reference at the beginning of your program, then close it just before to stop the execution.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 4 of 10
(623 Views)

No, I understand what you are saying. Maybe I did not make myself clear enough. This is just a test project reading 1 value. The real project looks something like this:

 

vtiu_0-1708679430393.png

The loop does all the reading and updates the indicators. I pass the module and channel number to the sub vi which opens the data socket. A single close outside this loop will fail or not?

0 Kudos
Message 5 of 10
(615 Views)

I can only repeat what I wrote before. Open all references before the loop. Pass each reference to any number of 2500Read subvis you need to read your values. Close references after the loop.

Don't forget to do a proper error handling. If any DataSocket Open throws an error, its unlikely that the program can safely run.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 6 of 10
(607 Views)

I have just found this, is it what you mean?

 

vtiu_0-1708680950883.png

If this is the case, it would be better for me to have an array of indicator names instead of the array as shown here and use "i" to select the right indicator. Is that even possible?

0 Kudos
Message 7 of 10
(600 Views)

@vtiu  ha scritto:

I have just found this, is it what you mean?

 

vtiu_0-1708680950883.png

If this is the case, it would be better for me to have an array of indicator names instead of the array as shown here and use "i" to select the right indicator. Is that even possible?


Yes this is about what I meant. You don't need to reverse the reference array though, since they are all independent connections.

About your question, this highly depends on how the UI is organized. If you prefer indivisual indicators, you may do one of the following:

1) group them in a cluster; then use Array To Cluster to convert your array and update all values at once in the UI

2) create an array of references to the indicators, then update them into the read loop by means of a Property Node (Value property); this is going to be al little slower, but will give you more flexibility on the indicators location

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 8 of 10
(587 Views)
Solution
Accepted by topic author vtiu

I have managed to get your option 2 to work. For 4 channels the loop time is 2 ms which is very fast! It is a liitle strange to leave indicators "lying around" unwired but it works.

 

Unless you have further comments, I will take this solution and finish this thread. Many thanks.

 

test2.png

 

PS. I took out the reverse 1D array after posting.

0 Kudos
Message 9 of 10
(574 Views)

Yes, reusing references is MUCH faster than opening and closing them every time.

No further compelling comments on my side.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 10 of 10
(567 Views)