CNC - How to manipulate SMC_GeoInfo objects

2024-07-26
2024-07-26
  • trusty-squire - 2024-07-26

    I have an application using CNC GCode interpolation, but I need to modify the GCode provided to the PLC based on certain parameters. I am currently attempting to modify the SMC_GeoInfo objects in the SMC_OutQueue using the code below. Note that all the other code is pretty standard and works fine, but when I add the below it errors.

    PROGRAM TEST
    VAR
        fbReadCncFile : SMC_ReadNCFile2;
        fbCncInterpreter : SMC_NCInterpreter;
        arrCncInterpreter : ARRAY[1..99] OF SMC_GeoInfo;
        pGeoInfo: POINTER TO SMC_GeoInfo;
        giGeoInfo: SMC_GeoInfo;
        // ...
    END_VAR
    
    // ... Some code here in order to read CNC file using SMC_ReadNCFile2 and provide to SMC_NCInterpreter
    
    pGeoInfo := SMC_GetObj(poq:=ADR(fbCncInterpreter.poqDataOut), n:=1);
    
    IF pGeoInfo <> 0 THEN
        giGeoInfo := pGeoInfo^;
        // Do some manipulation here, then update the queue at the same position
        MC_SetObj(poq:=ADR(fbCncInterpreter.poqDataOut) , n:=0 , pgi:=ADR(giGeoInfo) );
    END_IF
    

    It throws an error when I get to the line giGeoInfo := pGeoInfo^;
    Error:

    EXCEPTION [AccessViolation] occured: App=[Sim.Device.Application], Task=[PathTask]

    How do I use SMC_GetObj and access the data? It creates a pointer with the value as shown in the photo, but all the dereferenced values say dereference of invalid pointer.

     
  • trusty-squire - 2024-07-26

    Sometimes you just need to pose a question on a forum and re-read it to get clarity.

    pGeoInfo := SMC_GetObj(poq:=ADR(fbCncInterpreter.poqDataOut), n:=1);
    

    This won't work, I'm providing a pointer to a pointer, as poqDataOut is already a pointer! I just need to remove the ADR() and it works.

    pGeoInfo := SMC_GetObj(poq:=fbCncInterpreter.poqDataOut, n:=1);
    
     

Log in to post a comment.