beautypg.com

Basic programming guide – Remote Processing BASIC for the CX-10 Modbus User Manual

Page 51

background image

BASIC PROGRAMMING GUIDE

2-42

PRINT
PRINT #,
P.
?

Syntax:

PRINT expr
P. expr
? expr
PRINT#port,expr
P.#port,expr
?#port,expr
Where: expr = any string, mathematical number, or calculation

port = serial output port 0 or 1. Your card may have more ports.

Function:

Prints value of expr to a serial port

Mode:

Command, run

Use:

PRINT "String",$(0),REGREAD(9)*.007214

DESCRIPTION

PRINT is used to send serial data to any port. Default is COM 0. PRINT #n may be used to write data out of
a modbus port.

If there is no expr, a carriage return - line feed combination is sent. expr is any combination of
instructions/operators and variables, strings, or literal values. More than one expr may be output by
separating them with commas. Values are printed with a leading and trailing space; a list of positive values
separated by commas will thus print with two intervening blanks. A "+" is implied. The "-" symbol precedes
negative values and takes the place of the normal preceding space. Strings and literals are output with no
added blanks. If a comma is the last character in the list then the normal is suppressed.

The shorthand versions P. and ? are converted to PRINT after each program line is entered, so a P. or ? is
never listed.

The PRINT#port, instruction functions exactly like the PRINT instruction, but it directs output to the
designated serial port. When using this syntax, any output directed by the UO command is bypassed.

P.# and ?# are shorthand for PRINT#.

When PRINT #n is used for a modbus port, a required number of parameters in a specific sequence is
required. Modbus transaction types supported are 3 and 16. These are query and write, respectively.
Generally, a modbus ID and register number are required,

A modbus query (read from a slave or other device on a network) is as follows:

PRINT #n,id,3,address,length

Where: n = modbus port number on board. This is usually 1 or 3 or both. Refer to your board manual.

Id = modbus ID of device you want to get data from
address is valid modbus address
length is number of registers to return

After a query, you will want to retrieve the data. This is done through a number of registers and is board
dependent. Generally registers 4781-4786 are used to retrieve data. Refer to your boards manual for specific
information.

A modbus write (write to a slave on a modbus network) is as follows: