beautypg.com

3 output programming basics, 4 translating bytes – Campbell Scientific CR1000 Measurement and Control System User Manual

Page 208

background image

Section 7. Installation

208 

 

 

7.8.8.5.3 Output Programming Basics

Applications with the purpose of transmitting data to another device usually
include the following procedures. Other procedures may be required depending on
the application.

1. Open a serial port (SerialOpen() command) to configure it for

communications.

• Parameters are set according to the requirements of the communications link

and the serial device.

• Example:

SerialOpen

(Com1,9600,0,0,10000)

• Designate the correct port in CRBasic.
• Correctly wire the device to the CR1000.
• Match the port's baud rate to the baud rate of the device in CRBasic.
• Use a fixed baud rate (rather than auto baud) when possible.

2. Build the output string.

• Example:

SerialOutString

= "*" & "27.435" & "," & "56.789" & "#"

Tip — Concatenate (add) strings together using & instead of +.
TipCHR() instruction is used to insert ASCII / ANSI characters into a

string.

3. Output string via the serial port (SerialOut() or SerialOutBlock() command).

• Example:

SerialOut

(Com1,SerialOutString,"",0,100)

• Declare the output string variable large enough to hold the entire

concatenation.

• Example:

Public

SerialOutString

As String

* 100

SerialOut() and SerialOutBlock() output the same data, except that

SerialOutBlock() transmits null values while SerialOut() strings are
terminated by a null value.

7.8.8.5.4 Translating Bytes

One or more of three principle data formats may end up in the

SerialInString()

variable (see examples in Serial Input Programming Basics

(p. 206)

). Data may be

combinations or variations of all of these. The manufacturer of the instrument
must provide the rules by which data are to be decoded.

Alpha-numeric: Each digit represents its own alpha-numeric value. For

example, R = the letter R, and 2 = decimal 2. This is the easiest protocol to
translate since the literal translation is what is received from the transmitting
instrument. Normally, the CRBasic program receiving the transmission will
be written to parse (split) the string up and place the values in CR1000
variables.