GET_VAR for checking initialize of a position in a structure

  • i am trying to look into a structure that contains positional data that i pull out depending on what "carrier" is in front of the robot.

    each Carrier has a max of 24 drop positions and a min of 1.


    the goal is to only have 1 program and move in the positions required for that specific carrier at the robot.


    however when i try to load positions that are not initialized, the program gives me the INTP-311 fault.


    How can i check if the array element has data in it or not. and then skip over the loading line?




    PROGRAM CarrierArray

    %ALPHABETIZE

    %CMOSVARS

    %COMMENT ='CarrierPositions'


    TYPE

    Location = STRUCTURE

    ClipNum : ARRAY[25] OF XYZWPR

    ENDSTRUCTURE


    VAR

    CarrierNum : ARRAY[64] OF Location

    RegNum, Status, CurrCarrier, PosRegUpdate, DropLocation, data_type, entry :INTEGER

    Real_Val:REAL

    str_value:STRING[10]


    ----------------------------------------------------------------------------------

    ROUTINE CheckPosReg(ival:INTEGER):BOOLEAN


    BEGIN


    END CheckPosReg


    -----------------------------------------------------------

    ROUTINE clearPosReg

    VAR

    PreRegNum, PosRegNum:INTEGER

    BEGIN

    WRITE(CHR(137),CHR(128));

    DELAY 1000

    WRITE(' Clearing All Drop Position Registers' ,CR)

    FOR RegNum = 100 TO 125 DO

    PreRegNum = RegNum +100

    PosRegNum = PreRegNum +200

    CLR_POS_REG(regNum,0,status)

    CLR_POS_REG(PreRegNum,0,status)

    CLR_POS_REG(PosRegNum,0,status)

    ENDFOR

    WRITE(' All Drop Position Registers Cleared' ,CR)

    WRITE(' Ready For Carrier Data' ,CR)

    END clearPosReg


    ----------------------------------------------------------

    BEGIN

    -- Clear all previous position registers

    clearposReg

    --WAIT FOR CurrCarrier = 100


    GET_TPE_PRM(1,1,CurrCarrier,Real_Val,str_value,status)


    FOR DropLocation =1 TO 25 DO

    PosRegUpdate = DropLocation + 100

    WRITE(' Transferring Data From Carrier:' ,CurrCarrier ,CR)

    WRITE(' Position:' ,DropLocation,CR)

    WRITE(' To PR: ',PosRegUpdate ,CR)

    SET_POS_REG(PosRegUpdate,CarrierNum[CurrCarrier].ClipNum[DropLocation],Status) <-----------------------this line giving issues when "DropLocation" is not initialized

    DELAY 1000

    ENDFOR


    END CarrierArray

  • I'm not sure if there is a way to check for uninitialized registers, maybe someone else can comment on that. But I do have an alternate solution.


    Set all unused PRs to all zeros. Then in your program if you have a drop location that is all zero's you know to not use it.

  • I haven't tested it, but the built in UNINIT function might work, so long as you don't leave it unsubscripted. Something like this:


    nChk = 0

    For nChk = 1 to 32(whatever the array size)

    If UNINIT(yourArray[nChk]) THEN

    yourArray[nChk] = 0

    Endif

    Endfor

Advertising from our partners