• 沒有找到結果。

9. Program

9.5. ST Program

9.5.1. Functional Components of Program

This program is written in the ST language. The functional components are as follows:

Major classification Minor classification Description 1. Communications

processing

1.1. Starting the communications processing

1.2. Clearing the communications processing status flags 1.3. Communications processing in

progress status

The communications processing starts.

2. Initialization processing

2.1. Initializing the timers 2.2. Initializing the instructions

2.3. Initializing the instruction execution flags

2.4. Initializing the timer enable flags 2.5. Initializing the error code storage

areas

2.6. Setting each processing monitoring time and setting the communications parameters

2.7. Setting the send/receive processing required/not required setting and send data

2.8. Converting send data from a string to a BYTE array

2.9. Initializing the receive data storage areas

2.10. Initialization setting end processing

The parameters for serial

communications are set and the error code storage areas are initialized.

The send/receive required/not required setting is set, and the send data and receive data are set.

3. Send processing 3.1. Determining the send processing status and setting the execution flag 3.2 Enabling the send processing time

monitoring timer

3.3. Executing the send instruction

The processing starts when the send processing required/not required setting is set to Required and the initialization processing ends normally.

4. Receive processing

4.1. Determining the receive processing status and setting the execution flag 4.2. Enabling the receive waiting time

monitoring timer

4.3. Enabling the receive processing time monitoring timer

4.4. Executing the receive instruction 4.5. Executing the destination device error

detection instruction

The processing starts when the receive processing required/not required setting is set to Required and the send processing ends normally.

The receive processing is repeated when multiple receive data arrive. The receive data is stored and checked.

5. Processing number error process

5. Processing number error process The error processing is executed when a non-existent status processing number is detected.

9.5.2. Program List

The program is shown below.

The communications setting and send data (command data) setting, which need to be changed depending on the destination device, are set in the function blocks (ParameterSet, SendMessageSet, and ReceiveCheck). For information on how to change these values, refer to 9.5.3 Detailed Description of the Function Blocks.

●Program: Program0 (General-purpose serial communications connection check program) 1. Communications processing

2. Initialization processing

3. Send processing

4. Receive processing

5. Processing number error process

9.5.3. Detailed Description of the Function Blocks

The user-defined function blocks are shown below.

The code which you need to edit according to the destination device is indicated by the red frames on the function blocks below.

●ParameterSet function block

(General-purpose serial no-protocol communications parameter setting)

Instruction Name ST expression

ParameterSet

Variable name I/O Data type Description

Execute Input BOOL

Execution flag:

The function block is executed when this flag changes to TRUE and it is stopped when this flag changes to FALSE.

TfsTime Output UINT

Send processing monitoring time:

This variable sets the monitoring time of the send processing in increments of 10 ms.

TrTime Output UINT

Receive wait monitoring time:

This variable sets the waiting time for the receive data in increments of 100 ms.

TfrTime Output UINT

Receive processing monitoring time:

This variable sets the monitoring time of the receive processing in increments of 10 ms.

Busy Output BOOL Busy

Done Output BOOL Normal end

Error Output BOOL Error end

ErrorID Output WORD Error information ErrorIDEx Output DWORD Error information

Not used

(Not used in this program.)

[External variables]

None

[Program]

●SendMessageSet function block

(General-purpose serial no-protocol communications send data setting)

Instruction Meaning ST expression

SendMessageSet

General-purpose serial no-protocol communications send data setting

Serial_ParameterSet_instance(Execute, Send_Data, ComType);

[Internal variables]

Name Data type Description

Send_Header STRING[5] Send header: Header of send message

Send_Addr STRING[5] Destination device address: Address of destination device Send_Command STRING[256] Destination device command:

Command sent to destination device

Send_Check STRING[5] Send check code: Check code of send message Send_Terminate STRING[5] Send terminator: Terminator of send message

[Input/Output]

Name I/O Data type Description

Execute Input BOOL

Execute: The function block is executed when this flag changes to TRUE and it is stopped when this flag changes to FALSE.

Send_Data Output STRING[256] Send data: This variable sets a command that is sent to the destination device.

ComType Output BYTE

Send/receive type: This variable sets whether send/receive processing are required.

1:Send only, 2: Receive only, 3: Send and Receive

Busy Output BOOL Busy

Done Output BOOL Normal end

Error Output BOOL Error end

ErrorID Output WORD Error code

ErrorIDEx Output DWORD Expansion error code

Not used

(Not used in this project.)

[External variable]

None

[Program]

●RecieveCheck function block

(General-purpose serial no-protocol communications receive processing)

Instruction Meaning ST expression

ReceiveCheck

Name Data type Description

Receive_Check STRING[5] FCS receive value:

FCS receive result of receive data Calc_Check STRING[5] FCS calculation value:

FCS calculation result of receive data

[Input/Output]

Variable

name I/O Data type Description

Execute Input BOOL

Execution flag: The function block is executed when this flag changes to TRUE and it is stopped when this flag changes to FALSE.

tLength Input UINT Receive data length: Byte length of receive data Recv_Data In-out STRING[256] Receive data storage area:

An area that stores the receive data after detection

Recv_Buff In-out STRING[256] Receive buffer: An area that temporarily stores the receive data that is used for detection.

Done In-out BOOL Normal end: TRUE for a normal end Error In-out BOOL Error end: TRUE for an error end

ErrorID In-out WORD Error code: This variable stores 16#1000 for a destination device error and 16#2000 for an FCS error.

ErrorIDEx In-out DWORD

Expansion error code:

This variable stores the FCS determination result or the destination device error code.

Busy Output BOOL Busy Not used

(Not used in this program.)

Rcv_Size Output INT Storage receive data length: Data length of receive data

[External variable]

None

[Program]

相關文件