Hello there,
I have created a socket server (Fanuc robot LR Mate 200iC/5L with R30iA controller) and client on Pc with python.
$SCR_GRP[1].$m_pos_enb = True
The server code looks like this:
Code
PROGRAM tcpserver2
%STACKSIZE = 4000
%NOLOCKGROUP
%NOPAUSE=ERROR+COMMAND+TPENABLE
%ENVIRONMENT uif
%ENVIRONMENT sysdef
%ENVIRONMENT memo
%ENVIRONMENT kclop
%ENVIRONMENT bynam
%ENVIRONMENT fdev
%ENVIRONMENT flbt
%INCLUDE klevccdf
%INCLUDE klevkeys
%INCLUDE klevkmsk
-------------------------------------------------------------------------------
VAR
file_var : FILE
tmp_int : INTEGER
tmp_int1 : INTEGER
tmp_real : REAL
tmp_str : STRING[128]
tmp_str1 : STRING[128]
STATUS : INTEGER
entry : INTEGER
posreg : XYZWPR
my_real : REAL
-------------------------------------------------------------------------------
ROUTINE get_real(prog_name : STRING; var_name : STRING) : REAL
VAR
entry : INTEGER
i : REAL
STATUS : INTEGER
BEGIN
GET_VAR(entry, prog_name, var_name, i, STATUS)
IF STATUS<>0 THEN
WRITE('Error:[',prog_name,']',var_name,STATUS,CR)
ENDIF
RETURN(i)
END get_real
-------------------------------------------------------------------------------
BEGIN
-- DISCONNECT the server port BEFORE doing a CONNECT
WRITE('Disconnecting..',CR)
MSG_DISCO('S3:',STATUS)
WRITE('Done.',CR)
SET_FILE_ATR(file_var, ATR_IA)
-- set the server port before doing a connect
SET_VAR(entry, '*SYSTEM*','$HOSTS_CFG[3].$SERVER_PORT',1002,STATUS)
WRITE('Connecting..',CR)
MSG_CONNECT('S3:',STATUS)
WRITE(' Connect Status = ',STATUS,CR)
IF STATUS = 0 THEN
-- Open S3:
WRITE ('Opening',CR)
FOR tmp_int1 = 1 TO 20 DO
OPEN FILE file_var ('rw','S3:')
STATUS = IO_STATUS(file_var)
WRITE (STATUS,CR)
IF STATUS = 0 THEN
-- WRITE an INTEGER
FOR tmp_int = 1 TO 1000 DO
WRITE('Reading',CR)
-- Read 10 bytes
BYTES_AHEAD(file_var, entry, STATUS)
WRITE(entry, STATUS, CR)
READ file_var (tmp_str::10)
STATUS = IO_STATUS(file_var)
WRITE (STATUS, CR)
WRITE('Succesfull read data from client..',CR)
WRITE('Send data back to client..',CR)
-- Write 4 bytes (REAL)
my_real = get_real('*SYSTEM*','SCR_GRP[1].$MCH_POS_X')
WRITE file_var (my_real::9::2)
STATUS = IO_STATUS(file_var)
WRITE (STATUS, CR)
WRITE('Done sending!',CR)
ENDFOR
CLOSE FILE file_var
ENDIF
ENDFOR
WRITE('Disconnecting..',CR)
MSG_DISCO('S3:',STATUS)
WRITE('Done.',CR)
ENDIF
END tcpserver2
Display More
I am stuck on the following code below. I am trying to send a system variable to the client.
Code
-- Write 4 bytes (REAL)
my_real = get_real('*SYSTEM*','SCR_GRP[1].$MCH_POS_X') <<
WRITE file_var (my_real::9::2)
Can someone help me, please?