Am attempting to interface a Vaisala PTB330 over RS232 to a CR6 datalogger via the user terminals.
For clarity, the PTB330 is wired to the CR6 as such
PTB330 - User Port RS232 TX to CR6 C2
PTB330 - User Port RS232 RX to CR6 C1
PTB330 - User Port RS232 GND to CR6 GND
_________________________
The PTB330 Serial settings are:
9600b/s
8N1
Poll Adress:0
________________________
I've confirmed the unit is outputting barometric pressure as an ASCII string in a 6 digit format with 2 decimal places via connecting directly with Putty ie.
1014.15
1014.18
I am having issues with converting this data to a floating point number to be logged within the unit as currently the output to the CR6 registers as NAN(Not a number).
At first I wanted to try and read it as a string, but I'd prefer the data stored directly as a floating point into a table for ease of use.
I've tried a few different approaches with trying to store the string inside a variable then convert it to a float before outputting it in the table. However I cannot seem to get it to work.
'CR6 Series 'Created by Short Cut (4.7) 'Declare Variables and Units Public BattV Public PTemp_C Public AirTC Public RH Public WS_ms Public WindDir Public RawTempV Public RawHumidV Public RawBuffer As String * 50 Public CleanPressure As String * 20 Units BattV = Volts Units PTemp_C = Deg C Units AirTC = Deg C Units RH = % Units WS_ms = meters/second Units WindDir = degrees 'Define Data Tables DataTable(Hourly, True, -1) DataInterval(5, 60, Sec, 10) MQTTPublishTable(1,0,10,Min,2,0,0,0) Minimum(1, BattV, FP2, False, True) Maximum(1, BattV, FP2, False, True) Minimum(1, PTemp_C, FP2, False, True) Maximum(1, PTemp_C, FP2, False, True) Minimum(1, AirTC, FP2, False, True) Maximum(1, AirTC, FP2, False, True) Minimum(1, RH, FP2, False, True) Maximum(1, RH, FP2, False, True) Maximum(1, WS_ms, FP2, False, True) Minimum(1, WS_ms, FP2, False, True) Sample (1, WindDir, FP2) Sample (1, CleanPressure, String) EndTable DataTable(Seconds, True, -1) DataInterval(5, 60, Sec, 10) MQTTPublishTable(1,0,10,Min,2,0,0,0) Minimum(1, BattV, FP2, False, False) Sample (1, AirTC, FP2) Sample (1, RH, FP2) Sample (1, CleanPressure, String) EndTable 'Main Program BeginProg SerialOpen(COMC1, 9600, 0, 0, 25) 'Main Scan Scan(5, Sec, 1, 0) Battery(BattV) PanelTemp(PTemp_C, 60)
'Poll PTB330 & Read ASCII SerialOutBlock(COMC1, "SEND", 4) Delay(0, 500, mSec) SerialInRecord(COMC1, RawBuffer, &H20, 0, &H0D, RawBuffer, 1) If RawBuffer <> "" Then ' The idea here is to trim and convert to float, then format to "XXXX.XX" Sprintf(CleanPressure, "%06.2f", Float( Trim(RawBuffer) )) EndIf 'MP100A Temp & RH Sensor VoltSE(AirTC, 1, mV1000, U1, False, 0, 60, 0.1, 0) VoltSE(RawTempV, 1, mV1000, U1, False, 0, 60, 1, 0) VoltSE(RH, 1, mV1000, U2, False, 0, 60, 0.1, 0) VoltSE(RawHumidV, 1, mV1000, U2, False, 0, 60, 1, 0) If (RH > 100) AND (RH < 108) Then RH = 100 '05103 Wind Sensor PulseCount(WS_ms, 1, U6, 5, 1, 0.098, 0) BrHalf(WindDir, 1, mV5000, U4, U3, 1, 2500, True, 20000, 60, 355, 0) If (WindDir >= 355) OR (WindDir < 0) Then WindDir = 0 CallTable Hourly CallTable Seconds NextScan EndProg
The
Sprintf(CleanPressure, "%06.2f", Float( Trim(RawBuffer) ))
doesn't feel like the right way to do it.
Any assistance would be greatly appreciated.