06-14-2010 08:58 AM
Solved! Go to Solution.
06-14-2010 09:23 AM
06-14-2010 09:24 AM
Hi,
So it is easy. The while loop runs :
1rst step, there is an exclusive Or, which make that 2 boolean controls cannot be ON at the same time.
The second step is to write a port. The port is the collection of channels. 8 (depends of your device) channels make a port.
You can write on a port using several methods : writing an array 1D of booleans (the easiest to understand), or you can write a value to the port. The value is exactly the same that writing a 1D array, because the value is the translation of the array in a word. for exemple, if you write (True,True,False, False) on your port, you can write 12d, or 0C, the result will be the same...
Any other question ?
06-14-2010 09:31 AM
06-14-2010 09:38 AM
When you press 4, it calculates 247d, so it is 11100011.
I think that when you measure the voltage on the ports, you will recognize these values. Isn't it ?
06-14-2010 09:43 AM
06-14-2010 09:45 AM
06-14-2010 09:49 AM
This is the device:
http://parts.digikey.com/1/parts/760645-mounting-brd-16-pos-w-50-conn-70rck16-hl.html
Ok I can attach a probe somewhere if I take it out of the housing it is in, but what will that tell me?
06-14-2010 09:54 AM
It is a TTL signal : if the line is on, you should measure a 5V signal, and if the line is off, you should measure a 0V signal.
Betweek the GND and each line, you should recognize the 11110111, which is the translation of your 247d. I think that it reverse the lines of the port, so you should measure only one port at ON, which is the 4th or the 5th, depending on how you're reading.
06-14-2010 09:56 AM
The #6 your seeing is the number of elements in the array not a value for the array.
Now for some deeper explainations. From the code it appears that exactly 1 of 6 valves may be used and an additional valve may be in one of two possible states.
When the program is run the cluster of buttons is initiallized to all False. and we enter the outer while loop where a sequence structure starts. In the first frame of the sequence we initiallize a shift register to hold the current value of "Buttons." and this loop runs unthrottled (Add a wait for next ms multiple to this loop to prevent using 100% of the CPU!)
For each iteration the buttons are read and if a change has occured to any value buttons that were previously True are reset to False to prevent opening more than one valve.
When the user presses OK or stop- the current "Buttons" value is passed to the next frame. This frame convertsthe 7 boolean values to a integer where each valve is controlled by a seperate bit of the integer (Isolation is bit 6 and bits 0-5 each control a mixing valve)
Now I'd strongly recommend reworking the DAQmx calls- it is pointless to initiallize the task each time you want to use it- Create the task in the initialzation case and wait until the user exits to destroy the task. And well a sequence structures are frowned on- (there are better ways to do this)
As far as adding a relay- right now the relays are associated to the hardware by their index position in the cluster (element 1 = bit 0 etc....) to add a new valve you would need to decide what bit you would use to drive it and code in that bits' value to write a 0 in that bit. (hint the 40 constant is realy 0x40 right-click>visable items>show radix )
Let me know if you need further elaboration