torfbolt / PyDAQFlex

Python implementation of Measurement Computing's DAQFlex command framework
15 stars 14 forks source link

USB TEMP #8

Open OskarCis opened 8 years ago

OskarCis commented 8 years ago

Hi I am new in Python and PyDAQFlex, I will it with a USB TEMP card of MCC. But when I assign the name of card, I find the issue to see below.

import daqflex dev=daqflex.USB_TEMP()

Traceback (most recent call last): File "<pyshell#1>", line 1, in dev=daqflex.USB_TEMP() AttributeError: 'module' object has no attribute 'USB_TEMP'

somebody could help me?

dassishot commented 8 years ago

Hello, how are you? I did all use of DAQFLEX with C #, because some features were ready with the API. If this is interesting to you please contact me. Francisco de Assis

ixjlyons commented 8 years ago

PyDAQFlex doesn't have a USB_TEMP class, so you'll have to define one. It's should be pretty simple -- see one of the existing device classes for an example.

OskarCis commented 8 years ago

Thanks to both, I will try to write the clases for USB_TEMP. I understand that max _counts =0x0FFF for all class, but What about with the id_product? Is it a row?

OskarCis commented 8 years ago

Thanks to both, I will try to write the class for USB_TEMP. I understand that max _counts =0x0FFF for all class, but What about with the id_product? Is it a row?

ixjlyons commented 8 years ago

The id_product attribute corresponds to the device's idProduct device descriptor. It's something you'd have to determine with the device plugged in. On Linux, you can use lsusb -v to print out this information. I'm not very familiar with other systems, but apparently USBView does something similar for Windows.

OskarCis commented 8 years ago

Hi ixjlyons, I am using raspbian, I already have defined a USB_TEMP class, but now appears a new issue:

import daqflex dev=daqflex.USB_TEMP()

Traceback (most recent call last): File "<pyshell#1>", line 1, in dev=daqflex.USB_TEMP() File "daqflex/devices.py", line 70, in init self.dev.set_configuration() File "build/bdist.linux-armv7l/egg/usb/core.py", line 869, in set_configuration self._ctx.managed_set_configuration(self, configuration) File "build/bdist.linux-armv7l/egg/usb/core.py", line 102, in wrapper return f(self, _args, *_kwargs) File "build/bdist.linux-armv7l/egg/usb/core.py", line 148, in managed_set_configuration self.backend.set_configuration(self.handle, cfg.bConfigurationValue) File "build/bdist.linux-armv7l/egg/usb/backend/libusb1.py", line 794, in set_configuration _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value)) File "build/bdist.linux-armv7l/egg/usb/backend/libusb1.py", line 595, in _check raise USBError(_strerror(ret), ret, _libusb_errno[ret]) USBError: [Errno 16] Resource busy

I attached you my device.py I dont know if I have a mistake. Thanks for your help.

ixjlyons commented 8 years ago

This may point to an actual bug in PyDAQFlex, but I'm not sure.

The error comes from pyusb and it may be indicating that a kernel driver is holding on to the device. Reference this issue for what seems to be a similar problem that several people run into.

Could you try the following code and see if it generates an error? It just sets up the device like PyDAQFlex does but detaches the kernel driver if it is active. Replace id_product with your device's idProduct:

import usb

dev = usb.core.find(idVendor=0x09db, idProduct=id_product)
if dev.is_kernel_driver_active(0):
    dev.detach_kernel_driver(0)
dev.set_configuration()

If this works without error, the check should be added before line 70 of devices.py.

OskarCis commented 8 years ago

Hi ixjLyons, I had written before because couldn´t try your recommendations. I tried it yesterday and worked. The raspberry pi can setup a USB_Temp device, but when I try to sent a message appears a new issue: This is my code:

import daqflex d=daqflex.USB_TEMP() d.find_serial_numbers() [u' 01923E6E'] d.send_message("AI{0]:VALUE/DEGC") Traceback (most recent call last): File "<pyshell#4>", line1, in d.send_message("?AI{0]:VALUE/DEGC") File "daqflex/devices.py", line 125, in send_message raise IOError("send failed, possibly wrong command?") IOError:Send failed, possibly wrong command?

Do you know whats the problem?

Regards

ixjlyons commented 8 years ago

@OskarCis: It looks like you've got a typo:

d.send_message("?AI{0]:VALUE/DEGC")

It should read:

d.send_message("?AI{0}:VALUE/DEGC")
OskarCis commented 8 years ago

I’m sorry, when I typed the past code, I copied this with mistake. Thanks for correcting me. However although correctly type the code still see the error. I attached the picture of my raspberry’s screensaver for you. This is my code:

import daqflex dev=daqflex.USB_TEMP() dev.find_serial_numbers() [u'01923E6E'] dev.send_message("?AI{0}:VALUE/DEGC")

Traceback (most recent call last): File "<pyshell#3>", line 1, in dev.send_message("?AI{0}:VALUE/DEGC") File "daqflex/devices.py", line 125, in send_message raise IOError("Send failed, possibly wrong command?") IOError: Send failed, possibly wrong command?

Thank you for your help!

sample

ixjlyons commented 8 years ago

@OskarCis: Sorry, this is pretty much the end of my ability to help, since I don't have the hardware. Here are a couple things though: