0

I am new to Pyserial, I'm trying to use it for communication between my computer and a microcontroller, I need to receive the data and put it into variables so that I can plot with those variables. Is there any way to do this? I have currently figured out reading data from input signals.

import serial
import sys
import Queue
import threading

ser = serial.Serial(port='COM6',timeout=None, baudrate= 57600)

# opening the port 'ser' that was just created to receive data

flag = ser.isOpen()

print flag

while 1:

    data = ser.read(1)

    n = ser.inWaiting()

    if n:

        data = data + ser.read(n)

    data = data.split()


    for item in data:

        item = str(item)

        sys.stdout.write(item + '\n')
4

1 回答 1

0

我正在这样做:在运行 UBuntu 的 AVR 和 Beagle 之间来回传输数据。

serial = serial.Serial("/dev/ttyO1", 波特率=9600)

然后以特定的波特率打开串行端口后,您只需要:

while True:
     while serial.inWaiting() > 0:
           inChar = serial.read() # Read a character inChar has that byte what is sent over the UART 

并发送到微控制器只需执行 serial.write("") 就是这样。但请确保在执行所有这些命令时串行线是 open()

于 2013-11-07T06:01:13.520 回答