Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

NAN response from serial connection with Vaisala PTB330


whoneyc Sep 15, 2021 09:56 PM

I am attempting to Hello World a serial connection with a CR6-WIFI connected to a Vaisala PTB330 pressure sensor. I have attempted to follow the serial communications white paper for the datalogger, and I receive an "NAN" response. This is my first time using CRBasic, coming from Arduino, so I may be missing something obvious. Here is my code:

'CR6 Series

'Declare Variables and Units
Public BattV
Public PTemp_C
Public Temp_C
Public PBT330_TQFE as String * 50

Units BattV=Volts
Units PTemp_C=Deg C
Units Temp_C=Deg C

'Define Data Tables
DataTable(testasdf,True,-1)
DataInterval(0,2,Sec,10)
Average(1,Temp_C,FP2,False)
Sample(1,PBT330_TQFE,String)
EndTable

DataTable(Table2,True,-1)
DataInterval(0,1440,Min,10)
Minimum(1,BattV,FP2,False,False)
EndTable

'Main Program
BeginProg
'Open Serial port
SerialOpen(COMU3, 4800, 26, 0, 25)
'Main Scan
Scan(500,mSec,4,0)
'Default CR6 Datalogger Battery Voltage measurement 'BattV'
Battery(BattV)
'Default CR6 Datalogger Wiring Panel Temperature measurement 'PTemp_C'
PanelTemp(PTemp_C,60)
'Type T Thermocouple measurements 'Temp_C'
TCDiff(Temp_C,1,mv200C,U1,TypeT,PTemp_C,True,0,60,1,0)
SerialOutBlock(COMU3,"TQFE ?",6)
Delay(0,5000,mSec)
SerialInRecord(COMU3,PBT330_TQFE,&h02,0,&h0D,PBT330_TQFE,01)
'Call Data Tables and Store Data
CallTable testasdf
CallTable Table2
NextScan
EndProg

Wiring is a 3-Wire RS-232 type connection using the RX/TX/Gnd terminals on the PTB330.

Simple Description of Operations

In the code, I attempt to send ``TQFE ?`` via serial, which is the command required by the Vaisala to read a temperature value (picked arbitrarily as my Hello World variable). I delay for a moment, then I request bytes to be stored in PBT330_TQFE with that length.

Results

The expected result is a string which looks like: "T 123.45 C". The observed result is "NAN".

What I've Tried

I have played with portions of the code here to no avail, this includes: changing the delay length, the line begin char, and the line termination char. I am particularly suspicious of the line ending char, since the protocol guide for the PTB330 is decidely vague on the subject. I would normally assume a EOL or null termination, but the guide only vaguely hints at LF and CR symbols.

I attempted to analyze the communications using the terminal emulator. When I do so, I only see the OUT message:

"12.34.56.000 T TQFE ?"

and nothing following it. I can't tell without pulling out my oscilloscope if the sent message is sending a response. The "NAN" I see in the data viewer is likely an empty or overrun string.

My Questions

Why am I not receiving a response from the sensor? Is there something obvious I have messed up? Does anyone have any experience with this instrument?


Nico Sep 21, 2021 05:08 AM

1) I get a compile error if I run your code in Loggernet/CRbasic:

[Version]E:\Data_LoggerNet\Lib\Compilers\CR6Comp.exe VERSION:CR6.Std.06.08 DATE:06/21/2017
NoName0.CR6 -- Compile Failed!

line 40: Scan interval too short for measurement by 4572 mSec.
Error(s) detected in the program. Double-click an error above to navigate to it.

2) the PTB330 user manual mentions TWO serial ports.. one is called 'service' and the other is called 'user'.
The service port should be the one that is for service only (connect to it for maintenance) and its settings will be fixed and not be customizable.. the user port on the other hand can be in all sorts of states.
Which one are you using?
Have you had access to the unit via the service port and a computer to check on the settings the user port has?

https://www.vaisala.com/sites/default/files/documents/PTB330_User_Guide_in_English.pdf

"In the code, I attempt to send ``TQFE ?`` via serial, which is the command required by the Vaisala to read a temperature value.."

According to the manual I linked this command sets the temprature for QFE corrected pressure (page 69) ?!?

Is this your first serial sensor?
You might want to try to use a computer with a terminal program with the sensor only (put the CR6 aside) and follow the manual on how to talk to the sensor.. The 'HowTo' starts at page 65 and will give you a terminal example on page 72.

I would try 'VERS' or 'SERI' or '?' via the service port first to see that your temrinal session is set up properly.. then advance from there (see page 68 and ongoing) to undertand how to interogate the sensor.. I'd say command 'SEND' will give you the current readings in the format that is configured and which your logger later needs to cut into pieces (string operations) to make sensible values from you can store.


whoneyc Sep 30, 2021 01:42 AM

Thanks for the suggestions, Nico.  I found the actual error that was causing problems, but I will respond to your points first.

1) I get a compile error if I run your code in Loggernet/CRbasic:

That's odd.  My guess is that came up because of the delay line, but I'm not sure.  Either way, with enough poking it should compile.

2) the PTB330 user manual mentions TWO serial ports.. one is called 'service' and the other is called 'user'.

I am using the "user" port with RX/TX lines from the screw terminals on the Vaisala to those on the logger.  Power is connected through a benchtop supply since the CR6 is unable to output 12V lines when connected via USB for debugging.

Have you had access to the unit via the service port and a computer to check on the settings the user port has?

That would be trivial with a terminal connection and an ethernet cord, but no I had not done that.

According to the manual I linked this command sets the temprature for QFE corrected pressure (page 69) ?!?

The code I was trying was based on the syntax on pg. 77.

Is this your first serial sensor?

No.  My PhD used serial sensors.  This is, however, my first CRBasic attempt.  Everything else was AVR/Arduino and x1000 times easier!  This program forces me to use Windows.  Gross.  Full Linux support when?

---------------------------------

The actual solution:

I wired it wrong.  The CR6 logger does not use 12V logic on the U pins I had plugged into, and only pins C1-4 are RS-485 compliant (ref).  U pins can only do serial logic between 0-5V.

I had to tweak the code a bit to play nice.  I sent a request string "R" (the actual code I need instead of "TQFE ?"), the line ending codon is &h0D0A and I used a line start codon of the leading space (&h20) so it would allow arbitrary length strings.  The string can be converted to a float with implicit typing.

If anyone wants to see my final "Hello World" code for this sensor, let me know.  I will post it here.  The only reason I did not do so already is that I'm at home now, away from the scary world of Windows computers.

Log in or register to post/reply in the forum.