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

UDP record and playback in Python

Discussion in 'Miscellaneous' started by vthinsel, Jun 15, 2016.

  1. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    436
    Location:
    FRANCE
    Balance:
    5,963Coins
    Ratings:
    +563 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    Hello,

    I decided to learn Python recently and was looking for a small project to start. When I started developing my first UDP plugin for ProjectCars in VB, I was annoyed with the test/debug which required me to launch PCars on my PS4 and drive for some time, pause, restart, .... If only I had a way to capture UDP data accurately and replay it, with the exact same timing...... I dreamt of it, and here it is !
    You just need to install python 3.x from www.python.org and unzip the attached files in a directory.
    The first tool is used to capture UDP data:
    D:\Perso\Python_UDP_Receiver>python UDPReceive.py -h
    usage: UDPReceive.py [-h] -p PORT [-f FILE] [-b BUFFER] [-c COUNT]
    [-s SECONDS]

    Capture UDP packets for further analysis and playback

    optional arguments:
    -h, --help show this help message and exit
    -p PORT, --port PORT Port to listen to
    -f FILE, --file FILE File to write data to
    -b BUFFER, --buffer BUFFER
    Host target
    -c COUNT, --count COUNT
    Stop capture after x packets
    -s SECONDS, --seconds SECONDS
    Stop capture after x seconds

    D:\Perso\Python_UDP_Receiver>


    As an example : D:\Perso\Python_UDP_Receiver>python UDPReceive.py -p 5606 -f pcars.bin -c 500 -s 60 will capture UDP data from ProjectCars for 60 seconds or 500 packets.

    This tool also generates another output file with .raw suffix which is the raw UDP received data, without any additional data such as timing. The pcars.bin file from the example is compressed and includes timing data used for playback.

    The second tool is for regular playback :
    D:\Perso\Python_UDP_Receiver>python UDPSend_timed.py -h
    usage: UDPSend_timed.py [-h] -p PORT -f FILE -s SERVER [-b BUFFER]

    Send UDP file captured previously using UDPReceive.py

    optional arguments:
    -h, --help show this help message and exit
    -p PORT, --port PORT Port to listen to
    -f FILE, --file FILE File to send
    -s SERVER, --server SERVER
    Host target
    -b BUFFER, --buffer BUFFER
    Buffer size

    D:\Perso\Python_UDP_Receiver>


    You can send to a given IP address, or even broadcast like ProjectCars is doing.
    The last tool uses the raw UDP file and replays it as fast as it can. In fact, I used this one to develop the two others :)

    By using the replay you can easily tune your rig using the same scenario again and again without having to drive. I also checked the behavior of PCars Dash on my tablet.... so many usecases and so easy !

    Feel free to give it a try, and if you have idea for features , feel free to use this thread !

    Python is a really nice language with so many ready-to-use modules making development journey a breeze. :thumbs

    Attached Files:

    • Like Like x 5
    • Creative Creative x 3
  2. AlexinChina

    AlexinChina Member

    Joined:
    Sep 2, 2015
    Messages:
    71
    Location:
    China
    Balance:
    371Coins
    Ratings:
    +8 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
    Good Tools ,I 'll try it later
  3. AlexinChina

    AlexinChina Member

    Joined:
    Sep 2, 2015
    Messages:
    71
    Location:
    China
    Balance:
    371Coins
    Ratings:
    +8 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
  4. Rebeka

    Rebeka New Member

    Joined:
    Mar 11, 2019
    Messages:
    3
    Balance:
    97Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    DC motor, AC motor, SCN6, SimAxe, SimforceGT, 4DOF
  5. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    436
    Location:
    FRANCE
    Balance:
    5,963Coins
    Ratings:
    +563 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    This thread is about recording UDP telemetry stream sent over network, nothing to do with serial transmission. Open another thread is you want.
    • Agree Agree x 1
  6. JayZ83

    JayZ83 New Member

    Joined:
    May 25, 2020
    Messages:
    23
    Balance:
    152Coins
    Ratings:
    +5 / 0 / -0
    My Motion Simulator:
    Arduino
    Hi .
    Just download with the UDP_receiver.
    But how can we setup the simtool so then it can listen to my UDP broadcast ?

    tks
  7. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    436
    Location:
    FRANCE
    Balance:
    5,963Coins
    Ratings:
    +563 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    Just send the UDP data you previoulsy recorded to the port the plugin listens to.
    Of course you need to send data matching what the plugin expects.
    • Like Like x 1
  8. JayZ83

    JayZ83 New Member

    Joined:
    May 25, 2020
    Messages:
    23
    Balance:
    152Coins
    Ratings:
    +5 / 0 / -0
    My Motion Simulator:
    Arduino
    lol.
    Thank you Vthinsel.
    Currently still waiting for admin assistant to purchase plugin package.

    There will be all from your UDP plugin : )

    tks
  9. Map63Vette

    Map63Vette Member

    Joined:
    May 19, 2016
    Messages:
    127
    Occupation:
    Mechanical Engineer
    Location:
    Lawrence, KS
    Balance:
    430Coins
    Ratings:
    +31 / 0 / -0
    @vthinsel I know this is a pretty old thread, but hoping you might still be around. Did you have to have the game running in the background for SimTools to pick up anything from the UDP_Send functions? I've been trying to modify an old plugin someone created to work with a different telemetry mod for a specific game and I managed to get a log file from the UDP_Receive script you wrote, but I'm not getting any data streaming into SimTools. I've tried running both the game itself and the UDP_Send script, but I'm wondering how SimTools knows what plugin it needs to be using at any given point. I assume it watches for the process associated with the plugin to be active to know which plugin code to use (the game manager bar goes from green to blue when it see is). If I just run the UDP_Send script with nothing else running I'm guessing SimTools wouldn't see anything as it doesn't know how to interpret any input at that point. Just trying to narrow down where my issue is right now. I think I got my plugin modified to parse the new telemetry stream I have, but I'm not sure I'm actually getting the packets into SimTools for whatever reason. Your send script makes it much easier to debug than constantly launching the game over and over again (especially since it's a VR game), but I'm thinking I still at least need it to run in the background and was hoping to get some confirmation on that so it's one less thing to rule out as a possible issue.
  10. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    436
    Location:
    FRANCE
    Balance:
    5,963Coins
    Ratings:
    +563 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    Hello,
    No , the original game is not needed at all. Thats the beauty of the record/playabck UDP tools. It allowed me to develop plugins without having the game, just captures that were sent to me.
    For simtools to work, the plugin has to be started manually though. Or you can trick it by having a notepad.exe renamed to the expected name by the plugin.
    The plugin tester is to be used before simtools anyway, it makes things easier.
    • Informative Informative x 1
  11. Map63Vette

    Map63Vette Member

    Joined:
    May 19, 2016
    Messages:
    127
    Occupation:
    Mechanical Engineer
    Location:
    Lawrence, KS
    Balance:
    430Coins
    Ratings:
    +31 / 0 / -0
    Okay, I guess "starting the plugin" is mostly what I was getting at. I was thinking I needed the game to be running for the plugin to start. Is there some kind of plugin tester outside of just running SimTools and seeing if the virtual axis and tuning center values change when it's getting sent new data? That's more or less the stage I'm at now. I have a telemetry mod that is actively sending data and a plugin that I believe is parsing data correctly (I have tested the functions in the plugin in a different app and they appear to split up values correct at least), but the two don't seem to be talking to each other.

    I'm a little confused on the UDP setup as I found another UDP send/receive tool that works kind of like a terminal program. The weird part with it is that it doesn't seem to recognize when your UDP_Send script is running, but if I run your UDP_Send script in one window and your UDP_Receive script in another everything works fine, so not sure why the other program doesn't see a stream happening.
  12. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    436
    Location:
    FRANCE
    Balance:
    5,963Coins
    Ratings:
    +563 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
  13. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    436
    Location:
    FRANCE
    Balance:
    5,963Coins
    Ratings:
    +563 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
  14. Map63Vette

    Map63Vette Member

    Joined:
    May 19, 2016
    Messages:
    127
    Occupation:
    Mechanical Engineer
    Location:
    Lawrence, KS
    Balance:
    430Coins
    Ratings:
    +31 / 0 / -0
    Ah, perfect, thanks! I think that plugin tester is exactly what I was looking for. Also, good grief they are already up to 3.0? They need to update the sticky on plugin development. I started trying to adapt the plugin I found to work with my new telemetry using a the 1.0 demo plugin and couldn't get it to work only to find out the issue was I needed to be using the 2.0 stuff. Now I'm wondering if my problem is that I need the 3.0 version...
  15. Map63Vette

    Map63Vette Member

    Joined:
    May 19, 2016
    Messages:
    127
    Occupation:
    Mechanical Engineer
    Location:
    Lawrence, KS
    Balance:
    430Coins
    Ratings:
    +31 / 0 / -0
    Well, guess I may have spoken too soon. V3 appears to be in the beta stage, and that plugin tester only seems to work with v3 series plugins. I am still running v2 and the plugin tester doesn't acknowledge my v2 plugin as valid, though the plugin validator that comes with the sample files does, it just doesn't have any output. Don't suppose anyone wants to backport the plugin tester to work with earlier versions?