02-23-2024 01:57 AM - edited 02-23-2024 02:12 AM
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
Solved! Go to Solution.
02-23-2024 02:29 AM
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.
02-23-2024 02:41 AM
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.
02-23-2024 03:01 AM
@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.
02-23-2024 03:12 AM
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:
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?
02-23-2024 03:27 AM
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.
02-23-2024 03:39 AM
I have just found this, is it what you mean?
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?
02-23-2024 04:29 AM - edited 02-23-2024 04:30 AM
@vtiu ha scritto:
I have just found this, is it what you mean?
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
02-23-2024 05:07 AM - edited 02-23-2024 05:09 AM
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.
PS. I took out the reverse 1D array after posting.
02-23-2024 05:15 AM
Yes, reusing references is MUCH faster than opening and closing them every time.
No further compelling comments on my side.