Loading Data from Mass Flow Controller with VDT2
jpepper83
B +050.08 +026.92 +000.00 +000.00 000.00 O2
I tried using VDTRead2 but can't seem to get any data past the first period. I need to query the controller every time I change the setpoint via VDTWrite2 (which works fine for me, by the way), and append the data to "history," if possible.
I've been working on this for a few days now, and can't get it to work. Any help would be great! Thanks!
JP
Or, as a debugging tool, execute this:
VDTGetStatus2 0, 0, 0; Print V_VDT
before calling VDTRead2 to determine the number of characters in the RS232 input buffer.
If that does not get you unstuck, please post the commands you are executing.
Also include your Igor version and OS.
Also, let me know what the device is sending as the terminator character. Typically this is carriage-return, linefeed or carriage-return+linefeed. Consult the device's documentation to make sure you know what it is sending.
October 1, 2010 at 05:36 pm - Permalink
Function is below:
//Start Button-----------------------------------------
Function Start(ctrlName):ButtonControl
String ctrlName
NVAR QA1, QB1
Variable ISA=QA1*64000/50
Variable ISB=QB1*64000/50
String ISA2MFC=num2istr(ISA)
String ISB2MFC=num2istr(ISB)
String /G StartData
VDTOpenPort2 'COM1'
VDTOperationsPort2 'COM1'
VDTTerminalPort2 'COM1'
VDT2 /P='COM1' baud=19200,databits=8,stopbits=1, parity=0,echo=1
VDTWrite2 "A"+ISA2MFC+"\r" +"B"+ISB2MFC+"\r"
VDTWrite2 "A" +"\r"
VDTTerminalPort2 'COM1'
VDTGetStatus2 0,0,0;Print V_VDT
VDTRead2 StartData
Print StartData
End
I get this in history when button is pressed:
0
A +06&
The Actual data should look like I gave above.
With "Sleep" command, history shows this:
84
A +06€
--------------------
Mass Flow Controller sends and receives line ends with "\r".
Thanks,
JP
October 4, 2010 at 12:07 pm - Permalink
That's the only problem that jumps out at me.
October 4, 2010 at 03:15 pm - Permalink
1) Sends a query command to MFC: A
2) Reads the buffer byte by byte until it reaches a " " and "\r", at which it ceases and clears the session with the Flow Controller.
3) Once it has the return string: B +050.08 +026.92 +000.00 +000.00 000.00 O2, it parses each value and creates a variable to set each value to, and sends the remainder of the buffer along to parse the next value...
-->Pressure=+050.08, Buffer=+026.92 +000.00 +000.00 000.00 O2
-->Temperature=+026.92, Buffer=+000.00 +000.00 000.00 O2
-->Vol. Flow=+000.00, Buffer=+000.00 000.00 O2
-->Mass Flow=+000.00, Buffer=000.00 O2
-->Setpoint=000.00, Buffer=O2
-->Gas=O2
I think I can use the SplitString operation to parse the values, but I need to be able to read the whole string from the buffer first, and VDT2Read is not doing the trick. Any suggestions? Again, I want to read byte-by-byte until the whole string is formed, then parse the string into individual variables.
Thanks.
June 1, 2011 at 12:53 pm - Permalink
You can read byte-by-byte by using /N=1 with VDTRead2:
String byte
do
VDTRead2 /N=1 /T="" /O=10 byte
if (char2num(byte) == 13) // CR?
break
endif
result += byte
while(1)
Print result
However, since CR is by default a terminator character for VDTRead2, you should be able to simply do this:
VDTRead2 /O=10 result
Print result
June 1, 2011 at 02:47 pm - Permalink
The code:
Function Start(ctrlName):ButtonControl
String ctrlName
NVAR QA1, QB1
Variable ISA=QA1*64000/50
Variable ISB=QB1*64000/50
String ISA2MFC=num2istr(ISA)
String ISB2MFC=num2istr(ISB)
String /G SCh, SPress, STemp, SVFR, SMFR, SSLPM, SGas
String AResponse, BResponse
COMINIT()
VDTWrite2 "A"+ISA2MFC+"\r"
VDTRead2 /T="\r" AResponse
Print AResponse
VDTWrite2 "B"+ISB2MFC+"\r"
VDTRead2 /T="\r" BResponse
Print BResponse
Here's the output:
A +065.43 +026.13 +002.96 +013.11 011.80 N2
B +064.68 +026.28 +000.63 +002.75 003.14 O2
Now, the next step is creating a background task that will graph the data in real-time. Any suggestions?
June 1, 2011 at 03:41 pm - Permalink
In Igor Pro 6.20 or later, choose File->Example Experiments->Programming->Slow Data Acq.
This uses a thread to acquire data and a named background task to retrieve it from the thread and display it. You don't need the thread and can't use it because VDT2 is not thread-safe. However, you can use the background task code from that experiment.
June 1, 2011 at 06:33 pm - Permalink
I am doing something very similar to this and have the same problem with graphing the data vs. real time. The Slow Data Acq code is too overwhelming for my level of coding. Can you be a little more specific on how to display this data vs. time ?. Data points are accumulated through a ForLoop
November 10, 2015 at 12:27 pm - Permalink