PLC程序的例子

本节显示了一个示例程序的Beckhoff TwinCAT PLC与RoboDK OPC通信的代理服务器。

项目主要

VAR

bConnected: BOOL;

StationPointer:力;

iStep: INT;

bStart: BOOL;;

我:INT;

吨:吨;

bReset: BOOL;

bWrite: BOOL;

TON2:吨;

bShow: BOOL: = TRUE;

英属维尔京群岛:BOOL: = True;

END_VAR

VAR

Robot_name: STRING (80): =“ABB_RB1”;

Item_ID: ULINT;

arrJoints: ARRAY [0 . .LREAL 11);

strJoints:字符串(80):= ";

arrJointsFromStr: ARRAY [1 . .LREAL 11);

sSeparator: STRING (1): = " ";

arrJointsCommand: ARRAY [1 . .LREAL 11);

strJointsCommand:字符串(80);

END_VAR

VAR常数

cStepWaitCmd: INT: = 0;

cStepInit: INT: = 5;

cStepGetItem: INT: = 10;

cStepGetItemReset: INT: = 20;

cStepGetItemError: INT: = 990;

cStepGetJoints: INT: = 30;

cStepGetJointsReset: INT: = 40;

cStepGetJointsError: INT: = 991;

cStepGetJointsStr: INT: = 50;

cStepGetJointsStrReset: INT: = 60;

cStepGetJointsStrError: INT: = 992;

cStepSetJointStrDelay: INT: = 69;

cStepSetJointsStr: INT: = 70;

cStepSetJointsStrReset: INT: = 80;

cStepSetJointsStrError: INT: = 993;

cStepEnd: INT: = 300;

cStepWaitReset: INT: = 999;

END_VAR

VAR

aSplit: ARRAY [1 . .11)的字符串(80);

bResultSplit: BOOL;

调试:BOOL;

URL:字符串:= ' http://192.168.3.42:8091 ';

END_VAR

bConnected: = OPCUA_VirtualClient_RoboDK_Station.bConnected;

案例iStep

cStepWaitCmd:

如果bStart那么

iStep: = cStepInit;

bStart: = FALSE;

END_IF

cStepInit:

StationPointer: = 0;

我:= 1到11

arrJoints[我]:= 0.0;

arrJointsFromStr[我]:= 0.0;

aSplit[我]:= ";

END_FOR

如果不是OPCUA_VirtualClient_RoboDK_Station.getItem.bBusy

而不是OPCUA_VirtualClient_RoboDK_Station.getItem.bError

而不是OPCUA_VirtualClient_RoboDK_Station.getJoints.bBusy

而不是OPCUA_VirtualClient_RoboDK_Station.getJoints.bError

而不是OPCUA_VirtualClient_RoboDK_Station.getJointsStr.bBusy

而不是OPCUA_VirtualClient_RoboDK_Station.getJointsStr.bError

而不是OPCUA_VirtualClient_RoboDK_Station.setJoints.bBusy

而不是OPCUA_VirtualClient_RoboDK_Station.setJoints.bError

而不是OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bBusy

而不是OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bError

然后

iStep: = cStepGetItem;

END_IF

iStep: = cStepGetItem;

cStepGetItem:

如果OPCUA_VirtualClient_RoboDK_Station.getItem。bDone然后

iStep: = cStepGetItemReset;

Item_ID: = OPCUA_VirtualClient_RoboDK_Station.getItem.Item_ID;

ELSIF OPCUA_VirtualClient_RoboDK_Station.getItem。bError然后

iStep: = cStepGetItemError;

END_IF

cStepGetItemReset:

如果不是OPCUA_VirtualClient_RoboDK_Station.getItem.bError

而不是OPCUA_VirtualClient_RoboDK_Station.getItem.bBusy

然后

iStep: = cStepGetJoints;

END_IF

cStepGetJoints:

如果OPCUA_VirtualClient_RoboDK_Station.getJoints.bDone

而不是OPCUA_VirtualClient_RoboDK_Station.getJoints.bBusy

然后

iStep: = cStepGetJointsReset;

ELSIF OPCUA_VirtualClient_RoboDK_Station.getJoints。bError然后

iStep: = 991;

END_IF

cStepGetJointsReset:

如果不是OPCUA_VirtualClient_RoboDK_Station.getItem.bError

而不是OPCUA_VirtualClient_RoboDK_Station.getItem.bBusy

然后

iStep: = cStepGetJointsStr;

END_IF;

cStepGetJointsStr:

如果OPCUA_VirtualClient_RoboDK_Station.getJointsStr.bDone

