Hallo zusammen,
ich habe ein merkwürdiges Problem bei der Kommunikation zwischen einer IRC5 und einem Keyence-Kamerasystem bzgl. der Zeichenketten.
Im Prinzip:
-sende ich einen Befehl "MW,#Step,21" (ändert eine Variable)
-Kamera sendet die Antwort "MW" dazu (laut Schnittstellenüberwachung in Kamera)
-ich schliesse den Port, Öffne den Port, lösche den IOBuffer
-sende einen Befehl "MR,#Step" (liest die Variable aus)
-Kamera sendet die Anwort "MR,+00021"
-jetzt lese ich die Zeichenkette und erwarte "MR,+00021", bekomme aber "MWMR,+00021" und verstehe nicht warum
Dieser Fehler passiert nur im Automatik-Modus, wenn ich langsam schrittweise durchgehe, funktioniert es. Also ein Timing-Problem, aber ich stehe auf dem Schlauch.
Ich sende danach auch noch den Trigger "T1" und erhalte wie gewünscht "T1,...." als Antwort.
Hier der Code meines Testprograms:
PROC Test_Keyence_XG_Comm()
!=============================================
! Dient zum Test der Kommunikation XG - Roboter
!=============================================
TPWrite "Schreibe Step-Variable 21";
Change_Step 21;
Command:="MR,#Step";
Send_Command;
TPWrite "Lese Antwort";
RecResult Answer, 14;
Send_T1;
TPWrite "Lese Antwort";
RecResult Answer, 33;
!==========================================
DecodeInspections 5;
Pick_A_X := 0.0;
Pick_A_Y := 0.0;
Pick_A_R := 0.0;
Pick_B_X := 0.0;
Pick_B_Y := 0.0;
Pick_B_R := 0.0;
ConvOk:=StrToVal(StrPart(Answer,8,8),Pick_A_X);
IF ConvOk THEN
ConvOk:=StrToVal(StrPart(Answer,17,8),Pick_A_Y);
IF ConvOk THEN
ConvOk:=StrToVal(StrPart(Answer,26,8),Pick_A_R);
IF ConvOk = FALSE THEN
ErrWrite "COMM VISION XG","Communication Error: "\RL2:="Picking Angle";
ENDIF
ELSE
ErrWrite "COMM VISION XG","Communication Error: "\RL2:="Y direction offset";
ENDIF
ELSE
ErrWrite "COMM VISION XG","Communication Error: "\RL2:="X direction offset";
ENDIF
TPWrite "+++++++++++++++++++++++++";
TPWrite "X Position:"\Num:=Pick_A_X;
TPWrite "Y Position:"\Num:=Pick_A_Y;
TPWrite "R Position:"\Num:=Pick_A_R;
TPWrite "+++++++++++++++++++++++++";
ENDPROC
PROC RecResult(string stCommand,num nExpChar)
VAR string stLocalString;
!*************************************
!receive inspection result from keyence
!*************************************
!Open "COM1:", SerialPort\Read\Bin;
Answer:="xx";
WaitDI CI_18_CameraBusy, 0;
ReadRawBytes SerialPort, rawbytes1\Time:=2;
UnpackRawBytes rawbytes1, 1, Answer\ASCII:=nExpChar;
Close SerialPort;
TPWrite "Received String: " + Answer;
!Stop;
ERROR
STOP;
TRYNEXT;
ENDPROC
!----------------------------------------------------------
!---------------- ------------------------------------------
PROC SendCommand()
!*************************************
!send command string to keyence
!*************************************
Close SerialPort;
Command:=Command+cr;
Open "COM1:", SerialPort\Bin;
ClearIOBuff SerialPort;
WaitDI CI_18_CameraBusy, 0;
WriteStrBin SerialPort, Command;
!Close SerialPort;
ENDPROC
!----------------------------------------------------------
!----------------------------------------------------------
PROC Send_T1()
!*************************************
!send T1, trigger request to Keyence
!*************************************
Command:="T1";
SendCommand;
!Receive(35);
ENDPROC
!----------------------------------------------------------
!----------------------------------------------------------
PROC Change_Step(num nStep)
!*************************************
!write program step variable to Keyence
!*************************************
VAR string strStep;
Command:="MW,#";
strStep:=ValToStr(nStep);
IF StrLen(strStep) = 1 THEN
strStep:= "00"+strStep;
ENDIF
Command:=Command+strStep;
SendCommand;
ENDPROC
!----------------------------------------------------------
!----------------------------------------------------------
PROC DecodeInspections(num nType)
!=================================
! Decode both Inspection Results
!=================================
OkInspection1 := 99;
ConvOk:=StrToVal(StrPart(Answer,4,1),OkInspection1);
IF ConvOk THEN
IF OkInspection1 > 0 THEN
boolInspectionResult1:=FALSE;
ELSE
boolInspectionResult1:=TRUE;
ENDIF
ELSE
ErrWrite\I, "VISION XG", "Camera Inspection Fault"\RL2:="DecodeInspection";
ENDIF
IF boolInspectionResult1 = FALSE THEN
TEST nType
CASE 1:
!PulseDO\PLength:=1.0, CO_23_Part_PrimingError;
ErrWrite\I, "VISION XG", "AddOn_PrimingError";
CASE 2:
!PulseDO\PLength:=1.0, CO_33_GlueingNotOK;
ErrWrite\I, "VISION XG", "AddOn_PUDeposalError";
CASE 3:
!PulseDO \Plength:=1.0, CO_33_GlueingNotOK;
ErrWrite\I, "VISION XG", "AddOn_PickingError";
CASE 4:
!PulseDO\PLength:=1.0, CO_34_WrongPrimingOnGlass;
ErrWrite\I, "VISION XG", "Enamel_PrimingError";
CASE 5:
PulseDO\PLength:=1.0, CO_37_ApplicationPositionFault;
ErrWrite "VISION XG", "AddsONPositioningError";
ENDTEST
ENDIF
OkInspection2 := 99;
ConvOk:=StrToVal(StrPart(Answer,6,1),OkInspection2);
IF ConvOk THEN
IF OkInspection2 > 0 THEN
boolInspectionResult2:=FALSE;
ELSE
boolInspectionResult2:=TRUE;
ENDIF
ELSE
ErrWrite\I, "VISION XG", "Camera Inspection Fault"\RL2:="DecodeInspection";
ENDIF
IF boolInspectionResult2 = FALSE THEN
TEST nType
CASE 1:
!PulseDO\PLength:=1.0, CO_23_Part_PrimingError;
ErrWrite\I, "VISION XG", "AddOn_PrimingError";
CASE 2:
!PulseDO\PLength:=1.0, CO_33_GlueingNotOK;
ErrWrite\I, "VISION XG", "AddOn_PUDeposalError";
CASE 3:
!PulseDO \Plength:=1.0, CO_33_GlueingNotOK;
ErrWrite\I, "VISION XG", "AddOn_PickingError";
CASE 4:
!PulseDO\PLength:=1.0, CO_34_WrongPrimingOnGlass;
ErrWrite\I, "VISION XG", "Enamel_PrimingError";
CASE 5:
PulseDO\PLength:=1.0, CO_37_ApplicationPositionFault;
ErrWrite "VISION XG", "AddsONPositioningError";
ENDTEST
ENDIF
ENDPROC
Alles anzeigen