04.01.2015 Views

CR1000 Manual - Campbell Scientific

CR1000 Manual - Campbell Scientific

CR1000 Manual - Campbell Scientific

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Section 7. Installation<br />

• String declarations: String variables are memory intensive. Determine how<br />

large strings are and declare variables just large enough to hold the string. If<br />

the sensor sends multiple strings at once, consider declaring a single string<br />

variable and read incoming strings one at a time.<br />

The <strong>CR1000</strong> adjusts the declared size of strings. One byte is always<br />

added to the declared length, which is then increased by up to another<br />

three bytes to make length divisible by four.<br />

Declared string length, not number of characters, determines the<br />

memory consumed when strings are written to memory. Consequently,<br />

large strings not filled with characters waste significant memory.<br />

7.8.8.5.6 Demonstration Program<br />

CRBasic example Receiving an RS-232 String (p. 210) is provided as an exercise in<br />

serial input / output programming. The example only requires the <strong>CR1000</strong> and a<br />

single wire jumper between COM1 Tx and COM2 Rx. The program simulates a<br />

temperature and relative humidity sensor transmitting RS-232 (simulated data<br />

comes out of COM1 as an alpha-numeric string).<br />

CRBasic Example 40.<br />

Receiving an RS‐232 String<br />

'To demonstrate <strong>CR1000</strong> Serial I/O features, this program simulates a serial sensor<br />

'by transmitting a serial string via COM1 TX. The serial string is received at<br />

'COM2 RX via jumper wire. Simulated air temperature = 27.435 F, relative humidity = '56.789%.<br />

'Wiring:<br />

'COM1 TX (C1) ----- COM2 RX (C4)<br />

'Serial Out Declarations<br />

Public TempOut As Float<br />

Public RhOut As Float<br />

'Declare a string variable large enough to hold the output string.<br />

Public SerialOutString As String * 25<br />

'Serial In Declarations<br />

'Declare a string variable large enough to hold the input string<br />

Public SerialInString As String * 25<br />

'Declare strings to accept parsed data. If parsed data are strictly numeric, this<br />

'array can be declared as Float or Long<br />

Public InStringSplit(2) As String<br />

Alias InStringSplit(1) = TempIn<br />

Alias InStringSplit(2) = RhIn<br />

'Main Program<br />

BeginProg<br />

'Simulate temperature and RH sensor<br />

TempOut = 27.435<br />

RhOut = 56.789<br />

'Set simulated temperature to transmit<br />

'Set simulated relative humidity to transmit<br />

210

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!