B4J Question (SOLVED)UDP packet not decoding

Discussion in 'B4J Questions' started by alienhunter, Dec 21, 2018.

  1. alienhunter

    alienhunter Active Member Licensed User

    i am trying to decode a UDP packet but it does not work somehow
    I tried byteconvertor and still nothing
    the UDP comes from
    and it sends Raw serial data over UDP.
    anyone knows how to
    thank you

    the code
    Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Dim UDPSocket1 As UDPSocket
    End Sub

    Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    End Sub

    Sub UDP_PacketArrived (Packet As UDPPacket)
    Dim msg As String
        msg = 
    BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")
    Log("PACKET LENGTH:" & Packet.Length)
    Log("PACKET OFFSET:" & Packet.Offset)
    Log("PACKET STRING:" & Packet.toString)

    End Sub
    this is the output in the log Capture.JPG
  2. Daestrum

    Daestrum Well-Known Member Licensed User

    Have you tried other encodings other than UTF-8, maybe it's just plain ascii.
  3. alienhunter

    alienhunter Active Member Licensed User

    yes sir
  4. Daestrum

    Daestrum Well-Known Member Licensed User

    Do you know what data it should be sending?

    if so use ByteConverter > HexFromBytes to see the data in hex, then it should be easier to see how it has been encoded.
  5. alienhunter

    alienhunter Active Member Licensed User

    ok i will try

    as far i can understand it shoud be int or float , it should return a temperature value or a volt value
  6. alienhunter

    alienhunter Active Member Licensed User

    This is the hex
    PACKET HEX:0000410037076C3B00006E6FBFC5ADC6C1200000BFAFA5B00000FFFF00000000000041200000C12000000000FFFF00000000000041200000C12000000002010000020000
  7. DonManfred

    DonManfred Expert Licensed User

    do you have an precise descriptiom about the packet?

    Using UDP-Packet decoding for a PS/4 Game i used RandomAccessfile to parse the Packets

    Example code with no relation to your packet.

    The Indexes used in the code are Values from the F1 game packets...

    You need to use the right index for your packets.
    See packetdescription to find out

    If you know the right index and you know there must be a value (int, float, long) you can pase the packet into the right values.
    Sub UDP_PacketArrived (Packet As UDPPacket)
    Dim raf As RandomAccessFile
    True'change the endianess if the version number is incorrect
    dim time as Long = raf.ReadLong(4' example to read a LONG value from index 4

    end sub
    Sub ShortToUnsigned(s As Short) As Int
    Return Bit.And(0xFFFF, s)
    End Sub
    Last edited: Dec 21, 2018
    alienhunter likes this.
  8. alienhunter

    alienhunter Active Member Licensed User

    i tried to make sense on every index to what i see in the controller looking for -3.7627
    and it does not

    i found something that may help
    see code below

  9. Erel

    Erel Administrator Staff Member Licensed User

    Please use [code]code here...[/code] tags when posting code.
    There are many mistakes in your code.

    Reading the data based on the structure you posted:
    Dim length As Short = raf.ReadShort(raf.CurrentPosition)
    Dim enabled As Byte = raf.ReadByte(raf.CurrentPosition)
    Dim CurRawValue As Short = raf.ReadShort(raf.CurrentPosition)
    4 bytes is either Int or Float. Never Double.
    alienhunter likes this.
  10. alienhunter

    alienhunter Active Member Licensed User

    thank you very much for your time and code
    yes i know the code is not correct :oops: i was giving this a try i did not know further how to
    only one thing
    i do not have the raf.ReadByte member raf.readbytes using RandomAccessFile 1.15 version

    But it worked with CurRawValue
    this is a udp stream used in mtconnect from a machine

    B4j = VALUE :10486
    Mtconnect = "ACTUAL">10486.0000000000</PathFeedrate>

    thanks a lot made my day :)
  11. alienhunter

    alienhunter Active Member Licensed User

    B4J works and looks better than MTconnect client , thank you for all the help

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice