2-661
2 Instruction Descriptions
NJ-series Instructions Reference Manual (W502)
Communications Instructions
2
SerialSend
• You cannot use this instruction in the primary periodic task.
• An error occurs in the following cases. Error will change to TRUE.
• The serial communications mode is not set to No-protocol Mode when the instruction is executed.
• The value of _Port_isAvailable is FALSE.
• The value of Port.UnitNo or Port.PhysicPortNo is outside of the valid range.
• There is no CJ-series Serial Communications Unit with the specified unit number.
• The value of SendSize is outside of the valid range.
• The value of SendSize exceeds the size of SrcDat[].
• Communications fail.
• The instruction is executed during a Unit restart.
• For this instruction, expansion error code ErrorIDEx gives the communications response code. The
values and meanings are listed in the following table. An expansion error code is output to ErrorIDEx
when the value of error code ErrorID is WORD#16#0800.
In this sample, a no-protocol command is sent to the barcode reader that is connected to serial port 2 of
a CJ-series Serial Communications Unit (unit number 0, device name ‘Barcode’). The Read Scene
Number command (@READ) is sent. The send data is the contents of the array variable SendDat[].
There is no start code and the end code is 16#OD (CR).
The settings of Serial Communications Unit are given in the following table.
Value Meaning
16#00000401 The serial communications mode is set to Protocol Macro, NT Link, Echoback Test, or
Serial Gateway Mode.
16#00000205 The serial communications mode is set to Host Link Mode.
16#00001001 The command is too long.
16#00001002 The command is too short.
16#00001003 The value of SendSize does not match the number of send bytes.
16#00001004 The command format is incorrect.
16#0000110C This is another parameter error.
16#00002201 The SerialSend or SerialRcv instruction is already in execution.
16#00002202 The protocol is being switched, so execution is not possible.
Sample Programming
Item Set value
Port 2: User-specified Setting Inclusion User settings
Port 2: Serial Communications Mode No-protocol
Port 2: Data Length 8 bits
Port 2: Stop Bits 1 bit
Port 2: Parity No
Port 2: Baud Rate 38,400 bps
Serial Communications Unit
with unit number 0
Barcode reader
Serial port 2
Command sent.