Byte conversion between RFID and RS232 module

Dokee
2008-06-26
2008-07-09
  • Dokee - 2008-06-26

    Hello,

    I have a programable gateway with RFID, and RS232 modul. I would like to send the RFID data to PLC on RS232. In the FB of the RFID In/Output has a 'ARRAY [1..1024] OF BYTE' variables and the RS232 input has 'POINTER TO ARRAY [0..7] OF BYTE'. Can I send the data between this 2 module with any byte converter?

    Does anyone have any experience?

    Greetings,

    Dokee

     
  • robkristiaan - 2008-06-26

    Hello,

    I do not quite get what you are looking for, do you want to convert an ARRAY [1..1024] OF BYTE to a POINTER TO ARRAY [0..7] OF BYTE ?

    in that case it is not just a conversion, a pointer is not a type its a link to another variable so it only holds the memory address of the variable that it links to.

    (isnt it possible to change the array 0..7 to 0..1023 or 1..1024?)

     
  • Dokee - 2008-07-01

    I see, thx.

    That case, have I chance to fix this problem?

    Because the FB, like BLxx_1RSxxx_FB, TX and RX type 're "POINTER ARRAY [0..7] OF BYTE" types. Can I modify any types or that FB inputs 're fix?

    Sorry for my questions, it possible not correct, but I'm a new in this theme.

     
  • robkristiaan - 2008-07-01

    this is only one way!!!!, you have to rewrite a part to do it the other way as well

    you can use a conversion function block like this:

    (warning test this extensively, it worked when i tested it)

    FUNCTION_BLOCK Convert (*Convertion FB*)
    VAR_INPUT
       abyInput:ARRAY [1..1024] OF BYTE; (*a = array by = byte for easyer reading code*)
       byCounter:BYTE; (*possible values 0..127    0 represents the first 8 bytes of the 1024 array and 127 represents the last 8 bytes of the 1024 array*)
    END_VAR
    VAR_OUTPUT
       abyOutput: ARRAY [0..7] OF BYTE;
    END_VAR
    VAR
       i:INT;
    END_VAR
    (*end declaration*)
    FOR i:=0 TO 7 DO (*0..7 to read 8 bytes out of the 1024 array. There are also dirty ticks to get rid of the for-loop, but this solution is the easyest to read*)
       abyOutput[i]:=abyInput[(byCounter*8)+i+1];                   (* byCounter*8 calculate the offset with the given 8 bytes to read +i is to cycle though the 8 bytes in the array +1 is to compensate for the startposition of 1*)
    END_FOR
    PROGRAM PLC_PRG (*MAIN PROGRAM (JUST FOR A TEST)*)
    VAR
       conv:Convert;
       byaTest: ARRAY[1..1024] OF BYTE;
       pbyaTest: POINTER TO ARRAY[0..7] OF BYTE;
       i:INT;
       j:BYTE;
       iState:INT:=0;
       str:STRING(1024);
    END_VAR
    (*end declaration*)
    CASE iState OF
       0: (*some data ito the test array*)
           FOR i:=1 TO 1024 DO
             byaTest[i]:=INT_TO_BYTE(i); (*values will get strange after 255*)
          END_FOR
          iState:=1;
       1: (*read data (i read it back into an 1024 array*)
          FOR j:=0 TO 127 DO (*1024 bytes/8 bytes=128 sets of 8 bytes (0..127 = 1..128)*)
             conv(abyInput:=byaTest,byCounter:=j);
             pbyaTest (*this is the pointer of the FB*):=ADR(conv.abyOutput); (*set the pointer to the address of the output*)
          END_FOR
          iState:=2;
       2:
          ;
    END_CASE
    
     
  • Dokee - 2008-07-01

    I'll test it, and very thanks for your help, and time.

    Regards,

    Dokee

     
  • Dokee - 2008-07-03

    I tested the program, and it worked alone. After I imported to my project, and make a program onject from the FB (when you sent).

    This prg name is CONVERT2. I set up the convert2 input to [CH_0_TXREF] adress (than I want to be send), and output to [RStxData] memory adress.

    This adress type is ARRAY [0..7] OF BYTE, like the abyOutput type. But the FB (BLxx1RSxxx_FB) input seems to be like a POINTER OF ARRAY... type adress.

    I send it to my screenshot about the program, I'll hope you look averything, that you need. If you have any time to look this, than I 'll thank you so much.

    Best regards,

    Dokee[/img]

    IMG: Teszt.jpg

     
  • robkristiaan - 2008-07-04

    Hello,

    edit: I didn't see the image the first time I looked, the poblem is you try to convert a 0..7 array to a 0..7 pointer array.

    the solution is to send the address of the 0..7 array to the FB.

    in structured text it lookes like this: ptTXdata:=ADR(RStxData);

    Is it possible to get the program including the function blocks you use (or the library), so i can take a crack at it

    I still don't know in what direction you want to send the data, from 1..1024 array to 0..7 array, the other way around or both ways. The function block i send you is only for 1..1024 array to 0..7 array

     
  • Dokee - 2008-07-09

    Thank You, durring I fix the variables, because I gave a wrong value of the output variable, and now fine. Just I don't near at net, and don't answer for u.

    Thank you again,

    Dokee

     
  • Dokee - 2008-07-09

    Oh, yes, the image. I see in my pc, but don't found in other pc. Sorry, that was a screenshot from the plc_prgogram trunk, visibles the in/out variables. Never mind!

     

Log in to post a comment.