Loading Data from Mass Flow Controller with VDT2

I have data that needs to be queried via RS232 port that has this format:

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
It's possible that you are calling VDTRead2 before all of the characters have been received from the device. Try adding a Sleep/S 1 call.

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.
Igor Pro 6.12A, Windows XP Pro

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

Remove the VDTTerminalPort2 lines. The terminal port is for interactive use only, like a dumb terminal. I don't remember but this might be interfering.

That's the only problem that jumps out at me.
Still having trouble getting the proper output via VDT2. I found an NI-VISA driver for the Flow Controllers, and here is the process it uses:

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.


Quote:
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.


You can read byte-by-byte by using /N=1 with VDTRead2:
String result = ""
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:
String result
VDTRead2 /O=10 result
Print result

So, I figured out the problem. Since I was sending two Write commands to separate controllers, there were two lines of info in the input buffer when I sent the Read command. For some reason Igor's VDT2 didn't like this. I've changed the code to read after each setpoint write, and it works like a charm now.

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?

Quote:
Now, the next step is creating a background task that will graph the data in real-time. Any suggestions?


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.
hrodstein wrote:
Quote:
Now, the next step is creating a background task that will graph the data in real-time. Any suggestions?


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.


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