03-03-2017 02:57 AM
Hi all,
My program is divided in such way:
- in sub VIs I have while loops controlling hardware. Each while loop works with different period and with different hardware. In final application I'll have minimum 10 of such sub VIs.
- in main VI I have GUI showing data from sub VIs and controlling them (setpoint, readback, stop)
Because main VI is just a GUI for me, I've decided to transfer data between it and sub VIs using Control Refnums.
For example for water bath: main VI sends a setpoint and stop signal to sub VI and sub VI sends bath's temperature to main VI. I don't want to use queues and notifiers because they are generating to many wires.
Everything worked perfectly until when I added an indicator in GUI that sub VI is working ("Bath is operating" variable).
It works fine when bath is not connected, or it has a wrong COM port number. But when I unplug the bath when the program runs something strange happens. Sub VI is writing 0 to "Bath is operating" (see attached debugging screenshot), but main VI reads value 1.
Any ideas how to fix it?
Solved! Go to Solution.
03-03-2017 03:09 AM - edited 03-03-2017 03:11 AM
I *think* that when you unplug the bath, an error occurs on the top branch of the subVI while loop (right?). This then goes into the next loop iteration via the shift register. The bottom branch of the error wire shows 'Error Status'=T, so 0 is the output where you have the probe. However, your top wire also has the same 'Error In' condition, and so the property nodes, using the 'Standard Error In' rules, do nothing. No new value is written and your main VI doesn't receive any change - only the last working iteration updates the value.
Regarding 'fixing' it, just remove the error in wire from the property node where you write the value. Be aware that the value you get out of the LDT1011 'Temp' node might be (I'm guessing) 0, so that will be written as the 'Bath temperature value'. You might not want that - if so, you'll need to handle that condition.
03-03-2017 03:27 AM
Thanks for help, I've forgot about that...
Can you tell me is the communication between VI using refnums efficient? That's a simplest way I've found so far to do it.
03-03-2017 03:51 AM
Efficient... well, I have no benchmark to point to, and I generally mess up when trying to write benchmarking code for my own project(s), so I can only say my understanding from reading others' work is 'not really'.
As I understand it, setting a value using the Value Property Node requires the main, 'UI' thread. This can slow down an application quite significantly, compared with a queue/notifier, or even a local variable. On the other hand, your data is pretty small (a double and a long?), and your loop iteration is only at 1Hz. With a 1 second update time, I don't think it's likely you'll need to worry, so using the simple solution seems reasonable.
Your main loop is going round on a 40ms wait time - obviously this might be because your other subVIs operate more quickly, but if it's just to have fast response to changes to set-points or the stop value, you might consider using an Event Structure. This will trigger when you change something, and since you're already using Value Change, you can just switch to 'Value Change (Signalling)' and have it also update every time a value changes that you're reading.
This might be more work than you want to invest in this part of your work though, so you should of course prioritize whatever needs doing most. If it's working now, and you don't anticipate writing the values very quickly, you should be ok.
I'm attaching my (messy) attempt at benchmarking a value change event. YMMV.
03-03-2017 04:13 AM - edited 03-03-2017 04:28 AM
Ok, I understand yours point, this benchmark shows it pretty well. I expect to heave one quicker loop (5 ms period), so I'll use there notifiers/queue or I'll access property node inside it only few times per second.