AsciiRead (FB)

FUNCTION_BLOCK AsciiRead EXTENDS AC500_StateMachine.AbbLConC3

Function block to read incoming serial messages as ASCII code and validate them according to defined telegram ending parameter.

Once the corresponding message is received, the Ready output is set to TRUE for one cycle. The output Message will display the actual message without the ending and the output Length will give corresponding length without the ending. Per default the maximum size of Message is set to 255 characters. To read messages beyond 255 characters, the library parameter CharLength must be increased.

Hint

The max size of Message is 255 by default and can be increased with the CharLength parameter.

An internal buffer is used to store the read data. The buffer is set to 5000 caracters by default and can be modified according to the needs by changing the library parameter InternalBufferSize. If the buffer exceeds, because the ending telegram is never reached, the function block will return an error ERR_BUFFER_OVERFLOW.

Warning

The internal buffer of the function block is cleaned once Enable is set to FALSE.

Resetting the function block by setting Enable from TRUE -> FALSE will close the COM port if AsciiWrite is not in use. Elswise, if AsciiWrite is used in parallel, the COM port remains open to fulfill the write job and is then automatically closed by the AsciiWrite.

Closing the COM port and therefore resetting the AsciiRead requires more cycles to be performed reliable. Therefore, the outputs Busy and Error must be monitored to check whether resetting has been finished or not.

Hint

When the COM port is closed, the Linux buffer is cleaned up and already received information are lost.

Telegram ending

Telegram ending selection

Telegram ending size

Telegram ending value

Description

None

No telegram ending identifier selected. The character received since last call are provided. The maximum number of characters is limited to the parameter setting of the Ascii library and can be modified by changing the size for CharLength.

Character

Number of ending characters 1 or 2

Character values, e.g. 16#0D0A <CR><LF>

According to the set value, it is checked for 1 or 2 ending characters.

The ending character(s) is (are) not passed, i.e. they are not contained in the `Message`output

Telegram length

Number of characters > 0 and <= CharLength (Param List)

Telegram received is reported once the number of characters defined in “Value” is received.

Duration

Time in [ms]

Telegram received is reported once the time set for “Value” is elapsed. The time starts with the first FALSE -> TRUE at input Enable and will reset after successfull receive of the data.

Telegram timeout

Time in [ms]

Telegram received is reported once the pause between two telegrams is greater than the time set in “Value”. The time starts with the first received bytes and will restart every time new bytes are received. If the time exceeds, the message is returned.

InOut:

Scope

Name

Type

Initial

Comment

Inherited from

Input

Enable

BOOL

FALSE

A rising edge (Enable = TRUE) starts the operation, the output Busy goes to TRUE. All other inputs are read and considered continuously. Execution will continue forever until a falling edge (Enable = FALSE) aborts the operation. During Aborting the Busy is still TRUE. Afterward all outputs are reset.

AbbLConC3

Output

Busy

BOOL

FALSE

Operation is running (while output Error is FALSE)

AbbLConC3

Error

BOOL

FALSE

Operation is stopped with error (while output Busy is FALSE). This output is TRUE for at least one cycle or until Enable is set to FALSE. The output ErrorID gives more details about the error.

AbbLConC3

Input

Com

STRING

‘COM_1’

Node name of the serial interface

TelegramEnding

TELEGRAM_ENDING

Telegram ending parameter

Output

ErrorId

ERROR_ID

ERROR_ID.NO_ERROR

ErrorId <> NO_ERROR if output Error = TRUE

AddErrNo

DWORD

Additional error number to indicates errors coming from underlying libraries. Please check AC500_Com.COM.ERROR enumeration for references

Ready

BOOL

Rising flag that indicates a new message is present at Message output. Ready will be TRUE for only one cycle

Message

STRING(Param.CharLength)

Received message according to definition of telegram ending

Length

UDINT

Length of the actual message