Hi there ,
i want to communicate plc to kr c2 controller ( krc5.6 ) , but i want communicate realtime in background and any program running at foreground
thanks
Hi there ,
i want to communicate plc to kr c2 controller ( krc5.6 ) , but i want communicate realtime in background and any program running at foreground
thanks
all right... go ahead.
all right... go ahead.
How?
the smart way... define the problem, break it down and solve it step by step.
you did not state
what is your idea of real time? could be message very 1ms, 100ms, 10s... "real" is relative...
how much data you need to exchange per second?
are you sure that RS232 can do what you want? have you done RS232 comms before (using any device)?
what is the format of data? this may require additional processing.
what kind of help you need exactly and with what? What did you do so far? post your code
did you consider using Ethernet? EthernetKRL aka EKI is more modern approach....
or using one of open source servers like KVP or C3Bridge. then you do not need anything on the robot side. you can read and write pretty much anything.
RS232 is legacy interface that is used less and less. it will not be completely gone any time soon but computers today normally do not even have such port. this was trend for many years...
but if you do want to use RS232, it is doable...you need to get relevant documentation and check examples. some are shared on this forum. i normally write and test my code as robot program module and once it is debugged, just call it from Submit.
the performance will likely not be great due to slow interpolation cycle (12ms). so even if messages are short and do not need much processing/parsing, theoretical throughput would be some 80messages per second. reality is going to be less than that. i have not tried it but i am estimating that maybe 10-20 per second and without issue is going to be quite a success.
Another issue would be the protocol.
What type of protocol do you want (or have) to use?
message every 100ms to 150ms .
my device limited to use rs232 for communication.
i want to use rs232 for some inputs and outputs in background.
have you done any RS232 comms before? do you know what type of cable and port settings you need?
yes.
yes i know but i didn't run in background.
that is ok... working on code that runs in Submit is pain. it is easier to make it work in robot interpreter. as long this is an expert module with no INI or motions etc. you can then link it with Submit.
It's been far too many years since I did anything with KRC2 RS232, but I recall the Ford version KRC1s used Submit RS232 to communicate with WTC weld timers. I'm not sure if that continued into KRC2s or not. I never worked on that code, but I did find an old copy that might provide some useful hints:
&ACCESS R
DEF WTC_COM (CMD :IN,WT_NO :IN )
; Wed Oct 21 09:31:23 1998 Rev. 1.0
;-----------------------------------------------------------
; Macro to call the Weltronic Controler via CREAD/CWRITE
;
; Lindemann KUKA R12-S4 10.03.98 Design
; 26.03.98 new bitmap from WTC
; 18.05.98 automatic reweld
; Roy Fri Oct 24 07:35:34 1998
; polled from sps.sub
; Wed Nov 04 18:05:47 1998
; last weld data
; add logic for clearing buffer if not == to zer0
; need to limit the buffer time (cycles)
;-----------------------------------------------------------
INT CMD,WT_NO
COMM_STATUS=0
SWITCH CMD
CASE 1 ; wtc communication
COMMUNICATE (WT_NO )
CASE 2 ; connection
CONNECTION (WT_NO )
CASE 3 ; data monitor
WELD_DATA (WT_NO )
DEFAULT ; wrong WTC-command
COMM_STATUS=1
ENDSWITCH
CONN_OK[WT_NO]= NOT (COMM_STATUS<>0)
; check for comm. fault? display loop message if needed
IF NOT CONN_OK[WT_NO] THEN
; clear all timer type fault message.
$LOOP_MSG[]=" "
SWITCH WT_NO
CASE 1 ; reset all wtc 1 inputs
RDATA_WORD=0
SDATA_WORD=0
R1COMMREQST1=FALSE
CASE 2 ; reset all wtc 2 inputs
ENDSWITCH
; SetLoopContMsg to display comm fault message
SETCOMMMSG (WT_NO,COMM_STATUS )
MEM_COMM_FAULT=TRUE
ELSE
; check for weld fault? display loop message if needed
SWITCH WT_NO
CASE 1
IF RD_WTCFAULT THEN
; check for a valid fault
IF (RD_FAULTCODE==0) OR ((RD_FAULTCODE==21) AND NOT EXT_ENBL_RLY) THEN
; clear all timer type fault message.
$LOOP_MSG[]=" "
ELSE
; SetLoopContMsg to display comm fault message
SETWELDMSG (1,RD_FAULTCODE )
MEM_RD_WTCFAULT=TRUE
ENDIF
ELSE
IF (MEM_RD_WTCFAULT OR MEM_COMM_FAULT) THEN
MEM_RD_WTCFAULT=FALSE
MEM_COMM_FAULT=FALSE
; clear all timer type fault message.
$LOOP_MSG[]=" "
ENDIF
ENDIF
CASE 2
ENDSWITCH
ENDIF
END ;(main )
;================
DEF CONNECTION (WT_NO :IN )
INT WT_NO
; reset all serial inputs and outputs
RDATA_WORD=0
SDATA_WORD=0
; set the current controller addresses
WTC_ADR=WT_NO+ADR_OFFSET
; open serial channel
COPEN(:SER_2,WTC_HANDLE)
; check for error opening serial channel 2
IF WTC_HANDLE==0 THEN
COMM_STATUS=2
ELSE
; used to clear the input buffer of any extra data
CLEAR_BUFFER ( )
MODUS=#SYNC
; send connection telegram
CWRITE(WTC_HANDLE,STATE,MODUS,"%1R%1R0202",ENQ,WTC_ADR)
; check connection return status
IF (STATE.RET1<>#CMD_OK) AND (STATE.RET1<>#DATA_OK) THEN
COMM_STATUS=6
ELSE
MODUS=#ABS
OFFSET=0
LOC_ADR=0
RET_WTC_ADR=0
; check response telegram
CREAD(WTC_HANDLE,STATE,MODUS,TIMEOUT,OFFSET,"%1R%4D",LOC_ADR,RET_WTC_ADR)
SWITCH STATE.RET1
CASE #CMD_TIMEOUT,#CMD_REJ,#CMD_ABORT,#DATA_BLK ; connection fault
COMM_STATUS=3
CASE #DATA_OK,#DATA_END ; connection ok
; wrong connection
IF (WTC_ADR<>LOC_ADR) THEN
COMM_STATUS=4
ENDIF
DEFAULT
; no response from channel
COMM_STATUS=7
ENDSWITCH
ENDIF
ENDIF
END ;CONNECTION
;================
DEF COMMUNICATE (WT_NO :IN )
INT WT_NO
INT ERRCNT
ERRCNT=5
; used to clear the input buffer of any extra data
CLEAR_BUFFER ( )
REPEAT
; sps running heart beat check
PULSE (SPS_RUNNING,TRUE,3.0 )
WTC_ADR=WT_NO+ADR_OFFSET
SWITCH WT_NO
CASE 1
WTC_SEND=SDATA_WORD ; set telegram
CASE 2
ENDSWITCH
OFFSET=0
MODUS=#SYNC
; send communication telegram
CWRITE(WTC_HANDLE,STATE,MODUS,"%1R%04X",WTC_ADR,WTC_SEND)
; check communication return status
IF (STATE.RET1<>#CMD_OK) AND (STATE.RET1<>#DATA_OK) THEN
COMM_STATUS=6
ERRCNT=0
ELSE
MODUS=#ABS
OFFSET=0
LOC_ADR=0
WTC_RECEIVE=0
; check respones telegram
CREAD(WTC_HANDLE,STATE,MODUS,TIMEOUT,OFFSET,"%1R%4X",LOC_ADR,WTC_RECEIVE)
SWITCH STATE.RET1
CASE #CMD_TIMEOUT,#CMD_REJ,#CMD_ABORT,#DATA_BLK ; communication fault
COMM_STATUS=5
ERRCNT=ERRCNT-1
CASE #DATA_OK,#DATA_END ; communication ok
; check for wrong connection
IF (WTC_ADR<>LOC_ADR) THEN
COMM_STATUS=4
ERRCNT=0
ELSE
SWITCH WT_NO
CASE 1
RDATA_WORD=WTC_RECEIVE
CASE 2
ENDSWITCH
ERRCNT=0
COMM_STATUS=0
ENDIF
CASE #DATA_OK,#DATA_BLK,#CMD_REJ ; buffer read error
; used to clear the input buffer of any extra data
CLEAR_BUFFER ( )
DEFAULT
COMM_STATUS=7
ERRCNT=0
ENDSWITCH
ENDIF
UNTIL (ERRCNT==0)
END ;COMMUNICATE
;================
DEF WELD_DATA (WT_NO :IN )
INT WT_NO
INT ERRCNT
WTC_ADR=WT_NO+ADR_OFFSET
ERRCNT=5
; used to clear the input buffer of any extra data
CLEAR_BUFFER ( )
REPEAT
; sps running heart beat check
PULSE (SPS_RUNNING,TRUE,3.0 )
OFFSET=0
MODUS=#SYNC
; send data telegram
CWRITE(WTC_HANDLE,STATE,MODUS,"%1R%C%X",WTC_ADR,"R",DATA_ADR)
; check data return status
IF (STATE.RET1<>#CMD_OK) AND (STATE.RET1<>#DATA_OK) THEN
COMM_STATUS=6
ERRCNT=0
ELSE
MODUS=#ABS
OFFSET=0
LOC_ADR=0
LST_DATA=0
; check response telegram
CREAD(WTC_HANDLE,STATE,MODUS,TIMEOUT,OFFSET,"%1R%C%X",LOC_ADR,WTC_ID[1],LST_DATA)
SWITCH STATE.RET1
CASE #CMD_TIMEOUT,#CMD_REJ,#CMD_ABORT,#DATA_BLK ; data fault
COMM_STATUS=5
ERRCNT=ERRCNT-1
CASE #DATA_OK,#DATA_END
; check for wrong connection
IF (WTC_ADR<>LOC_ADR) THEN
COMM_STATUS=4
ERRCNT=0
ELSE
SWITCH DATA_ADR
CASE 20
LST_WLD_CURR[WT_NO]=LST_DATA
ENDSWITCH
COMM_STATUS=0
ERRCNT=0
ENDIF
CASE #DATA_OK,#DATA_BLK,#CMD_REJ ; buffer read error
; used to clear the input buffer of any extra data
CLEAR_BUFFER ( )
DEFAULT
COMM_STATUS=7
ERRCNT=0
ENDSWITCH
ENDIF
UNTIL (ERRCNT==0)
END ;WELD_DATA
;================
DEF CLEAR_BUFFER ( )
INT BFRCNT
BFRCNT=0
WHILE ($DATA_SER2>0) AND (BFRCNT<=5)
; sps running heart beat check
PULSE (SPS_RUNNING,TRUE,3.0 )
MODUS=#SEQ
OFFSET=0
LOC_ADR=0
WTC_RECEIVE=0
CREAD(WTC_HANDLE,STATE,MODUS,TIMEOUT,OFFSET,"%R",CLEARBUFFER)
BFRCNT=BFRCNT+1
ENDWHILE
END
;================
DEF SETWELDMSG (WT_NO :IN,MSGNO :IN )
INT WT_NO,MSGNO
SWITCH WT_NO
CASE 1
SWITCH MSGNO
CASE 1
$LOOP_MSG[]="Timer1 E1: ControllerFailure. "
CASE 4
$LOOP_MSG[]="Timer1 E4: IllegalPowerFrequency. "
CASE 6
$LOOP_MSG[]="Timer1 E6: TimerBatteryAlarm. "
CASE 7
$LOOP_MSG[]="Timer1 E7: PowerFuseOpen. "
CASE 8
$LOOP_MSG[]="Timer1 E8: PrimaryCableGrounding. "
CASE 11
$LOOP_MSG[]="Timer1 E11: SCR/IGN-Shorted. "
CASE 12
$LOOP_MSG[]="Timer1 E12: TimerOverride. "
CASE 13
$LOOP_MSG[]="Timer1 E13: HighCurrent. "
CASE 14
$LOOP_MSG[]="Timer1 E14: SpuriousInterrupt. "
CASE 15
$LOOP_MSG[]="Timer1 E15: MC-Fault. "
CASE 21
$LOOP_MSG[]="Timer1 E21: TimerEmergencyStop. "
CASE 25
$LOOP_MSG[]="Timer1 E25: PilotInvalid. "
CASE 26
$LOOP_MSG[]="Timer1 E26: OutOfControlRange. "
CASE 27
$LOOP_MSG[]="Timer1 E27: NoStepperReset. "
CASE 28
$LOOP_MSG[]="Timer1 E28: StationWaterFlowFault. "
CASE 29
$LOOP_MSG[]="Timer1 E29: TipWaterFlowFault. "
CASE 31
$LOOP_MSG[]="Timer1 E31: HalfCycling. "
CASE 32
SWITCH WSGUN[S_ACT.PGNO1]
CASE #GUN1
$LOOP_MSG[]="Timer1[Gun1] E32: LowCurrent/MC-Fault "
CASE #GUN2
$LOOP_MSG[]="Timer1[Gun2] E32: LowCurrent/MC-Fault "
ENDSWITCH
CASE 33
$LOOP_MSG[]="Timer1 E33: RegulationOutOfRangeLow. "
CASE 34
$LOOP_MSG[]="Timer1 E34: RegulationOutOfRangeHigh. "
CASE 35
$LOOP_MSG[]="Timer1 E35: ExternalNoWeld. "
CASE 36
$LOOP_MSG[]="Timer1 E36: InternalNoWeld. "
CASE 37
$LOOP_MSG[]="Timer1 E37: SecondaryOutOfRangeLow. "
CASE 38
$LOOP_MSG[]="Timer1 E38: SecondaryOutOfRangeHigh. "
CASE 39
$LOOP_MSG[]="Timer1 E39: AutoStepperFault. "
CASE 40
$LOOP_MSG[]="Timer1 E40: AuxContactorFault. "
CASE 41
$LOOP_MSG[]="Timer1 E41: WaitingForRetract. "
CASE 42
$LOOP_MSG[]="Timer1 E42: WaitingForPressureSwitch. "
CASE 44
$LOOP_MSG[]="Timer1 E44: AVC-OutOfRange. "
CASE 46
$LOOP_MSG[]="Timer1 E46: EndOfStepper. "
CASE 47
$LOOP_MSG[]="Timer1 E47: ReWeldDone. "
CASE 49
$LOOP_MSG[]="Timer1 E49: PilotClosed. "
CASE 50
$LOOP_MSG[]="Timer1 E50: DEP-PowerFuseOpen. "
ENDSWITCH
CASE 2
ENDSWITCH
END ;SETMSG
;================
DEF SETCOMMMSG (WT_NO :IN,MSGNO :IN )
INT WT_NO,MSGNO
SWITCH WT_NO
CASE 1
SWITCH MSGNO
CASE 1
$LOOP_MSG[]="Timer1: WrongWeldCommand. "
CASE 2
$LOOP_MSG[]="Timer1: ErrorOpenSerialPort2. "
CASE 3
$LOOP_MSG[]="Timer1: NoConnection. "
CASE 4
$LOOP_MSG[]="Timer1: WrongConnection. "
CASE 5
$LOOP_MSG[]="Timer1: ConnectionLost. "
CASE 6
$LOOP_MSG[]="Timer1: ErrorWritingTo. "
CASE 7
$LOOP_MSG[]="Timer1: ErrorReadingFrom. "
ENDSWITCH
CASE 2
ENDSWITCH
END ;SETCOMMMSG
Display More
thanks panic mode & SkyeFire