Posts by pramtekkar

    thank you all for the help. I data format to be transferred from cognex 3d scanner can be in the Ascii type, 16 bit- signed integer and soo on. Please see the attachment. I have created variable in my karel program to accept this data. Ca you please let me know if the variables I declared are wrong and wont accept the data ?
    is my line of code to read the file from cognex application correct?


    PROGRAM Cognex
    %COMMENT = 'KL_SocketMessaging V9.1'
    %STACKSIZE = 8096
    %NOLOCKGROUP
    %NOPAUSESHFT
    %NOPAUSE = ERROR + COMMAND + TPENABLE
    %NOBUSYLAMP
    %NOABORT = ERROR + COMMAND
    %INCLUDE KLEVCCDF -- predefined key character code constants
    %INCLUDE KLIOTYPS -- karel IO type definitions
    %INCLUDE KLEVKEYS -- predefined karel key code constants





    VAR ---- Global Variable declaration
    file_var : FILE -- for client communication
    enc_count: INTEGER
    tmp_int : INTEGER
    tmp_int1 : INTEGER
    tmp_str : STRING[128]
    status : INTEGER -- communication status
    entry : INTEGER
    try : INTEGER
    xs : STRING[128]
    ys : STRING[128]
    angles : STRING[128]
    x : REAL
    y : REAL
    angle : REAL
    comment : STRING[16]
    loop1 :BOOLEAN
    my_pos :XYZWPR




    BEGIN

    MSG_PING('S3:',status)
    WRITE TPDISPLAY('pinging',status)

    SET_FILE_ATR(file_var, ATR_IA)
    SET_VAR(entry,'*SYSTEM*','$HOSTC_CFG[3].$SERVER_PORT',5001,status)


    -- Connect the tag
    WRITE TPDISPLAY('Connecting…',CR)
    MSG_DISCO('S3:', status) ----- closing port before start


    MSG_CONNECT ('S3:',status)
    WRITE('Connect Status =',status,CR)
    loop1= TRUE

    IF status = 0 THEN
    WHILE loop1 = TRUE DO
    WRITE TPDISPLAY('OPENING FILE..',CR)
    OPEN FILE file_var('RW','S3:')
    status=IO_STATUS(file_var)
    IF status = 0 THEN
    FOR tmp_int =1 TO 10 DO
    READ file_var(tmp_str ::10)
    READ file_var(tmp_int ::10)
    IF status <> 0 THEN
    WRITE('Loop Test Fails',CR)
    loop1 = FALSE
    tmp_int = 10
    ENDIF
    ENDFOR
    ENDIF
    ENDWHILE
    ENDIF

    READ file_var(xs::10)
    READ file_var(ys::10)
    READ file_var(ys::10)
    WRITE TPDISPLAY ('disconnecting', CR)
    MSG_DISCO('S3:',status) --Disconnect Socket

    -- Convert the data
    CNV_STR_REAL(xs, x)
    CNV_STR_REAL(ys, y)
    CNV_STR_REAL(angles, angle)
    WRITE TPDISPLAY('X:',x,CR,'Y:',y,CR,'R',Angle,CR)
    END Cognex


    Please let me know how can I proceed to get the right data in the correct format.
    How can I read daa from the cognex file into group inputs?

    I am new at socket messaging and got this code for communication between cognex and fanuc. I made few modification.
    I have few doubts.


    Question
    1) What will the code line mp_str='' will do ?
    2) the status of the connection is coming a hug number not a 1 or a 0 ? How should I approach?
    3) What does READ file_var (xs::0::2, ys::0::2, angles::0::2) represent?
    4) READ file_var(mp_str) ?? the file_var will access which file or variable from the cognex? Where am I able to get all the variables read in the fanuc tp pendant?



    PROGRAM SOCKET_MESSAGING
    %COMMENT = 'KL_MAIN V9.1'
    %STACKSIZE = 8096
    %NOLOCKGROUP
    %NOPAUSESHFT
    %NOPAUSE = ERROR + COMMAND + TPENABLE
    %NOBUSYLAMP
    %NOABORT = ERROR + COMMAND
    %INCLUDE KLEVCCDF -- predefined key character code constants
    %INCLUDE KLIOTYPS -- karel IO type definitions
    %INCLUDE KLEVKEYS -- predefined karel key code constants
    %INCLUDE KLEVKMSK -- predefined mask codes for built in functions


    VAR
    file_var : FILE -- for client communication
    tmp_int : INTEGER
    mp_str : STRING[128]
    status : INTEGER -- communication status
    entry : INTEGER
    try : INTEGER
    statuss :STRING[1]
    xs :STRING[9]
    ys :STRING[9]
    angles :STRING[9]
    x :REAL
    y :REAL
    angle :REAL



    CONST
    port_number= 23 --- Socket port number


    BEGIN

    SET_FILE_ATR(file_var, ATR_IA)
    SET_VAR(entry,'*SYSTEM*','$HOSTC_CFG[3].$SERVER_PORT',port_number,status)


    -- Connect the tag
    WRITE TPDISPLAY('Connecting…',CR)
    MSG_DISCO('C3:', status) ----- closing port before start
    -- Need to be called before any tag can be used for socket messgaing (1st parameter is the tag name ,2nd parameter integer that will contain status of the operation)
    MSG_CONNECT ('C3:',status)
    WRITE('Connect Status =',status,CR)
    OPEN FILE file_var('rw','C3:')

    -- Read the In-Sight Welcome message
    WRITE TPDISPLAY('Logging In',CR)
    mp_str =''
    READ file_var(mp_str)
    WRITE TPDISPLAY(mp_str,CR)


    -- Read User: prompt
    READ file_var(mp_str::6::0)
    IF UNINIT(mp_str) THEN
    mp_str = ''
    ENDIF
    WRITE TPDISPLAY(mp_str,CR)
    IF (mp_str <>'User: ') THEN
    WRITE TPDISPLAY('User Failed',CR)
    --Error
    RETURN
    ENDIF


    --Send User Name
    WRITE file_var('admin',CHR(13),CHR(10))


    -- Read Password prompt
    mp_str =''
    READ file_var(mp_str::10::0)
    IF UNINIT(mp_str) THEN
    mp_str = ''
    ENDIF
    WRITE TPDISPLAY(mp_str,CR)
    IF (mp_str <>'Password: ') THEN
    WRITE TPDISPLAY('Password Failed',CR)
    --Error
    RETURN
    ENDIF


    --Send Password
    WRITE file_var('',CHR(13),CHR(10))


    -- Read Login Response
    mp_str =''
    READ file_var(mp_str)
    IF UNINIT(mp_str) THEN
    mp_str = ''
    ENDIF
    WRITE TPDISPLAY(mp_str,CR)
    IF (mp_str <> 'User Logged In') THEN
    WRITE TPDISPLAY('Log In Failed',CR)
    --Error
    RETURN
    ENDIF


    -- Instruction In-Sight to Acquire an Image
    -- (wait for a response)
    WRITE TPDISPLAY('Trigger',CR)
    WRITE file_var ('sw8',CHR(13),CHR(10))

    -- Read Status
    READ file_var (statuss)
    IF statuss <> '1' THEN
    WRITE TPDISPLAY('sw8 Failed',CR)
    RETURN
    ENDIF

    -- Get the value in cell C7
    WRITE TPDISPLAY('Get Value C7',CR)
    WRITE file_var ('gvc007',CHR(13),CHR(10))

    -- Read Status
    READ file_var (statuss)
    IF statuss <> '1' THEN
    WRITE TPDISPLAY('gvc007 Failed',CR)
    RETURN
    ENDIF

    -- Read the data
    -- This will split the information at the quotations "'".
    -- Example String '10.5''9.8''15.9'
    READ file_var (xs::0::2, ys::0::2, angles::0::2)


    --Disconnect Socket
    MSG_DISCO('C3:', status)


    -- Convert the data
    CNV_STR_REAL(xs, x)
    CNV_STR_REAL(ys, y)
    CNV_STR_REAL(angles, angle)
    WRITE TPDISPLAY('X:',x,CR,'Y:',y,CR,'R',Angle,CR)


    END SOCKET_MESSAGING

Advertising from our partners