bencorrado / pmsensor

Library to read data from particulate matter sensors
MIT License
20 stars 15 forks source link

Error reading from mh_z19 #4

Closed remimikalsen closed 7 years ago

remimikalsen commented 7 years ago

Hi,

running on VirtualBox Ubuntu 16.04 LTS 32 bit VM (Windows 10 host) I share a USB-Serial converter into the virtual machine.

The device itself appears like this: $ sudo lsusb Bus 001 Device 017: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter

And is apparently present at: /dev/ttyUSB0

I get the following error in python when I run the co2_demo.py (where I point it to ttyUSB0 instead of the example device from the original file):

Traceback (most recent call last): File "co2_demo.py", line 10, in ppm = co2sensor.read_mh_z19("/dev/ttyUSB0") File "/srv/co2/pmsensor/pmsensor/co2sensor.py", line 16, in read_mh_z19 result = read_mh_z19_with_temperature(serial_device) File "/srv/co2/pmsensor/pmsensor/co2sensor.py", line 47, in read_mh_z19_with_temperature if ser.inWaiting() > 0: File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 538, in inWaiting return self.in_waiting File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 464, in in_waiting s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str) IOError: [Errno 5] Input/output error

The kernel log does not contain any errors, but the syslog has the following relevant events: usb 1-2: new full-speed USB device number 17 using ohci-pci usb 1-2: New USB device found, idVendor=1a86, idProduct=7523 usb 1-2: New USB device strings: Mfr=0, Product=2, SerialNumber=0 usb 1-2: Product: USB2.0-Serial ch341 1-2:1.0: ch341-uart converter detected usb 1-2: ch341-uart converter now attached to ttyUSB0 usb 1-2: USB disconnect, device number 17 usb 1-2: ch341_read_int_callback - usb_submit_urb failed: -19 ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0 ch341 1-2:1.0: device disconnected

Is this a config issue, a software issue, missing package issue or a driver issue?

Any ideas about what is wrong?

Best regards, Remi

remimikalsen commented 7 years ago

I'm updating the issue as I had some progress.

I updated my host computer drivers for the chipset (http://www.wch.cn/download/CH341SER_EXE.html) and installed the Oracle VM VirtualBox Extension Pack to be able to get USB2.0 support on devices shared from the host to the VM.

Now I just receive a None value when reading from the device. The next time I try to read values the device isn't available (input/output error). Same thing happens if I try to cat the device.

I assume I'm having some other level issues and that nothing is wrong with the software itself.