Call physical address by variable

galexis
2020-06-09
2020-06-29
  • galexis - 2020-06-09

    There is any solution to cal physical , example: %IW1
    like this:

    i:=1;
    
    MyVariable:=%IWi;
    

    Thanks for your answers.
    Bests regards.

     
  • galexis - 2020-06-10

    Is it possible to make POINTER move X byte from %IW1 to a numbrer of byte ?

     
    • i-campbell

      i-campbell - 2020-06-29
      PROGRAM PLC_PRG
      VAR
          value : BYTE;
          position0 : POINTER TO BYTE;
          index : BYTE;
      END_VAR
      position0 := ADR(%IB0);
      value  := position0[index];
      
       
      • galexis - 2020-06-29

        This code work for several %IB (example %IB0 to %IB10) to position0 in 1 instruction if I set index to 10 ?

         
  • galexis - 2020-06-11

    I want to put all data receive by ethernet IP in data by code, I don't want to use graphic interface.

     
  • Lo5tNet - 2020-06-11

    Are you asking to do something like:

    VAR
        iValue: INT := 511; //Value to be split or you could do wValue AT %IW1: WORD;
        pValue: POINTER TO BYTE; //Address of iValue
        byValue1: BYTE; //LSB for iValue
        byValue2: BYTE; //MSB for iValue
    END_VAR
    
    //Set pointer
        pValue := ADR(iValue);
    
    //Get LSB byte in int value
        byValue1 := pValue^; //Value would be 255
    
    //Increment to next byte in int value
        pValue := pValue + 1;
    
    //Get MSB byte in int value
        byValue2 := pValue^; //Value would be 1
    

    There are a lot of ways to approach this so it would help if you showed an example using sudo code to help show what you are trying to accomplish. You could also use a UNION to split values up into smaller data types.

     

    Last edit: Lo5tNet 2020-06-11
  • galexis - 2020-06-14
    iValue: INT := 511; //Value to be split or you could do wValue AT %IW1: WORD;
    

    I want to define on input of FB the address %IW1. Is it possible ? And after, by code incremente adress to %IW2, %IW3, etc...

    The idea is create a function block with input the first address of %IW and the first address of %QW:

    FB for Slave ethernet ip 1:
    First_Input := %IW1;
    First_Input[1]:= DATA[1].word_1;
    First_Input[2]:= DATA[1].word_2;
    First_Input[3]:= DATA[1].word_3;
    ....

    FB for Slave ethernet ip 2:
    First_Input := %IW10;
    First_Input[1]:= DATA[2].word_1;
    First_Input[2]:= DATA[2].word_2;
    First_Input[3]:= DATA[2].word_3;
    ....

    FB for Slave ethernet ip 10:
    First_Input := %IW100;
    First_Input[1]:= DATA[2].word_1;
    First_Input[2]:= DATA[2].word_2;
    First_Input[3]:= DATA[2].word_3;

     

    Related

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

  • Lo5tNet - 2020-06-15

    This should be enough to get you started and you can build off of this.

    ******************************************************
    FUNCTION MyFunction : WORD
    VAR_INPUT
        pValue : POINTER TO WORD; //Pointer to start address. In your case it would be %IW0
        wIndex : WORD; //Index above start address to go to. 0 = %IW0, 1 = %IW1, 2 = %IW2.....
    END_VAR
    pValue := pValue + (wIndex * SIZEOF(WORD)); //Set pointer to desired index
    MyFunction := pValue^; //Get value from pointer and return
    ******************************************************
    //Then call it like:
    PROGRAM PLC_PRG
    VAR
        wIndex : WORD; //Index value to get. 0 = %IW0, 1 = %IW1, 2 = %IW2.....
        wReturnValue : WORD; //result from function call for test
    END_VAR
    wReturnValue := MyFunction(pValue:= ADR(%IW0), wIndex:= wIndex);
    
     
    • galexis - 2020-06-16

      wIndex doesn't work. For pValue := %IW8 : when wIndex = 0 I have the good result of %IW8 but if I put wIndex:=1; I haven't got value of %IW9. Result is 0.

       
  • aliazzz

    aliazzz - 2020-06-15

    Maybe you should check out this store example: https://store.codesys.com/io-mapping-tool.html

    It enables you to graphically map IO to an FB 'on the fly' or do it programmatically.
    Plus this example is open-source, so if you want to know how it works or modify it for your own needs you can do that.

    Good luck

     
    • galexis - 2020-06-16

      I think it's not I want to do....

       
  • galexis - 2020-06-16
     
    • aliazzz

      aliazzz - 2020-06-16

      That is the standard/normal/vanilla symbolic way of coupling IO...

      In general there are 2 vanilla flavours (there are way more options but those aren't exactly vanilla anymore);
      1 Declare variables in your IO point and reference that variable in your POU (program, FB, Func, whatever)
      2 Declare variables in your POU and couple them to an IO point.

      PS: I never use hardcoded IO adresses in my code (%I, %Q, %M etc) .

       

      Last edit: aliazzz 2020-06-17
  • galexis - 2020-06-29

    Is it possible to create my own ethernet ip device ? I have x same device, I/O are mapped on table, just number of ligne change. Could I create my special device with special parameter which defines number of line in the table, I could win a lot of time.

     

Log in to post a comment.