(only available for certain terminals with a special, modified implementation of the CANopen protocol)
This document describes how the terminal's asynchronous serial interface can be accessed through the interpreter. These functions can be used to communicated with remote equipment, like voltmeters with RS-232 interface, modems, etc. For GPS receivers, there is a separate decoder built inside the firmware (which is not the scope of this document).
Note: Only very few terminals support this function - see Feature Matrix : "serial port access") !
This feature must be unlocked (by the manufacturer,
or via password) before using it .
The same applies to the script
language - it must also be unlocked before you can use it to access the
serial ports .
See also:
Screenshot of the serial port settings in the programming tool.
The serial port selected here will appear as device "serial1" in the simulation.
file.open("serial1/<baudrate>)
(script command to open a "file", in this case a serial port)
ser.baud
(old display interpreter command)
@ser.baud=19200
sets the baudrate for the serial port to 19200 bit/sec.
ser.prot
(old display interpreter command)
ser.term
).ser.term
ser.rstr
ser.rcvd
ser.rclr
ser.rbuf
ser.rbcnt
ser.clr
(interpreter
command, not a function - returns no value)
ser.tx(<string-expression>)
(interpreter command)
For a special application, the reception and transmission of binary data block was implemented in a special terminal firmware. The following display interpreter commands (and functions) can handle binary data blocks sent or received via the terminal's asynchronous interface ("RS-232"). In this context, "tbin" means "transmit binary", and "rbin" means "receive binary".
ser.rbin.l
(lower case L) = length of the received binary
block.
ser.rbin.b[0]
,
ser.rbin.b[1]
,ser.rbin.b[2]
, ... etc .
ser.rbin.b[<n>]
= accesses the <n>-the byte
in the received binary block.
ser.rbin.dump
: dump of the received binary block (in
hexadecimal notation).
ser.rbin.send
: sends(!) the previously received binary
block (possibly after being modified through other commands)
ser.rbin.ti
= number of milliseconds passed since the
last byte was received (and appended to the binary block).
Almost the same components are available to transmit binary blocks. The following commands can be used to assemble a block under interpreter control, which can be sent through the serial port.
ser.tbin.l
(lower case L) = length of the transmitted
binary block.
ser.tbin.b[<n>]
= sets the <n>-the byte in
the transmittable binary block.
ser.tbin.dump
: dump of the transmittable block (in
hexadecimal notation).
ser.tbin.send
: sends(!) the previously assembled binary
block.
ser.tbin.b[0]
....
ser.tbin.b[ser.tbin.l - 1]
will be transmitted as fast as possible
through the serial port ("RS-232").Some examples for binary data blocks:
ser.tbin.dump=010203FF : REM fill the TX-block with 4 bytes (hex
0x01 0x02 0x03 0xFF)ser.tbin
= ser.rbin : REM copy received block into transmit
block
ser.tbin.b[2]=0x12 : REM replace the 3rd(!) byte with hex 12
ser.tbin.b[1]=ser.tbin.b[0] : REM copy the 1st(!) receive byte into the 2nd(!)
TX-byte
ser.tbin.send : REM send the binary block
Handling received data blocks is quite complicated with the UPT's global (or local) event definitions. To be honest, the terminal was never designed for such low-level processing. But at least, with the ser.rbin functions, you can detect if something was received, how many bytes were received, and you can access the received data byte-by-byte. Of course, you won't be able to implement complicated serial protocols this way - such a task requires a fully grown up programming language (which the terminal's interpreter is not).
The script language greatly simplifies the use of the serial port(s) for your own purpose (see details about the script language in another document).
Unfortunately, the script language is only available for devices with a 32-bit CPU, furthermore the file I/O functions which are used to access the serial ports from a script belong to the 'extended script functions' which must be unlocked before they can be used.
For details about the general use of the file I/O functions, please refer to the script language reference .
Use the file.open command, with
a device name (instead of the filename) like "serial1" for the first serial
port, or "serial2" for the second port.
These pseudo-filenames can
optionally be extended with additional parameters, which instruct the system
how to open a serial port:
handle := file.open("serial1/9600") // open the first serial port
with 9600 bits/second
Use the file.read_line function to read the input stream from the serial port, line by line, separated with CARRIAGE RETURN characters (or CR + NL).
To send a line of text, use file.write, and add a carriage return + new line at the end of the line (Unix users will leave away the 'new line' character).
For a complete example, see the script language documentation. Don't miss the explanation of the 'Serial Port Demo'. It uses a script to shows all lines received from both serial ports on the LCD (at least for the MKT-View II, which has two serial ports which can be accessed from the script) :
Standard 9-pole "D-sub" connector,
female, usually found on the "DCE" side (modem, or "Null-Modem"
cable).
Signals which are not available (or not always available) on the display
terminal are written in parentheses in the table below .
Caution: The "GPS-Mouse-Port"
on the MKT-View II is NOT COMPATIBLE with this RS-232 connector !
Pin Number | Signal Name | Direction (at the "DCE" side), Remarks |
1 |
( DCD ) |
not available |
2 |
TxD |
input (!) |
3 |
RxD |
output (!) |
4 |
( DTR ) |
data terminal ready, not available |
5 |
GND |
signal ground |
6 |
( DSR ) |
data set ready, not available |
7 |
( RTS ) |
request to send, not available |
8 |
( CTS ) |
clear to send, not available |
9 |
( RI ) |
ring indicator, not available |
Standard 9-pole "D-sub" connector, male, usually found on
the "DTE" side (for example, on the back of a PC).
Signals which are not available (or not always available) on the display
terminal are written in parentheses in the table below .
Pin Number | Signal Name | Direction (at the "DTE" side), Remarks |
1 |
( DCD ) |
not available |
2 |
TxD |
output |
3 |
RxD |
input |
4 |
( DTR ) |
data terminal ready, not available |
5 |
GND |
signal ground |
6 |
( DSR ) |
data set ready, not available |
7 |
( RTS ) |
request to send, not available |
8 |
( CTS ) |
clear to send, not available |
9 |
( RI ) |
ring indicator, not available |
Non-Standard
9-pole "D-sub" connector, female, used at the 'GPS-Mouse-Port'
in the MKT-View II.
Caution: This "GPS-Mouse-Connector" on the MKT-View
II is NOT COMPATIBLE with a standard
RS-232 connector !
Pin Number | Signal Name | Direction (from the MKT-View's point of view), Remarks |
1 |
- |
|
2 |
"RxD" (in doc #85512) |
input (!); NMEA data from the GPS into the MKT-View |
3 |
"TxD" (in doc #85512) |
output (!); commands from the MKT-View to the GPS |
4 |
- |
|
5 |
GND |
signal ground |
6 |
"VON" |
Supply Voltage ! (output from MKT-View to the GPS) |
7 |
- |
|
8 |
- |
|
9 |
"VBAT" |
permanent supply voltage for standby-mode |
There is a small test file for the MKT-View which demonstrates some of the possibilities using only the display interpreter. You can load it from \programs\ser_test.cvt .
On the first display page, the configuration of the serial port is displayed, and the last received string is shown on the terminal's screen. Furthermore, you can send a test string from this page (which may be edited on the screen also).
The ser.rbuf function shows the buffer for the currently received (still
"incomplete") line of text.
The ser.rsts function contains the last "complete" line.
In the lower part, a few test patterns for the ser.rcvd function are show. Watch the results when sending different strings to the terminal, which contain the string "hello" (only), "hello this is a test", and "this is a test". You will quickly get an impression how this function can be used to detect special patterns in the received text.
In the event definitions of this page, the terminal looks for the string "help" in the received data. If this string is detected, it calls(!) a different page, from which a short help text is transmitted through the serial port in response to the "help"-command.
Other
event definitions on this page parse numeric values from the received data.
For example, the variable 'X' will be set to the numeric value contained
in the first 8 characters of a received string. By replacing the Event
always
by something like
ser.rcvd("$GPRMC*"), you may be able to parse navigation information from
a GPS receiver (though for GPS/NMEA-0183, there is a specialized decoder
in the terminal firmware, so you don't need the interpreter to decode GPS
position data).
Originally, the serial port was exclusively used to download the terminal application ("user program") through the PC's RS-232 interface. Since the serial port may now be occupied by the application, the terminal cannot (always) listen for commands from the PC. Why ?
The program download between PC and Terminal uses a block-oriented protocol for the serial port called "3964R". When you select "Send application to the terminal through the serial port", but the serial port is occupied by the application (as described in this document), the 3964R-handler may be passive to avoid interference with the protocol which your terminal-application uses (through appropriate interpreter commands). The PC will therefore never receive the expected response from the terminal .... and your terminal application will, at least, be "irritated" by the characters received from the serial port.
So what to do in this case, when your application occupies the terminal's serial port, but you want to download a new application through just this port ? The answer is:
The terminal will reprogram the serial port for communication with the PC in this case, which includes the initialisation of the 3964R-protocol.
If the serial port is not occupied by the terminal-application (which is the default, see ser.prot), you don't necessarily have to use the system menu to activate the download.
File: ..?..\uptwin1\help\sercmd_01.htm
Author: W.Büscher, MKT Systemtechnik
Last modified: 2007-01-08 (ISO8601, YYYY-MM-DD)