PySimpleDX不知道自己的类

2024-04-26 01:31:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试让这个模块工作,但由于某些原因,它似乎不知道自己的类

这是我的密码:

    import pysimpledmx

    mydmx = pysimpledmx.DMXConnection(3)

这是我需要从PySimpleDX获取的代码:

    class DMXConnection(object):
      def __init__(self, comport = None):
        '''
        On Windows, the only argument is the port number. On *nix, it's the path to the serial device.
        For example:
            DMXConnection(4)              # Windows
            DMXConnection('/dev/tty2')    # Linux
            DMXConnection("/dev/ttyUSB0") # Linux
        '''
        self.dmx_frame = [0] * DMX_SIZE
        try:
          self.com = serial.Serial(comport, baudrate = COM_BAUD, timeout = COM_TIMEOUT)
        except:
          com_name = 'COM%s' % (comport + 1) if type(comport) == int else comport
          print "Could not open device %s. Quitting application." % com_name
          sys.exit(0)

        print "Opened %s." % (self.com.portstr)

要使用DMXConnection时出现的错误:

AttributeError: module 'pysimpledmx' has no attribute 'DMXConnection'

但如您所见,DMXConnection是pysimpledmx的一个属性。 我试着用PIP重新安装模块,但是没有成功。你知道吗


Tags: 模块thenamedevselfcomonlinux