How To Communicate With Instrutech Vacuum Gauge Via Serial Port


zhaolin8921

Recommended Posts

Hello,

 

I am pretty new to DaqFactory and serial communication. 

 

My task is to read the pressure readings from the gauge per 1 second and display the reading by a text field on front page.

 

I have set up the communications between the gauge and DaqFactory. In the Comm Monitor window, I got:

 

Tx: #01RD\013
Rx: *01 9.99E+09\013
Tx: #01RD\013
Rx: *01 9.99E+09\013
Tx: #01RD\013
Rx: *01 9.99E+09\013
 
The gauge is based on ask-answer. When I send #01RD\013, it will return the reading I want. 
 
My problem now is that I can't figure out how to do it by sequence in an automatic fashion. I tried the following code:
 
private string stin
private in
while(1)
   try
 device.vacuum_gauge.Purge()
 device.vacuum_gauge.Write("#01RD\r")
 stin = device.vacuum_gauge.ReadUntil(50)
   catch()
 ? strLastError 
   endcatch
   delay(1)
endwhile

But I get an error: 

 

C1136 Timeout: read_pressure Line 7

 

 

Can anyone help me? Thank you so much!

 

Lin

 
Link to comment
Share on other sites

Two problems:

 

1) you don't want \r.  You want:

 

device.vacuum_gauge.write("#01RD" + chr(13))

 

2) you don't want to read until 50.  50 is the binary code for the ASCII character '2'.  You want:

 

device.vacuum_gauge.readUntil(13)

 

which will read until the \013 in the output, the carriage return.

 

You'll then want to parse the result.  It looks fixed field, so you'll likely just do:

 

in = strToDouble(mid(stin,3,20))

Link to comment
Share on other sites

I'd create a channel for it.  Call it pressure, type = "Test", A to D, Channel and D# = 0, Timing = 0.  Then add this line after the in=strtoDouble(...)

 

pressure.addValue(in)

 

Then you can just display Pressure[0] in any of the screen controls, or plot pressure vs time in a graph.

Link to comment
Share on other sites

Use format():

 

format("%.3e", myVal)

 

If myVal = 1.2345e-6, then the result of the above is 1.235e-006.  Use E instead of e for 1.235E-006. The result is a string.  Format() works just like printf() a very common function.  The parameters are described in the user's guide section 4.12.9

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.