9. Program
9.4. Variables
The variables used in this program are listed below.
9.4.1. List of Variables
The following tables list the data types, external variables (user-defined global variables/device variable for CJ-series Unit/system-defined variable) and internal variables that are used in this program.
●Data type (Structure)
[Communications processing status flags]
Name Data type Description
sStatus STRUCT Structure of communications processing status flags Busy BOOL
Communications processing in progress flag TRUE: Processing is in progress.
FALSE: Processing is not in progress.
Done BOOL Communications processing normal end flag TRUE: Normal end / FALSE: Other than normal end Error BOOL Communications processing error end flag
TRUE: Error end / FALSE: Other than error end
[Communications instruction execution flags]
Name Data type Description
sControl STRUCT Serial communications instruction execution flags
Send BOOL Send processing instruction
TRUE: Executed / FALSE: Not executed
Recv BOOL Receive processing instruction
TRUE: Executed / FALSE: Not executed
[Timer enable flags]
Name Data type Description
sTimerControl STRUCT Time monitoring timer enable flags
Tfs BOOL Send processing time monitoring timer instruction TRUE: Enabled / FALSE: Not enabled
Tfr BOOL Receive processing time monitoring timer instruction TRUE: Enabled / FALSE: Not enabled
Tr BOOL Receive waiting time monitoring timer instruction TRUE: Enabled / FALSE: Not enabled
[Send/Receive processing required/not required setting flags]
Name Data type Description
sComType STRUCT Send/Receive processing required/not required setting flags
Send BOOL
Send processing TRUE: Required / FALSE: Not required
*Specify this when sending a command.
Receive processing TRUE: Required / FALSE: Not
●Data type (Union) [Error code processing]
Name Data type Description
uErrorFlags UNION Error code processing union
BoolData ARRAY[0..15]
OF BOOL
2-byte error code is processed in units of 1 bit as 16-bit string.
: TRUE (Error) / FALSE (Normal)
•Communications error
BoolData[0]: Send processing BoolData[1]: Receive processing
•Timeout error
BoolData[8]: Send processing BoolData[9]: Receive processing BoolData[14]: Receive wait
•Others
BoolData[2..3,6..7,10..11,13]: Reserved BoolData[4]: Processing number error
BoolData[5]: Send/Receive required/not required detection error
BoolData[12]: Destination device error BoolData[15]: Transmission error
WordData WORD 2-byte error code is processed as WORD at once.
●External variables
[User-defined global variables]
Variable name Data type Description
Input_Start BOOL
Communication start switch
The program starts when this flag changes from FALSE to TRUE.
Output_RecvMess STRING[256] An area that stores the receive data (response) (256 bytes)
Output_ErrCode WORD
An area that stores the error flag for a communications error or a timeout error that is detected at the send processing or receive processing.
Normal end: 16#0000 Output_CmdsErrorID WORD
An area that stores the error code for an error that is detected at the send processing or receive processing.
Normal end: 16#0000
Output_CmdsErrorIDEx DWORD
An area that stores the extension error code for an error that is detected at the send processing or receive processing.
Normal end: 16#00000000 Output_TransErrCode WORD
An area that stores the transmission error status (J01_P2_TransErrSta) at a communications error.
Normal end: 16#0000 Output_MErrCode DWORD
An area that stores the destination device error code for a destination device error.
Normal end: 16#00000000
Output_ReceiveLength INT An area that stores the receive data size
[Device variables for CJ-series Unit] (Serial Communications Unit)
Variable name Data type Description
J01_P2_NopSerialSendExecSta BOOL Send processing executing flag
J01_P2_TransErr BOOL Transmission error
J01_P2_TransErrSta BOOL Transmission error status J01_P2_NopRcvCompleteSta BOOL Receive completion
Additional Information
For details on the variables of the Serial Communications Unit, refer to 2-3 Device Variable for CJ-series Unit in the CJ-series Serial Communications Units Operation Manual for NJ-series CPU Unit (Cat.No. W494).
[System-defined variable]
Variable name Data type Description
_Port_isAvailable BOOL Communications Port Enabled Flag TRUE: Enabled, FALSE: Not enabled
Additional Information
For information on the system-defined variables, refer to Communications Instructions in Section 2 Instruction Descriptions of the NJ-series Instructions Reference Manual (Cat. No.
W502).
●Internal variables (Instance variables)
The following tables list the internal variables used to execute the function blocks in the program. An internal variable is called an “instance”. The name of the function block to use is specified as the data type of the variable.
[Instances of user-defined function blocks]
Variable name Data type Description
Serial_ParameterSet_i
nstance ParameterSet
No-protocol serial communications parameter setting function block
This variable sets the monitoring time of each processing from the send processing to receive processing.
Serial_SendMessageS
et_instance SendMessageSet
No-protocol serial communications send data setting function block
This variable sets the send/receive processing
required/not required setting and sets the send message.
Serial_ReceiveCheck_i
nstance ReceiveCheck
No-protocol serial communications receive processing function block
This variable stores the receive data and detects a normal end or an error end.
*For information on the user-defined function blocks, refer to 9.5.3 Detailed Description of Function Blocks.
[Instances of timers]
Variable name Data type Description
[Instances of communications instructions]
Variable name Data type Description
SerialSend_instance SerialSend SCU send serial (no-protocol send processing) function block
SerialRcv_instance SerialRcv SCU receive serial (no-protocol receive processing) function block
Additional Information
For information on the communications instructions, refer to Communications Instructions in Section 2 Instruction Descriptions of the NJ-series Instructions Reference Manual (Cat. No.
W502)
●Internal variables
Variable name Data type Description
Local_Status sStatus Communications processing status flags This variable is defined as sStatus structure.
Local_State DINT Processing number
Local_ErrCode uErrorFlgs An area in which an error code is edited.
This variable is defined as uErrorFlgs union.
Local_ExecFlgs sControl Communications instruction execution flags This variable is defined as sControl structure.
Local_SrcDataByte UINT Number of bytes to send Local_SrcData ARRAY[0..255]
OF BYTE
An area that stores the send data of the SerialSend instruction (256 bytes)
Local_RecvData ARRAY[0..2000]
OF BYTE
An area that stores the receive data of the SerialRcv instruction (2001 bytes)
Local_ReceiveMessage STRING[256] An area that stores the receive data after converted into a string. (256 characters)
Local_ReceiveSize UINT Size of receive data of SerialRcv instruction Local_RecvDataLength UINT Total byte length of receive data
Local_RecvCHNo UINT The element number in Local_RecvData that stores the receive data
Local_RecvCheckFlg BOOL
Destination device error detection instruction execution flag
TRUE: Executed / FALSE: Not executed Local_InitialSettingOK BOOL Initialization processing normal setting flag Local_TONFlgs sTimerControl Timer enable flags
This variable is defined as sTimerControl structure.
Local_ComType sComType
Send/Receive processing required/not required setting flags
This variable is defined as sComType structure.
Local_Port _sPORT Used port