2012-01-29 56 views
2

我正在使用激光切割器/雕刻机,这是Lasersaur开源激光切割机/雕刻机项目的一部分。我完成了硬件构建,没有意识到涉及到一些软件编程,在这种情况下是Python。我对Python一无所知,我有什么编码体验是在C#中从头开始构建一个定制的CMS。在Python 2.7.2中设置端口以与Arduino Uno配合使用

这是我的设置

电脑:东芝Satellite A-105

操作系统:Windows XP,SP3

代码:Python 2.7版

开发板:Arduino的乌诺

Arduino客户与Uno主板通话良好,所有的测试和上传工作。使用Arduino网站的入门指南,我可以设置一个COM端口供COM7使用,在这种情况下。问题是,当我运行的Python GUI和编译由Lasersaur提供我得到这个错误代码:

Traceback (most recent call last): 
    File "C:\LASERSAUR\lasersaur_Grbl\stefanix-LasaurGrbl-dac1a86\flash.py", line 128, in <module> 
    devices = os.listdir("/dev") 
WindowsError: [Error 3] The system cannot find the path specified: '/dev/*.*' 

在Lasersaur的人说,我需要设置的COM端口中的代码。我只是不知道自己做了些什么,或者提出了正确的问题。大量的阅读后然而,在我盯着屏幕,我相当肯定,我需要在这里设置端口:

## define serial port 
## 
if len(sys.argv) == 2: 
    # (1) get the serial device from the argument list 
    SERIAL_PORT = sys.argv[1] 
    print "Using serial device '"+ SERIAL_PORT +"' from command line." 
else:  
    if os.path.isfile(CONFIG_FILE): 
     # (2) get the serial device from the config file 
     fp = open(CONFIG_FILE) 
     line = fp.readline().strip() 
     if len(line) > 3: 
      SERIAL_PORT = line 
      print "Using serial device '"+ SERIAL_PORT +"' from '" + CONFIG_FILE + "'." 



if not SERIAL_PORT: 
    # (3) try best guess the serial device if on linux or osx 
    devices = os.listdir("/dev") 
    for device in devices: 
     if device[:len(GUESS_PPREFIX)] == GUESS_PPREFIX: 
      SERIAL_PORT = "/dev/" + device 
      print "Using serial device '"+ SERIAL_PORT +"' by best guess." 
      break 

我相当肯定,这将是一个额头拍打的答案,当我看到它。但任何帮助,将不胜感激。请让我知道你是否需要更多的细节。

V/R
K.澳元

+0

替换它 “'WindowsError:[错误3]系统无法找到指定的路径: '的/ dev /*.*''”。 '/ dev'是一个Unix路径。你在Windows上运行。 – Johnsyweb 2012-01-29 02:06:44

+0

你用什么命令行参数来启动这个脚本?它看起来像传递给脚本的任何参数(如果有的话)都没有被读取,python跳转到较低的代码块。 – 2012-01-29 02:43:51

回答

0

你传递任何参数,当您运行命令行这个脚本?这好像你不是。在命令行 试试这个:

C:\>python flash.py COM7 

如果仍然无法正常工作(或者是你一直以来的做什么),那么你可能会更好过把#'s在每行前在代码你张贴以上,并用

SERIAL_PORT = "COM7" 
+0

谢谢,这工作得很好!我将 SERIAL_PORT =“COM3” 置于 import os,sys 正下方的代码的顶部,并且再次位于平台代码块的下方,错误消失。 ...现在我有一个新的。但它的文件调用,所以我认为我可以修复它。 – user1175917 2012-01-29 07:11:06