Hello everyone,
Currently, I have established a connection between robot and pc by means of sockets. A python application runs a socket server, and on the Fanuc robot the client.
However, I have two additional questions I would like to ask you.
1) How can I send position data from the robot (for example x-axis) from the client to the server? I assume putting the script in BG-logic and refresh the variable constantly. However, how will the script look like? An example would be nice.
xPos=($SCR_GRP[1].$MCH_POS_X*10)
2) Do I need to open and close the server every time I want to send data to the server? Or just loop forever in a while loop?
Thanks in advance. Below my code.
Code
PROGRAM dsenddata
%STACKSIZE = 4000
%NOLOCKGROUP
%NOPAUSE=ERROR+COMMAND+TPENABLE
%ENVIRONMENT uif
%ENVIRONMENT sysdef
%ENVIRONMENT kclop
%ENVIRONMENT bynam
%ENVIRONMENT fdev
%ENVIRONMENT flbt
%INCLUDE klevccdf
%INCLUDE klevkeys
%INCLUDE klevkmsk
VAR
file_var : FILE
tmp_int : INTEGER
tmp_str : STRING[128]
STATUS : INTEGER
entry : INTEGER
loop1 : BOOLEAN
BEGIN
SET_FILE_ATR(file_var, ATR_IA)
SET_VAR(entry, '*SYSTEM*','$HOSTC_CFG[1].$SERVER_PORT',8000,STATUS)
WRITE(' VAR status = ',STATUS,CR)
-- Connect the tag
MSG_CONNECT('C1:',STATUS)
WRITE(' Connect status = ',STATUS,CR)
loop1 = TRUE
IF STATUS = 0 THEN
WHILE loop1 = TRUE DO
WRITE('Opening file...',CR)
OPEN FILE file_var('rw','C1:')
STATUS = IO_STATUS(file_var)
IF STATUS = 0 THEN
tmp_str = 'Senddata'
WRITE file_var(tmp_str)
WRITE('Wrote: ',tmp_str,CR)
WRITE('Waiting to read from server...')
READ file_var(tmp_str)
STATUS = IO_STATUS(file_var)
WRITE('Read status: ',STATUS,CR)
WRITE('Read: ',tmp_str,CR)
loop1 = FALSE
WRITE('Closed file.',CR)
CLOSE FILE file_var
ELSE
WRITE('Error opening file',CR)
loop1 = FALSE
ENDIF
ENDWHILE
ENDIF
WRITE('Disconnecting..', CR)
MSG_DISCO('C1:',STATUS)
WRITE('Disconnect status=',STATUS,CR)
END dsenddata
Display More