Programming Example for Acyclic Data ExchangeΒΆ

In the program example it is assumed that a maximum of 100 bytes is exchanged between CPU and Communication Module. The CM574-RS Communication Module is plugged into slot 1 (SLOT=1).

In principle, the program is the same in the AC500 CPU and the CM574-RS. The respective block names are to be used in the variable declaration for the CPU and the CM574.

In the example, the transmit and receive data are simply assigned to global byte ARRAYs:

VAR_GLOBAL
  abyRecDataCM574_1_1 : ARRAY[0..cdwMaxRec] OF BYTE; (* Data from DPRAM  *)
  abySendDataCM574_1_1 : ARRAY[0..cdwMaxSend] OF BYTE; (* Data to DPRAM *)
END_VAR
VAR_GLOBAL CONSTANT
  cdwMaxRec : DWORD := 99; (* +1 byte receive *)
  cdwMaxSend : DWORD := 99; (* +1 byte send *)
END_VAR

The program for receiving and transmitting the data looks as follows:

PROGRAM proComm_CPU_CM574
VAR
  bNewRecData : BOOL; (* new data received *)
  fbRecCM574_1 : DPRAM_CM5XX_REC; (* CPU: receive data from first CM574 *)
    : DPRAM_PM5XX_REC; (* CM574: receive data from CPU *)
  bRecErr : BOOL; (* receive error *)
  wRecErno : WORD; (* receive error number *)
  bNewSend : BOOL; (* new data from program *)
  bNewSendData : BOOL; (* new data available to send *)
  bSendDone : BOOL; (* data successfully sent *)
  fbSendCM574_1 : DPRAM_CM5XX_SEND; (* CPU: send data to first CM574 *)
    : DPRAM_PM5XX_SEND; (* CM574: send data to CPU *)
  bSendErr : BOOL; (* send error *)
  wSendErno : WORD; (* send error number *)
END_VAR
VAR CONSTANT
  cbySlotCM574_1 : BYTE := 1; (* SLOT number of first CM574 *)
  cbyChannelCM574_1_1 : BYTE := 1; (* Channel 1 of first CM574 *)
  cbyChannelCM574_1_2 : BYTE := 2; (* Channel 2 of first CM574 *)
END_VAR