raydodo - 2019-09-26

Hello all

I have a Kunbus RevPi Core3 running a Profinet controller with various IO-Link devices attached. I can access process data without issue. The following code works fine for an acyclic call:

PROGRAM PLC_PRG
VAR
    al_read : ProfinetCommon.IOL_CALL;
    err : ProfinetCommon.IOL_Error;
   convert: U_BYTES_TO_REAL;
   setpoint:REAL;
   
   aDataIn : ARRAY[0..3] OF BYTE;
END_VAR
IF elec.PNIOStatus = 0 THEN 
      //start the execution by setting REQ = TRUE !
      al_read.REQ    := TRUE;  
      
      al_read.ID := elec.GetID(0, 1, 2);        // ID of IO-Link Master
      al_read.CAP := 16#B400;                     // Fix for Ed. 2 devices. For legacy devices get value from vendor's documentation or use CommFB.RDREC for reading out IOL-M directory data (RDREC.Index = 0xB063)
      al_read.Port := 1;                          // IO-Link device is plugged in Port 1
      al_read.RD_WR := FALSE;                     // Read data
      al_read.IOL_Index := 65;                    // IOL-Index = 20 means 'Product Text', this will result in something like 'Laser Sensor'
      al_read.IOL_Subindex := 0;                  // 0 = read complete data-item
      al_read.LEN := 4;
      al_read.IOL_Data := ADR(aDataIn);       // an ARRAY[] OF BYTE will be returned
      
      al_read();
      IF(al_read.ERROR) THEN
         IF(al_read.STATUS <> 0) THEN
            // Profinet Communication-Error
            // e.g. DF80A100 (= PNIORW, application: write error) will be returned if a wrong 'ID' / submodule identifier is used as target
         ELSE
            // get IO-Link related error:
            err := ProfinetCommon.DECODE_IOL_STATUS(al_read.IOL_STATUS);
         END_IF
      ELSIF(al_read.DONE_VALID) THEN
         setpoint   := (BytesToReal(aDataIn[0], aDataIn[1], aDataIn[2], aDataIn[3])) ;   
      END_IF
      al_read.REQ := al_read.BUSY;        //reset REQ, we need just one execution
   END_IF

However, as soon as I split this out into a function block with a ReadAsync private method, accessed through an instance set up in the GVL, the call runs, there are no IOL_CALL.ERROR issues, but IOL_CALL.DONE_VALID is never TRUE. So I can't get any data back. I have attached a file highlighting the issue.

So, I think my GoogleFu is failing me, but how can I debug the DONE_VALID response? I don't know what is causing the problem. I am creating a struct / function block class for every IO-Link device.

Thanks for any links / suggestions

Regards

Ray

testbed_rebuild.project [259.94 KiB]

 

Related

Talk.ru: 1
Talk.ru: 2
Talk.ru: 3