1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

Python 3.5 bytes to float conversion help

Discussion in 'Miscellaneous' started by Pedro Pablo, Oct 20, 2016.

  1. Pedro Pablo

    Pedro Pablo Active Member

    Joined:
    Dec 7, 2015
    Messages:
    119
    Occupation:
    Software Developer
    Location:
    Valparaiso, Chile
    Balance:
    599Coins
    Ratings:
    +47 / 0 / -0
    Hi

    Some time ago i've made a program in Python to read memory and output to an arduino to get a speedometer. Now in the meantime of drumming, coding, keep trying to get the values from Initial D Special Stage and missing my ex-girlfriend, I want to do the same but with another game and using other methods.

    The game that i'm working is Race Driver GRID. I've made a simple UDP listener in Python, but I never worked with bytes (the memory reading module was a pain for me), so IDK what I have to do with this telemetry send by the game:

    b'6t}@q\x1f\x19>\xe4\x08\xc5E\x00\x08%\xbb\xc5\xaa\x84C&\xfe\x05A\xb3\x14\x89\xc4@\x88\xa4;^\xc2\x9b\xb9\x95;\xa4\xbb\x9f\xe5u\xb8t#H>\x823\xee\xb8\x15\x10{\xbf\x00\x9bz\xbf\xed\x05w=\xf3\xc7G\xbe\xe9<\x85\xc0\x1b\xda\x82\xc0 \x9d\x81\xc0\x9e\x9f~\xc0\xc2\xbc\xf8>\x8c\x9dU\xbf\x9d\xc6\xe6?\xe6/P?\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80?\x00\x00\x80?`\x9380\xc0\\\xe4/\x00\x00\x00\x00'

    I know that it's a byte object, so i've started researching from there, but without results. Reading in a post from the arduino forums, combining the 28, 29, 30 and 31 byte i'll get the speed, but my problem is how to do that. I want to know how to get those bytes and combining them. With that not only I can measure the speed, also i can get other kind of data (gear, rpm, etc....) and send it to an arduino (i donde it before)
  2. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    6,010Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    something like

    import socket

    UDP_IP ="0.0.0.0"
    UDP_PORT =20777

    sock = socket.socket(socket.AF_INET,# Internet
    socket.SOCK_DGRAM)# UDP
    sock.bind((UDP_IP, UDP_PORT))
    import struct
    x =0
    y =4
    data, addr = sock.recvfrom(1024)
    output =struct.unpack('f', data[x:y])# 4 bytes at a time
    • Like Like x 1
  3. Pedro Pablo

    Pedro Pablo Active Member

    Joined:
    Dec 7, 2015
    Messages:
    119
    Occupation:
    Software Developer
    Location:
    Valparaiso, Chile
    Balance:
    599Coins
    Ratings:
    +47 / 0 / -0
    Well, yesterday (THE IRONY!) i've figured out hot to get the data

    while True:
    data, addr = sock.recvfrom(1024) # Buffer Size
    speed = struct.unpack("27xf116x", data)
    gear = struct.unpack("131xf12x", data)
    print([int(speed[0]*3.6), int(gear[0])])

    The sad part is couldn't get the RPM. IDK if this the right way to get the data but at least it worked
  4. Pedro Pablo

    Pedro Pablo Active Member

    Joined:
    Dec 7, 2015
    Messages:
    119
    Occupation:
    Software Developer
    Location:
    Valparaiso, Chile
    Balance:
    599Coins
    Ratings:
    +47 / 0 / -0
    Well, i've tested your example and it worked too. So, IDK what choose :sos