hexagon logo

Using Variables in READLINE

This is probably a simple syntax problem, but searching has not given me any clues.

Goal: automate report display of heat lot code unique to workpiece serial #.

Done: Operator inputs serial # which is assigned to variable V1.

Done: CSV file created with master list of serial #s in first column with heat lot codes in next column.

Not working: getting file pointer to look for a variable (V1 the serial #) to return text after.

The READLINE example from the Help is designed to look for a standard block of text (Part ID, Location, etc) to return text after.

In my code so far, file pointer looks for text "V1" but returns nothing as it's not looking for the value of variable V1.

Code:

C1         =COMMENT/INPUT,YES,'Serial Number:'
            ASSIGN/V1=C1.INPUT
FPTR       =FILE/OPEN,C:\BLADERUNNER\BLADES\ROW_2\ROW2_HEAT_LOT_CODES.CSV,READ
VREAD      =FILE/READLINE,FPTR, "V1" +{VCODE}
            COMMENT/REPT,VCODE
            FILE/CLOSE,FPTR,KEEP
.
.
.


Thanks in advance!
  • You are defining the variable as the string "V1", not the variable named V1.

    Does this work any better?
    VREAD      =FILE/READLINE,FPTR, V1 + {VCODE}


    I guess VCODE is defined/set earlier in the program?
  • Hmmmm...

    Update:
    Added the explicit declaration of VCODE and filled it with a dummy value.
    Changed the syntax per recomendation.
    Note that "198" is the actual sample workpiece serial #.

                ASSIGN/VCODE=42
    C1         =COMMENT/INPUT,YES,'Serial Number:'
                ASSIGN/V1=C1.INPUT
    FPTR       =FILE/OPEN,C:\BLADERUNNER\BLADES\ROW_2\ROW2_HEAT_LOT_CODES.CSV,READ
    VREAD      =FILE/READLINE,FPTR, V1 + {VCODE}
                COMMENT/REPT,VCODE
                FILE/CLOSE,FPTR,KEEP


    Same results - the report displays:
    'Serial Number:' 198
    0


    So the dummy value of 42 is being replaced with 0.


    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    Next attempt:
    Converted the CSV file to a text file and replaced all comma seperators with spaces.
    Also, I added a comment line to display the success or failure of the read, which is stored in the VREAD variable of the READLINE command.

                ASSIGN/VCODE=42
    C1         =COMMENT/INPUT,YES,'Serial Number:'
                ASSIGN/V1=C1.INPUT
    FPTR       =FILE/OPEN,C:\BLADERUNNER\BLADES\ROW_2\ROW2_HEAT_LOT_CODESTXT.TXT,READ
    VREAD      =FILE/READLINE,FPTR, V1 + {VCODE}
                COMMENT/REPT,VCODE
                FILE/CLOSE,FPTR,KEEP


    Report displays:
    'Serial Number:' 198
    42
    ERROR


    This tells me that the READLINE is not wiping out the dummy value of 42 that I used while assigning VCODE.

    This is clearly a step in the wrong direction.


    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Round 3:
    OK, change back to CSV but keep the other changes:
                ASSIGN/VCODE=42
    C1         =COMMENT/INPUT,YES,'Serial Number:'
                ASSIGN/V1=C1.INPUT
    FPTR       =FILE/OPEN,C:\BLADERUNNER\BLADES\ROW_2\ROW2_HEAT_LOT_CODES.CSV,READ
    VREAD      =FILE/READLINE,FPTR, V1 + {VCODE}
                COMMENT/REPT,VCODE
                COMMENT/REPT,VREAD
                FILE/CLOSE,FPTR,KEEP


    Report displays:
    'Serial Number:' 198
    0
    ERROR


    Same failure-to-read error but for some reason the CSV file method replaces the dummy 42 with 0.

    OK, the little window of experimentation time has closed. Back to production.

    vpt.se, thank you for trying to help me. I suspect I may have to dwelve into scripting to accomplish this automation.

    - Josh
  • Minor progress:
    VREAD      =FILE/READLINE,FPTR, {V1} + {VCODE}

    This results in an actual value from the target CSV file being read in. Unfortunately it's not the correct value, which would be the code corresponding to my 198 serial # assigned to V1, but merely the value in the first row of the second column.

    This tells me that the code posted above is causing the file pointer to look at the first line of the file, skip over the first block of text no matter what it is, grab the second block of text after the delimiter, and stuff it into the variable VCODE.

    ........TO BE CONTINUED......
  • Readline is a serial read not a random read...

    You will have to loop to find what you want.

    Why the braces"{}" around your variables?
  • Readline is a serial read not a random read...

    You will have to loop to find what you want.


    I just discovered a method in the help file that may work, involving looping and treating the line as a string to be seperated into two variables. It's near the end of the READLINE section, in the Sample Code Dealing With Numbers Containing Preceding Zeros. If I can get this groggy CMM to boot up I'll test it and post it.



    Why the braces"{}" around your variables?

    The braces on the first variable V1 were just part of me trying different syntax to see what effect various character sets have on the execution of code. I was suprised to se that they made it skip over the delimiter.
    The braces on the second variable, VCODE, tell PCD to take the read-in data and store it in that variable. I got that from the READLINE help file.