Anyway, the fastest serial communication log is left in a file

Anyway, I want to keep a log of Serial communication from a device connected by USB right now. You can use it in such a case.

The environment is assumed to be Mac.

things to do

The language uses Python. Since pySerial is also used, let's install it with `$ pip install pyserial`.

The source is below

logger.py


import serial

com = serial.Serial('/dev/....')

while True:
    line = com.readline().strip().decode('utf-8')
    print(line)
    f = open('data.txt', 'a+')
    f.writelines(line)
    f.close()

com.close()

When you don't know the COM port

On Mac, you can check the list with the following command.

$ ls -l /dev/tty.usb*

Thank you for visiting us so far! We would appreciate it if you could comment on any improvements or unclear points.

Recommended Posts

Anyway, the fastest serial communication log is left in a file
What is the fastest way to create a reverse dictionary in python?
Check if the string is a number in python
When a file is placed in the shared folder of Raspberry Pi, the process is executed.
Get the file name in a folder using glob
[Sublime Text 2] Always execute a specific file in the project
Save the pystan model and results in a pickle file
[python] Change the image file name to a serial number
Change the standard output destination to a file in Python
[Note] Import of a file in the parent directory in Python
Is there a bias in the numbers that appear in the Fibonacci numbers?
The image is a slug
Output the key list included in S3 Bucket to a file
Process the contents of the file in order with a shell script
Play a sound in Python assuming that the keyboard is a piano keyboard
Check if the configuration file is read in an easy-to-understand manner
Why put a slice on the left side in the substitution formula
On Linux, the time stamp of a file is a little past.
Delete a particular character in Python if it is the last
Save the Pydrive authentication file in a different directory from the script
Read a file in Python with a relative path from the program
Read the config file in Go language! Introducing a simple sample
Get the formula in an excel file as a string in Python
[Golang] Check if a specific character string is included in the character string
Format the Git log and get the committed file name in csv format
Check if there is a specific symbol in the executable file and its dependent libraries (simplified version)
Count specific strings in a file
Save the binary file in Python
Is there a special in scipy? ??
Create a binary file in Python
The story of the "hole" in the file
Save a YAML-formatted file in PyYAML
Replace the directory name and the file name in the directory together with a Linux command.
What is the XX file at the root of a popular Python project?
A memo organized by renaming the file names in the folder with python
How to specify a .ui file in the dialog / widget GUI in PySide
Is the space replaced by a plus sign or% 20 in percent-encoding processing?
Test & Debug Tips: Create a file of the specified size in Python
View the full path (absolute path) of a file in a directory in Linux Bash
I made a program to check the size of a file in Python
I created a script to check if English is entered in the specified position of the JSON file in Python.