Results 1 to 3 of 3

Thread: Decode EPC

  1. #1

    Decode EPC

    Hallo,

    Ik krijg van een apparaat een JSon string terug met daarin een EPC code.
    Deze EPC code is hierin als volgt opgeslagen "base64url-encoded EPC of the tag"
    Nu wil ik deze tag omzetten naar een 96 bit hexcode (dus 24 nibbels)
    Ik heb wel de voorbeeld code die erbij zit geprobeerd (Python) en deze geeft precies terug wat ik wil
    Echter het lukt mij niet om deze code om te zetten in Delphi.

    de Python code is als volgt:
    Code:
    import base64
    import binascii
    
    my_epc = 'dHADJSAWhYUQABAJ'
    print(binascii.b2a_hex(base64.urlsafe_b64decode(my_epc)))
    
    //answer = b'747003252016858510001009'

  2. #2
    Fornicatorus Formicidae VideoRipper's Avatar
    Join Date
    Mar 2005
    Location
    Vicus Saltus Orientalem
    Posts
    5,703
    Zoiets?
    Click image for larger version. 

Name:	PecDecoder.png 
Views:	57 
Size:	2.9 KB 
ID:	8173
    Delphi Code:
    1. uses
    2.   NetEncoding;
    3.  
    4. function DecodePec(ABase64: string): string;
    5. var
    6.   MyValue: TArray<Byte>;
    7.   MyByte: Byte;
    8. begin
    9.   Result := '';
    10.   MyValue := TNetEncoding.Base64.DecodeStringToBytes(ABase64);
    11.   for MyByte in MyValue do
    12.     Result := Result + IntToHex(MyByte);
    13. end;
    14.  
    15. procedure TForm2.Button1Click(Sender: TObject);
    16. begin
    17.   Edit2.Text := DecodePec(Edit1.Text);
    18. end;
    TMemoryLeak.Create(Nil);

  3. #3
    Thanks dat werkt.
    Ik was zelf bezig met de TBase64Encoding component.
    Waar ik dus niet uitkwam/niet doorhad was de DecodeStringToBytes functie.

    Maar zo werkt ook

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •