如何在 Cygwin 中使用 COM 和 USB 端口? [英] How can I use COM and USB ports within Cygwin?

查看:79
本文介绍了如何在 Cygwin 中使用 COM 和 USB 端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Python 脚本从我的 Arduino 板发送/接收数据.我想使用 Python 和它的 pySerial 模块来做这件事,这似乎符合我的需要.所以我在 cygwin(后面是 windows XP)中安装了 Python 和 pySerial.

Python 脚本相当简单:

$ cat example.py#print使用python测试我的COM26端口"导入序列ser = serial.Serial()ser.baudrate = 9600端口号 = 26服务人员ser.open()ser.isOpen()

但是在运行时我收到以下错误.

$ python example.py回溯(最近一次调用最后一次):文件example.py",第 9 行,在 <module> 中ser.open()文件/usr/lib/python2.5/site-packages/serial/serialposix.py",第276行,打开raise SerialException("无法打开端口 %s: %s" % (self._port, msg))serial.serialutil.SerialException:无法打开端口 26:[Errno 2] 没有这样的文件或目录:'/dev/com27'

<块引用>

无法打开端口 26:[Errno 2] 没有那个文件或目录:'/dev/com27'

我如何知道我的 Arduino 已连接到端口 COM27?

嗯,很简单.Arduino IDE 是这样说的,我可以使用该端口从 IDE 的串行端口监视器工具发送和接收数据.此外,我也设法让超级终端使用该端口工作.

然而,Cygwin 似乎不知道这样的 USB 和 COM 端口:

$ ls -lah/dev总共 4,0K...fd ->/proc/self/fd队列shm标准错误 ->/proc/self/fd/2标准输入 ->/proc/self/fd/0标准输出 ->/proc/self/fd/1

应该提到的是,我在没有经典串行 COM 端口,只有 USB 端口的戴尔笔记本电脑上运行它.(所以我想这很正常,例如 /dev/com1 不存在.)

我不知道我问得是否正确,但我的问题是:我如何配置 Cygwin 以便它意识到这个 COM27 端口?

解决方案

如果超级终端可以访问它,那么它就安装为虚拟 COM 端口".Cygwin 将允许您以 /dev/ttyS26(Windows 称为 COM27)的形式访问它.在收到 CR 之前,您可能仍然遇到输入阻塞的问题——我有.(试图解决那个,我是如何找到这个的.)

I want to send/receive data from my Arduino board with a Python script. I would like to do it using Python and its pySerial module which seems to fit my needs. So I installed Python and pySerial within cygwin (windows XP behind).

The Python script is rather straightforward:

$ cat example.py

#print "testing my COM26 port using python"

import serial
ser = serial.Serial()
ser.baudrate = 9600
ser.port = 26
ser
ser.open()
ser.isOpen()

However at runtime I get the following error.

$ python example.py
Traceback (most recent call last):
  File "example.py", line 9, in <module>
    ser.open()
  File "/usr/lib/python2.5/site-packages/serial/serialposix.py", line 276, in open
    raise SerialException("could not open port %s: %s" % (self._port, msg))
serial.serialutil.SerialException: could not open port 26: [Errno 2] No such file or directory: '/dev/com27'

Could not open port 26: [Errno 2] No such file or directory: '/dev/com27'

How do I know my Arduino is connected to port COM27?

Well, it's simple. The Arduino IDE says so, I can send and receive data from the Serial Port Monitor tool for the IDE using that port. Besides, I managed to get the hyperterminal working using that port too.

However, it seems Cygwin is not aware of such USB and COM ports:

$ ls -lah /dev
total 4,0K
.
..
fd -> /proc/self/fd
mqueue
shm
stderr -> /proc/self/fd/2
stdin -> /proc/self/fd/0
stdout -> /proc/self/fd/1

It should be mentioned that I am running this on a Dell laptop that has no classic serial COM port, just USB ports. (So I guess it's plain normal for instance that /dev/com1 does not exist.)

I don't know if I'm asking correctly, but my question is: how can I configure Cygwin so that it becomes aware of this COM27 port?

解决方案

If Hyperterminal can access it, then it's installed as a "virtual COM port". Cygwin will let you access it as /dev/ttyS26 (called COM27 by Windows). You may still have an issue with the input blocking until a CR is received--I do. (Trying to solve that, is how I found this.)

这篇关于如何在 Cygwin 中使用 COM 和 USB 端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