我对python完全不熟悉。我正在使用python 3.4.3并且我一直在尝试将数据传输到usb到LED驱动电路。我想调制到达usb端口的数据。我的系统中安装了USB转串口转换器。任何人都可以建议相同的程序代码。我试过的程序是
import serial
ser=serial.Serial("/dev/ttyUSB0", 115200)
ser.open()
ser.isOpen()
print ('Enter your commands below.\r\nInsert "exit" to leave the application.')
我正在使用64位操作系统的MS Windows 8.1。
我使用从https://pypi.python.org/pypi/pyserial.The下载的pyserial-2.7.win32_py3k.exe安装了串口模块错误信息
Traceback (most recent call last):
File "C:/Users/shamsu/Desktop/ss.py", line 10, in <module>
bytesize=serial.SEVENBITS
File "C:\Python34\lib\site-packages\serial\serialwin32.py", line 38, in __init__
SerialBase.__init__(self, *args, **kwargs)
File "C:\Python34\lib\site-packages\serial\serialutil.py", line 282, in __init__
self.open()
File "C:\Python34\lib\site-packages\serial\serialwin32.py", line 66, in open
raise SerialException("could not open port %r: %r" % (self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port '/dev/ttyUSB1': FileNotFoundError(2, 'The system cannot find the path specified.', None, 3)
我是否安装了32位串行模块?我的系统使用64位Windows 8.1操作系统。
我不知道这个程序对我的应用程序是否正确。任何人都可以帮助我吗?
答案 0 :(得分:0)
在Windows上更改为
ser = serial.Serial('COM1', 9600) or ser = serial.Serial(port='COM4')
在课堂上使用可以像
那样self.ser=serial.Serial(port='\\.\COM1', baudrate=9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1)
打开图像,可以使用PIL或opencv 例如How do I convert a numpy array to (and display) an image?
使用opencv2和numpy
import cv2
import numpy as np
image = cv2.imread("image.png") # or full path to image
print(image.size)
print(image.shape)
print image[0,0]
ser.write(image[0,0])
Do the serial wirting in a loop and iterate across the image. Or first convert it to a black and white image then send it.
使用pyserial发送文件 Using Pyserial to send a file?
如何使用pyserial读取数据 How to read data from pyserial incrementally?
这应该足以让你开始