而不是OPCUA_VirtualClient_RoboDK_Station.getJointsStr.bBusy

然后

iStep: = cStepGetJointsStrReset;

ELSIF OPCUA_VirtualClient_RoboDK_Station.getJointsStr。bError然后

iStep: = cStepGetJointsStrError;

END_IF

cStepGetJointsStrReset:

如果不是OPCUA_VirtualClient_RoboDK_Station.getJointsStr.bError

而不是OPCUA_VirtualClient_RoboDK_Station.getJointsStr.bBusy

然后

iStep: = cStepSetJointStrDelay;

END_IF;

cStepSetJointStrDelay:

strJointsCommand: = ";strJointsCommand: = CONCAT (LREAL_TO_STRING (arrJointsCommand [1]), strJointsCommand);

strJointsCommand: = CONCAT (strJointsCommand ', ');

strJointsCommand: = CONCAT (strJointsCommand LREAL_TO_STRING (arrJointsCommand [2]));

strJointsCommand: = CONCAT (strJointsCommand ', ');

strJointsCommand: = CONCAT (strJointsCommand LREAL_TO_STRING (arrJointsCommand [3]));

strJointsCommand: = CONCAT (strJointsCommand ', ');

strJointsCommand: = CONCAT (strJointsCommand LREAL_TO_STRING (arrJointsCommand [4]));

strJointsCommand: = CONCAT (strJointsCommand ', ');

strJointsCommand: = CONCAT (strJointsCommand LREAL_TO_STRING (arrJointsCommand [5]));

strJointsCommand: = CONCAT (strJointsCommand ', ');

strJointsCommand: = CONCAT (strJointsCommand LREAL_TO_STRING (arrJointsCommand [6]));

TON2 (: = TRUE, PT: = T # 0.2秒);

如果TON2。问那么

TON2 (: = FALSE);

iStep: = cStepSetJointsStr;

END_IF

cStepSetJointsStr:

如果(

OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bDone

而不是

OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bBusy

)

不信bWrite

然后

iStep: = cStepSetJointsStrReset;

ELSIF OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bError

然后

iStep: = cStepSetJointsStrError;

END_IF

cStepSetJointsStrReset:

bWrite: = FALSE;

OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bExecute: = FALSE;

如果不是OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bError

而不是OPCUA_VirtualClient_RoboDK_Station.setJointsStr.bBusy

然后

iStep: = cStepEnd;

END_IF;

cStepEnd:

吨(:= TRUE, PT: = T # 0.1秒);

如果吨。问那么

吨(:= FALSE);

如果没有调试

iStep: = 10;

其他的

iStep: = cStepSetJointStrDelay;

END_IF;

END_IF

cStepGetItemError:

Item_ID: = 0;

iStep: = cStepWaitReset;

cStepGetJointsError:

我:= 0到11

arrJoints[我]:= -99999.99;

END_FOR

iStep: = cStepWaitReset;

cStepGetJointsStrError:

strJoints: = ";

iStep: = cStepWaitReset;

cStepWaitReset:

如果bReset那么

iStep: = cStepInit;

bReset: = FALSE;

END_IF;

END_CASE

aSplit [1]: = strJoints;

我:= 1到7

bResultSplit: = FindAndSplit (

pSeparator: = ADR (sSeparator)

pSrcString: = ADR (aSplit[我])

pLeftString: = ADR (aSplit[我])

nLeftSize: = SIZEOF (aSplit[我])

pRightString: = ADR (aSplit (i + 1))

nRightSize: = SIZEOF (aSplit (i + 1))

bSearchFromRight: = FALSE);

如果不是bResultSplit那么

退出;

END_IF

END_FOR

我:= 1到6

arrJointsFromStr[我]:= STRING_TO_LREAL (aSplit[我]);

END_FOR;

/ /

OPCUA_VirtualClient_RoboDK_Station.getItem (

bExecute: = iStep = cStepGetItem

Item_Name: = Robot_name

);

OPCUA_VirtualClient_RoboDK_Station.getJoints (

bExecute: = iStep = cStepGetJoints

Item_ID: = Item_ID关节= > arrJoints

);

OPCUA_VirtualClient_RoboDK_Station.getJointsStr (

bExecute: = iStep = cStepGetJointsStr

Robot_name: = Robot_name关节= > strJoints

);

如果bWrite那么

OPCUA_VirtualClient_RoboDK_Station.setJointsStr (

bExecute: = TRUE

Robot_name: = Robot_name关节:= strJointsCommand);

END_IF;

Baidu
map