'Python: read and send via serial interface from Notebook to Notebook
Hi guys I would like to receive and send data via a USB interface. My idea is simple: I have two Notebooks wired by using USB. On the first notebook1, the software: "serial monitor" is running for reading the data protocol. I would like to send messages with my Python program(notebook2).
The next step i would like to recive messages from the notebook1. The reciving massages should be saved in text file by python
Example :
(Python Program)notebook2 ----------------USB cable--------------------notebook1 (Serial Monitor for read/send)
should send a message (ABC) should recive the message (ABC)
after that the next step:
should read message (CBA) should send message (CBA)
print(_recived_message_)
Code here i got:
import serial.tools.list_ports as port_list
import serial
import time
ports = list(port_list.comports())
for p in ports:
print (p)
s = serial.Serial('COM6')
res = s.read()
print(res)
serialString = ""
while 1:
if serialPort.in_waiting > 0:
serialString = serialPort.readline()
try:
print(serialString.decode("Ascii"))
except:
pass
Output:
C:\Users\user\anaconda3\envs\ReadUSB\python.exe C:/Users/user/PycharmProjects/ReadUSB/main.py
COM6 - Prolific USB-to-Serial Comm Port (COM6)
i hope you guys can help me out
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
