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.

Programming CR1000 for a CS120 Sensor


trashbk Jun 15, 2012 10:49 AM

Dear all,

I have a CS120 visibility sensor and cannot get my CR1000 datalogger to read it.

The SC120 is working in continuous mode, if I connect with a Terminal Emulator I get the Full Format Message every 60 seconds - that means, the sensor is fine.
To the CR1000, the sensor is connected with a Gender Changer on the RS232 port because the cable has a female connector same as the logger.

Now I have the following CRBasic code in the slow sequence section:

'Measure visibility
SlowSequence
Scan (1,Sec,0,0)
SerialOpen (ComRS232,38400,3,0,10000)
SerialIn (InString,ComRS232,100,0,1000)
Visibility = Mid(InString,10,5)
VisibilityOutput=Replace(InString," ",",")
SerialClose(ComRS232)
NextScan

I do not understand why there is no string detected.

Does anybody have an idea?

Best regards


trashbk Jun 15, 2012 10:59 AM

Addition:

With a scan interval of 1s I get many many skipped scans - appears to me that this commands take more than 1s to complete, is that right?


aps Jun 15, 2012 11:59 AM

First to explain:
a) when you use SerialOpen the input buffer is flushed, so any data previously captured will be lost.
b) in your Serialin instruction you have set the timeout to 1 sec. This means that the scan (with the other instructions) will take longer than 1 second, hence the skipped scans.

The program below is about the most basic you can get for reading the automatic output. A few points to note:
i) if you set the scan rate faster than the output rate the reading will be NaN (no data) as the output is updated every scan. You can change the parameter at the end of the serialinrecord instruction to "hide" missing values.
ii) the com port in the example is COM2 - ammend as needed.
iii) I use serialinrecord using the start and end characters of the message to be sure we capture the whole message.
Clearly the program needs other code added to store data and capture other variables too.
---------
'CR1000
'Declare Variables and Units
Public InString As String * 60 'Incoming string
Public SerialIndest(16), NBytesReturned
Public Visibility
'Main Program
BeginProg
SerialOpen (Com2,38400,3,0,1000)
Scan(60,Sec,1,0)
SerialInRecord (Com2,InString,02,0,03,NBytesReturned,01) 'Read any data in the buffer
SplitStr (SerialIndest(),InString,"",16,0) 'Split out the data into numeric readings
Visibility=SerialIndest(5) 'For this example just extract the visibility
NextScan
EndProg

* Last updated by: aps on 6/15/2012 @ 6:03 AM *


trashbk Jun 15, 2012 03:49 PM

Dear Andrew,

thank you for the quick response.

I do not get the code to work. If I take exaclty your code and only change the COM port to ComRS232 it should work, right?

Is a gender changer on the RS232 correct or should it be a Nullmodem adapter?


Another point: I tried to send the POLL command to the CS120 with a terminal emulator when it is in "polled" mode, but this does not return an answer. Entering the configuration menues works, though. Is POLLing from a PC not possible?

Best regards


trashbk Jun 15, 2012 03:54 PM

Additional Info: I know that the CS120 is sending output strings, these are displayed in TeraTerm when I connect the CS120 to the PC in continuous mode.


aps Jun 15, 2012 04:22 PM

I think your problem will be a connection issue. The sensor is supplied with a rewirable connector supplied for initial connection to a PC for config and testing.

If you want to connect to the logger serial port you will need both a gender change and null modem connection. You can achieve the latter simply by rewiring the connector, swapping the wires to pins 2&3. Alternatively wire into one of the control port COM ports.


trashbk Jun 15, 2012 04:37 PM

It was indeed using a Nullmodem adapter - I found one in a corner of the workshop and just tried it. And it works instantaneously.

Polled mode and continuous works.

Thank you anyways, I did not know the SerialInRecord, that is much nicer.

Thank you and a nice weekend.


trashbk Jun 19, 2012 08:37 AM

Dear all,

I still have a problem with the data acquisition of the CS120 with the CR1000.
The Outstring and Instrings are looking good, also the splitstr command is working very well.
The only thing is that I get NAN values in my 1min-average DataTable.

Does anybody has an idea what I can change in my program code to avoid the NANs?

Best regards.


The related program code is:

Public OutString As String * 40 ' Outgoing string
Dim CheckVal As Long ' Checksum value
Public InString As String * 60 ' Incomming string
Public SerialIndest(16), NBytesReturned, Visibility
Dim TempString As String * 16
Public VisibilityOutput As String *150

BeginProg
' open port to the visibility sensor
SerialOpen (ComRS232,38400,3,0,10000)

'Measure visibility
SlowSequence

Scan (60,Sec,1,0)
' Send request for information once every 60 seconds


' Create the POLL string going out to the CS120
TempString = "POLL:0:0"
CheckVal = CheckSum (TempString,1,0) ' Use the CCITT CRC16 checksum
OutString = CHR(2) + TempString + ":" + FormatLong (CheckVal,"%04X") + ":" + CHR(3) + CHR(13) + CHR(10)
SerialOut (ComRS232,OutString,"",0,100) ' Send POLL request to the CS120

Delay (1,1,Sec)
SerialInRecord (ComRS232,InString,02,0,03,NBytesReturned,01) 'Read any data in the buffer
SplitStr (SerialIndest(),InString,"",16,0) 'Split out the data into numeric readings
Visibility = SerialIndest(5)

SerialFlush (ComRS232)

NextScan

DataTable (MinAvg,True,28800)
OpenInterval
DataInterval (0,1,Min,10)
Average (1,Visibility,FP2,False)
EndTable

EndProg


aps Jun 19, 2012 01:09 PM

I have been looking at similar reports recently. What you are seeing could be due to two problems. The first is due to an ommission in the manual - sorry for that. When you use the poll command the sensor waits till the end of the current second (on its timebase), works out the measurement in that second, then calculates the last minute average and outputs the data. This means you could have to wait for up to one second for the sensor to output which makes the maximum poll rate just slower than 1 Hz, i.e. you will get some NaN values if polling at 1 Hz as the sensors timebase drifts in and out of phase relative to the logger. We have also had a report that very occasionally the CS120 will miss a poll request - this is being investigated.

One solution to occasional bad or missed values (which can apply in any system) is to use the control parameter at the end of the average (and other similar) instructions, e.g.

Average (1,Visibility,FP2,Visibility=NaN)

This will prevent a NaN getting added into the statistic, unless of course the value being averaged is NaN for the entire averaging period.

On other thing to bear in mind with the CS120 is that it outputs a one minute average (rolling average) anyway so you will be averaging a rolling average.

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