Example: sdo write via ads – BECKHOFF FC5101 User Manual

Page 58

Advertising
background image

Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149

58

1:
ADSRead(READ:= FALSE);
IF ADSRead.err THEN
state := 2;
ReadDataAvailable := TRUE;
Error := ADSRead.ErrId;
ELSE
IF NOT ADSRead.busy THEN
state := 2;
ReadDataAvailable := TRUE;
END_IF
END_IF
2:
ADSRead(READ:= FALSE);
state := 0;
END_CASE

Example: SDO Write via ADS

In the following example program (structured text) for the use of ADS services for SDO communication, object
0x6200, sub-index 3, from the node with port number 0x1001 is written. It concerns digital outputs to an I/O
node.

(* Data to be written *)
WriteData[0] := 16#55;

(* write Object *)
SDO_WRITE(
StartWriting := WriteStart,
CO_Index := 16#6200,
CO_SubIndex := 3,
DataLength := 1,
PortNr := 16#1001,
WriteData := WriteData,
ADSNetID:='192.168.10.11.2.1'
);
IF SDO_WRITE.WriteDataFinished THEN
WriteStart := FALSE;
WriteError := SDO_WRITE.Error;
END_IF

The SDO_WRITE function block that has been called in turn calls the ADSWRITE function a number of times. It
looks like this (starting with the variable declaration):

FUNCTION_BLOCK SDO_WRITE
VAR_INPUT
ADSNetID:STRING(23); (* The AMSNetID addresses the FC5101 card. Can be empty
if only one local single channel card is present*)
PortNr:WORD; (* The Port No. addresses the CANopen Node (see System
Manager) *)
CO_Index:DWORD; (* This is the Index of the CANopen Object Dictionary
Entry*)
CO_SubIndex:DWORD; (* This is the Sub-Index of the CANopen Object Dictionary
Entry*)
DataLength:DWORD; (* This is the Length of the CANopen Object Dictionary
Entry*)
StartWriting:BOOL; (* only reset to FALSE after WriteDataFinished=TRUE*)
WriteData:ARRAY[0..255] OF BYTE; (*This array contains the data to be written to
the CANopen Object Dictionary*)
END_VAR
VAR_OUTPUT
WriteDataFinished:BOOL;
Error:DWORD;
END_VAR
VAR
state:BYTE := 0;
ADSWRITE:ADSWRITE;
END_VAR

Advertising
This manual is related to the following products: