pyserial serialwin32.py has attribute error

北慕城南 提交于 2019-12-01 14:13:16

To answer 1) Because this relies on the hardware available, it is perfectly possible that the test code worked in the environment it was written on, but doesn't work in your environment - may be quite likely if you are on Windows and this was written on Linux. The code uses port 0 - don't know how that maps to COM1 etc.

2) On Windows, COM ports used to have DOS names like COM1, COM2 - i.e. A string, not an int (they aren't like TCP/IP port numbers). More recently in Windows there is the \\.\COMnotanumber format which allows a more generic name, I've seen these used by a USB to serial converter. Having had a quick look at the source code of pyserial SerialBase in serialutil.py, it's a bit odd IMO, because AFAICT self.name only gets set when you use an explicit port setting by calling self.port(portname). You might want to try intializing the serial port instance with serport = Serial(0) then explicitly calling serport.port('COM1') (or whatever your port name is instead of COM1).

You may have the wrong version of serialwin32.py. I had the same error messages until I tried a different version. I am using 2.7 from here https://pypi.python.org/pypi/pyserial/2.7. Then I simply typed 'empl-client.py 8' and the error messages were gone. I also did not have the driver installed for the 'Embedded MotionApps' device. So, I found the eMPL_CDC.inf in the motion_driver_6.12 folder and installed it through device manager.

Now the problem I have is that the Embedded MotionApps device continuously connects and reconnects in Windows. Pygame is now running though but just sits there with a black screen. Invensense tell me that means it is connected and waiting for data.

It looks like there is data on the I2C bus and if the port would stay connected perhaps it might work. Though the data disappears from the bus when the port disconnects, so maybe the complete program is resetting. Actually there is a msp430_reset() function within the code and it does look like that is being called.

The possibility to use numbers as ports has been removed in pySerial 3.x. Use device names (strings) instead, e.g. "/dev/ttyS0", "COM4" etc.

Those numbers were not consistent across operating systems and sometimes did not even include all devices. You can use the serial.tools.list_port module to enumerate actually available serial ports on most operating systems.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!