Description

The following program is a short demo application which allows to easily switch between the four main functions of the XMIT block:

  • ASCII Message Out (0)

  • Simple ASCII In (1)

  • Terminated ASCII In (2)

  • Modbus Master (3)

To select the function enter the appropriate number into the ModeSelection variable. A rising signal on X_Trigger activates the XMIT block by setting the Start variable 1. Start remains 1 until the function has been performed or an error occured

IEC Section

Selection of configuration data

XMIT function block

Keeps Start "on" until command finished or an error occurs

Variable Declarations

The following tables show the variables used in this example

Variable table

Variable Name

Data Type

Address

Description

Start

BOOL

Must remain ON until the XMIT has been finished

Abort

BOOL

Aborts XMIT operation

opActive

BOOL

Indicates XMIT Status

opError

BOOL

Indicates XMIT Status

opDone

BOOL

Indicates XMIT Status

Port

BYTE

Select port 1 or 2

DirectMessageOut

WordArr256

400257

Actual configuration data or data to be transmitted

DirectXmitSet

XMIT_SET

400513

Actual configuration data

DirectMessageIn

WordArr256

400001

Data received by ASCII In functions

DirectXmitConfig

XMIT_CFG

400523

Actual configuration data

X_Trigger

BOOL

Triggers the XMIT function

ModeSelection

UINT

Select the requested function 0..3

Message AsciiOut

WordArr256

Message to be transmitted by ASCII Out

MessageSimpleAsciiIn

WordArr256

(no content needed)

MessageTermAsciiIn

WordArr256

Configuration data for Terminated ASCII In

MessageModbus

WordArr256

Configuration data for Modbus

XmitSetForAsciiOut

XMIT_SET

Configuration data for ASCII Out

XmitSetForSimpleAsciiIn

XMIT_SET

Configuration data for Simple ASCII In

XmitSetForTermAsciiIn

XMIT_SET

Configuration data for Terminated ASCII In

XmitSetForModbus

XMIT_SET

Configuration data for Modbus

Īnitial Values

The following tables show the initial values for the different arrays used:

Content of XmitSetForAaciiOut Data Structure

Element Name

Data Type

Address

Comment

BaudRate

WORD

9600

DataBits

BYTE

8

Parity

BYTE

2

StopBits

BYTE

1

CommandWord

WORD

512

Bit 7 set

MessageLen

WORD

16

Transmits the first 16 Characters from MessageAsciiOut array

RespTimeOut

WORD

100

RetryLimit

WORD

100

XmStartDelay

WORD

100

XmEndDelay

WORD

100

Content of XmitSetForSimpleAsciiIn Data Structure

Element Name

Data Type

Address

Comment

BaudRate

WORD

9600

DataBits

BYTE

8

Parity

BYTE

2

StopBits

BYTE

1

CommandWord

WORD

1152

Bits 6 and 9 set

MessageLen

WORD

16

opDone is set to 1 after receiving 16 characters

RespTimeOut

WORD

100

RetryLimit

WORD

100

XmStartDelay

WORD

100

XmEndDelay

WORD

100

Content of XmitSetForTermAsciiIn Data Structure

Element Name

Data Type

Address

Comment

BaudRate

WORD

9600

DataBits

BYTE

8

Parity

BYTE

2

StopBits

BYTE

1

CommandWord

WORD

2176

Bits 5 and 9 set

MessageLen

WORD

5

The DirectXmitSet.MessageLen element will be automatically set to 5 independent of this entry

RespTimeOut

WORD

100

RetryLimit

WORD

100

XmStartDelay

WORD

100

XmEndDelay

WORD

100

Content of XmitSetForModbus Data Structure

Element Name

Data Type

Address

Comment

BaudRate

WORD

9600

DataBits

BYTE

8

RTU Mode

Parity

BYTE

2

StopBits

BYTE

1

CommandWord

WORD

256

Bit 8 set

MessageLen

WORD

5

For Function Codes 01...06, 15 and 16

RespTimeOut

WORD

1000

RetryLimit

WORD

10

XmStartDelay

WORD

100

XmEndDelay

WORD

100

Content of MessageAsciiOut Data Structure

Element Name

Data Type

Address

Comment

MessageAsciiOut[2]

WORD

17220

'CD' to be transmitted

MessageAsciiOut[3]

WORD

17734

'EF'

MessageAsciiOut[4]

WORD

18248

'GH'

MessageAsciiOut[5]

WORD

18762

'IJ'

MessageAsciiOut[6]

WORD

19276

'KL'

MessageAsciiOut[7]

WORD

19790

'MN'

MessageAsciiOut[8]

WORD

20304

'OP'

MessageAsciiOut[...]

WORD

...

Content of MessageTermAsciiIn Data Structure

Element Name

Data Type

Address

Comment

MessageAsciiOut[1]

WORD

258

0x0102 1 starting and 2 termination characters

MessageAsciiOut[2]

WORD

9216

0x2400 First starting character '$'

MessageAsciiOut[3]

WORD

3338

0x0D0A Termination characters [CR][LF]

Content of MessageModbus Data Structure

Element Name

Data Type

Address

Comment

MessageAsciiOut[1]

WORD

3

Read multiple holding registers (4x)

MessageAsciiOut[2]

WORD

32

Read 32 registers

MessageAsciiOut[3]

WORD

10

Slave PLC modbus address

MessageAsciiOut[4]

WORD

101

Start with register 40101

MessageAsciiOut[5]

WORD

701

Data destination is register 40701