I attached my RAPID code here: What I’m trying to do is to send a message from c# program to the controller. And the controller will move as the message says. For example, I send “left”, then the controller will move to the left by a distance. This will work the first couple of time and then the error appears. Is there anything wrong in my code?
Thanks a lot!
MODULE COM_L
VAR bool flag := FALSE;
VAR bool clearFlag := FALSE;
VAR string command;
VAR intnum endnum;
VAR intnum connectnum;
CONST robtarget p11 := [ [600, -100, 800], [1, 0, 0, 0], [0, 0, 0,0], [ 9E9, 9E9, 9E9, 9E9, 9E9, 9E9] ];
PROC main()
RMQEmptyQueue;
CONNECT endnum WITH endCommTrap;
CONNECT connectnum WITH RABMsgs;
IRMQMessage flag, connectnum;
IRMQMessage command, endnum;
WHILE flag = FALSE DO
!do something, eg. normal processing…
IF clearFlag = TRUE THEN
RMQEmptyQueue;
clearFlag := FALSE;
ENDIF
WaitTime 3;
ENDWHILE
!PC SDK message received - do something…
TPWrite “Message from PC SDK, will now…”;
IDelete connectnum;
IDelete endnum;
EXIT;
ENDPROC
TRAP endCommTrap
VAR rmqmessage msg;
VAR rmqheader header;
VAR rmqslot rabclient;
VAR num userdef;
VAR string ack := “get command”;
VAR robtarget p1;
VAR robtarget pl;
VAR robtarget pr;
VAR robtarget pu;
VAR robtarget pd;
VAR string in_com;
RMQGetMessage msg;
RMQGetMsgHeader msg \Header:=
header\SenderId:=rabclient\UserDef:=userdef;
!check data type and assign value to flag variable
IF header.datatype = “string” THEN
RMQGetMsgData msg, in_com;
!return receipt to sender
! RMQSendMessage rabclient, ack;
ELSE
TPWrite “Unknown data received in RABMsgs…”;
ENDIF
StopMove;
StorePath;
p1 := CRobT();
IF in_com = “endCom” THEN
flag := TRUE;
ELSEIF in_com = “left” THEN
p1 := CRobT();
pl := p1;
pl.trans.x := p1.trans.x + 50;
MoveL pl, v1000, fine, tool0;
ELSEIF in_com = “right” THEN
p1 := CRobT();
pr := p1;
pr.trans.x := p1.trans.x - 50;
MoveL pr, v1000, fine, tool0;
ELSEIF in_com = “up123” THEN
p1 := CRobT();
pu := p1;
pu.trans.z := p1.trans.z + 50;
MoveL pu, v1000, fine, tool0;
ELSEIF in_com = “down” THEN
p1 := CRobT();
pd := p1;
pd.trans.x := p1.trans.x - 50;
MoveL pd, v1000, fine, tool0;
ENDIF
RestoPath;
StartMove;
clearFlag := TRUE;
ENDTRAP
ENDMODULE