下面講下如何將一些數(shù)據(jù)log下來,可以基于機(jī)器人本身的CWRITE指令來實(shí)現(xiàn)此功能:
(1).Log文件自動以時(shí)間命名;
(2).每隔10秒log一次;
(3).每條信息獨(dú)立一行;
具體實(shí)現(xiàn)過程如下:
1.在SmartPad上創(chuàng)建一個(gè)xxx.src,如下:
DEF Write_File( )
DECL INT handle
DECL STATE_T STAT
DECL MODUS_T MODE
DECL CHAR AxisPos[256]
DECL CHAR ProState[256]
DECL CHAR ErrorID[256]
DECL CHAR FILENAME[256]
DECL INT Offset
DECL BOOL bok
DECL char LF
MODE = #SYNC
HANDLE = 0
OFFSET=0
bOK=STRCLEAR(AXISPos[])
BOK=STRCLEAR(Prostate[])
BOK=STRCLEAR(ERRORID[])
LF = 10
SWRITE(AxisPos[],STAT,Offset,"%S:%F|%F|%F|%F|%F|%F","Current Axis Position",$AXIS_ACT.A1,$AXIS_ACT.A2,$AXIS_ACT.A3,$AXIS_ACT.A4,$AXIS_ACT.A5,$AXIS_ACT.A6)
Offset=0
SWITCH $PRO_STATE1
CASE #P_ACTIVE
ProState[]="Program State: RobotProgram is selected and running!"
CASE #P_FREE
ProState[]="Program State: RobotProgram is deselected!"
CASE #P_END
ProState[]="Program State: RobotProgram is selected and the end of program has been reached!"
CASE #P_RESET
ProState[]="Program State: RobotProgram is selected and has been stopped and reset!"
CASE #P_STOP
ProState[]="Program State: RobotProgram is selected and has been stopped!"
ENDSWITCH
SWRITE(ERRORID[],STAT,offset,"ErrorINFO: ERRORID-%D|LINENR-%D|PROG-%S|SUB-%S",$ERR.NUMBER,$ERR.LINE_NR,$ERR.MODULE[],$ERR.UP_NAME[])
offset=0
IF STRCLEAR(FILENAME[])THEN
SWRITE(FILENAME[],STAT,offset,"%D%D%D-%Dh%Dm%Ds.txt",($DATE.year),($DATE.MONTH),($DATE.DAY),($DATE.HOUR),($DATE.MIN),($DATE.SEC))
ENDIF
WAIT FOR TIMER_LIMIT(10)
CWRITE($FCT_CALL,STAT,MODE, "krl_fopen",FILENAME[], "w", HANDLE)
CWRITE($FCT_CALL, STAT, MODE, "krl_fputs", HANDLE, AxisPos[])
CWRITE($FCT_CALL, STAT, MODE, "krl_fputc", HANDLE, LF)
CWRITE($FCT_CALL, STAT, MODE, "krl_fputs", HANDLE, PROSTATE[])
CWRITE($FCT_CALL, STAT, MODE, "krl_fputc", HANDLE, LF)
CWRITE($FCT_CALL, STAT, MODE, "krl_fputs", HANDLE, ErrorID[])
CWRITE($FCT_CALL, STAT, MODE, "krl_fclose", HANDLE)
END
2.在SPS里調(diào)用該程序:
3.確保SPS運(yùn)行:
4.在機(jī)器人控制器路徑下C:\KRC\Roboter\Userfiles看生成的log文件:
5.查看具體log文件: