zhaolin8921 Posted October 16, 2013 Share Posted October 16, 2013 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 More sharing options...
AzeoTech Posted October 16, 2013 Share Posted October 16, 2013 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 More sharing options...
zhaolin8921 Posted October 16, 2013 Author Share Posted October 16, 2013 Thanks! It works! Just one more question, if I want to display the pressure value, in = strToDouble(mid(stin,3,20)), how should I do it on the front page then? Many thanks! Link to comment Share on other sites More sharing options...
AzeoTech Posted October 16, 2013 Share Posted October 16, 2013 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 More sharing options...
zhaolin8921 Posted October 16, 2013 Author Share Posted October 16, 2013 Thank you so much! It works just the way I want! Link to comment Share on other sites More sharing options...
zhaolin8921 Posted October 17, 2013 Author Share Posted October 17, 2013 Hey, I just come up with another simple question. I would like to display my result in a scientific notation (e.g. 1.23E+08) in a text box (display->variable value). But I can't find where I can change the format. Could you help me? Thanks! Link to comment Share on other sites More sharing options...
AzeoTech Posted October 17, 2013 Share Posted October 17, 2013 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.