问题描述
我想设置一个Prolite LED标志,以显示来自apache日志和其他有趣统计信息的滚动搜索查询.问题是,我的G5没有串行端口,因此我必须使用USB来串行加密狗.它显示为/dev/cu.usbserial和/dev/tty.usbserial.
I have a Prolite LED sign that I like to set up to show scrolling search queries from a apache logs and other fun statistics. The problem is, my G5 does not have a serial port, so I have to use a usb to serial dongle. It shows up as /dev/cu.usbserial and /dev/tty.usbserial .
当我这样做时,一切似乎都是笨拙的:
When i do this everything seems to be hunky-dory:
stty -f /dev/cu.usbserial
speed 9600 baud;
lflags: -icanon -isig -iexten -echo
iflags: -icrnl -ixon -ixany -imaxbel -brkint
oflags: -opost -onlcr -oxtabs
cflags: cs8 -parenb
当我使用串行端口工具与之交谈时,一切也都可以使用
Everything also works when I use the serial port tool to talk to it.
如果我在上面提到的串行端口工具上运行这段代码,那么一切都可以.但是,一旦我断开工具的连接,连接就会丢失.
If I run this piece of code while the above mentioned serial port tool, everthing also works. But as soon as I disconnect the tool the connection gets lost.
#!/usr/bin/python
import serial
ser = serial.Serial('/dev/cu.usbserial', 9600, timeout=10)
ser.write("<ID01><PA> \r\n")
read_chars = ser.read(20)
print read_chars
ser.close()
所以问题是,在没有串行端口工具的情况下开始与串行端口通信我需要执行哪些操作?这是权限问题吗?另外,/dev/cu.usbserial和/dev/tty.usbserial有什么区别?
So the question is, what magicks do I need to perform to start talking to the serial port without the serial port tool? Is that a permissions problem? Also, what's the difference between /dev/cu.usbserial and /dev/tty.usbserial?
没有,没有序列号.事实是,即使使用sudo运行python脚本,问题仍然存在,而且如果我在提到的gui工具中打开连接,唯一的问题就解决了.
Nope, no serial numbers. The thing is, the problem persists even with sudo-running the python script, and the only thing that makes it go through if I open the connection in the gui tool that I mentioned.
推荐答案
/dev/cu.xxxxx
是标注"设备,它是您与串行设备建立连接并开始与之交谈时所使用的设备. /dev/tty.xxxxx
是"dialin"设备,用于监视端口的传入呼叫,例如:传真侦听器.
/dev/cu.xxxxx
is the "callout" device, it's what you use when you establish a connection to the serial device and start talking to it. /dev/tty.xxxxx
is the "dialin" device, used for monitoring a port for incoming calls for e.g. a fax listener.
这篇关于以编程方式与OS X或Linux中的串行端口通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!