Arduino-pyFirmata-Python windows错误(5,访问被拒绝)

时间:2015-05-30 12:16:09

标签: python arduino pyserial

早上好

我想使用<?php // It may take a whils to crawl a site ... set_time_limit(10000); // Inculde the phpcrawl-mainclass include("libs/PHPCrawler.class.php"); // Extend the class and override the handleDocumentInfo()-method class MyCrawler extends PHPCrawler { function handleDocumentInfo($DocInfo) { // Just detect linebreak for output ("\n" in CLI-mode, otherwise "<br>"). if (PHP_SAPI == "cli") $lb = "\n"; else $lb = "<br />"; // Print the URL and the HTTP-status-Code echo "Page requested: ".$DocInfo->url." (".$DocInfo->http_status_code.")".$lb; // Print the refering URL echo "Referer-page: ".$DocInfo->referer_url.$lb; // Print if the content of the document was be recieved or not if ($DocInfo->received == true) echo "Content received: ".$DocInfo->bytes_received." bytes".$lb; else echo "Content not received".$lb; // Now you should do something with the content of the actual // received page or file ($DocInfo->source), we skip it in this example echo $lb; flush(); } } // Now, create a instance of your class, define the behaviour // of the crawler (see class-reference for more options and details) // and start the crawling-process. $crawler = new MyCrawler(); // URL to crawl $crawler->setURL("www.php.net"); // Only receive content of files with content-type "text/html" $crawler->addContentTypeReceiveRule("#text/html#"); // Ignore links to pictures, dont even request pictures $crawler->addURLFilterRule("#\.(jpg|jpeg|gif|png)$# i"); // Store and send cookie-data like a browser does $crawler->enableCookieHandling(true); // Set the traffic-limit to 1 MB (in bytes, // for testing we dont want to "suck" the whole site) $crawler->setTrafficLimit(1000 * 1024); // Thats enough, now here we go $crawler->go(); // At the end, after the process is finished, we print a short // report (see method getProcessReport() for more information) $report = $crawler->getProcessReport(); if (PHP_SAPI == "cli") $lb = "\n"; else $lb = "<br />"; echo "Summary:".$lb; echo "Links followed: ".$report->links_followed.$lb; echo "Documents received: ".$report->files_received.$lb; echo "Bytes received: ".$report->bytes_received." bytes".$lb; echo "Process runtime: ".$report->process_runtime." sec".$lb; ?> 将我的Arduino电路板连接到电脑,但发生了一个奇怪的问题。前提:pyFirmata libpySerial已成功安装在我的计算机上。我有pyFirmatawindows 8.0 64 bit和USB端口的驱动程序工作正常(因为我可以将每个草图上传到Arduino)。

我想要运行的代码非常简单:

如果按下Arduino(连接到引脚4,被来自button的{​​{1}}配置为输入),则红色指示灯将闪烁,否则绿色指示灯将亮起。我用一个简单的功能让它们眨眼:

method.get_pin()

board在全局范围内定义为firmata library

所有联系人工作正常,因为我用from time import sleep def Blink(pin): board.digital(pin).write(1) sleep(1) board.digital(pin).write(0) sleep(1) 测试它们,我确信在开始python之前没有打开任何串行连接。

这是奇怪的事情:

如果我在python shell上编写每个命令,整个工作正常,LED闪烁正确!! 但是如果我在一个模块上写下所有命令然后运行它就会发出这个错误:

pyfirmata.Arduino('com3')

也就是说,它无法打开端口。我尝试了一些调试,但它没有帮助我。

如果我通过

检查端口的状态
firmata_test.exe

但如果我使用

"Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    board = pyfirmata.Arduino('com3')
  File "C:\Python27\lib\site-packages\pyfirmata\__init__.py", line 16, in __init__
    super(Arduino, self).__init__(*args, **kwargs)
  File "C:\Python27\lib\site-packages\pyfirmata\pyfirmata.py", line 89, in __init__
    self.sp = serial.Serial(port, baudrate, timeout=timeout)
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 38, in __init__
    SerialBase.__init__(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\serial\serialutil.py", line 282, in __init__
    self.open()
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 66, in open
    raise SerialException("could not open port %r: %r" % (self.portstr, ctypes.WinError()))
SerialException: could not open port 'com3': WindowsError(5, 'Access denied.')"

它会弹出同样的错误。

看看por = serial.Serial() por.port = 'com3' por.isOpen() >>False TX定期闪烁,所以我可以想象它正在向串口发送一些数据。如果我打开arduino应用程序它会告诉我端口正忙。我无法确定是否存在管理员许可问题,因为我以管理员身份运行py IDLE。即使我在管理员模式下从CMD运行脚本,错误仍然存​​在。

非常感谢你的每一个回答。

1 个答案:

答案 0 :(得分:2)

伙计们我解决了这个问题!我重启电脑然后(首先)我在管理模式下启动CMD并运行模块..现在它工作!不知道为什么,似乎直到现在我第一次没有管理员权限运行。之后,即使我在管理模式下打开CMD,错误仍然继续出现。

希望这可以对某人有所帮助。

谢谢。