MDB Products
Released
Getting Started
MDB Developers' Playground - Code Samples and Examples
Title
Message
Create new category
What is the title of your new category?
Edit page index title
What is the title of the page index?
Edit category
What is the new title of your category?
Edit link
What is the new title and URL of your link?
Data Sniffer
Copy Markdown
Open in ChatGPT
Open in Claude
This program is to sniff all the data from the MDB Bus using our API. This program saves the data on a text file that you can use later for analyses.
Python
x
import serialimport sysimport datetimeimport timeif len( sys.argv ) > 1 : port_name = sys.argv[1] #Open serial port serialPort = serial.Serial( port = port_name, baudrate=115200, bytesize=8, timeout=0.1, stopbits=serial.STOPBITS_ONE ); last_time = 0 current_time = datetime.datetime.now() #get initial date for record file name #create initial file name_current_file = "REC " if(current_time.day < 10): name_current_file += "0" name_current_file += str(current_time.day) name_current_file += "-" if(current_time.month < 10): name_current_file += "0" name_current_file += str(current_time.month) name_current_file += "-" name_current_file += str(current_time.year) name_current_file += ".txt" f = open(name_current_file, "a") serialPort.write(bytearray("X,1\n\r",'ascii')) #Start sniffer while 1: #main loop try: if last_time != current_time: #check date to create new record file if new day close current record file and create new record file f.close() last_time = current_time name_current_file = "REC " if(current_time.day < 10): name_current_file += "0" name_current_file += str(current_time.day) name_current_file += "-" if(current_time.month < 10): name_current_file += "0" name_current_file += str(current_time.month) name_current_file += "-" name_current_file += str(current_time.year) name_current_file += ".txt" f = open(name_current_file, "a") current_time = datetime.datetime.now() #get updated date line = serialPort.readline() #serial read if line: #save data f.write(line.decode('utf-8')) time.sleep(0.1) except KeyboardInterrupt: raise SystemExit else : print("Please, enter valid serial port")To execute the program, just copy the code above to a file "sniffer.py" or download it from here and run it like shown below.
Bash
sudo python3 sniffer.py <serial_port>Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard
Last updated on
Next to read:
Go Lang Sample(C) 2024 Qibixx AG - contact us with any questions: info@qibixx.com
Discard Changes
Do you want to discard your current changes and overwrite with the template?
Archive Synced Block
Message
Create new Template
What is this template's title?
Delete Template
Message