I have this snippet of code which works fine on Windows and Mac OS X using Python 2.7.6. I am using the cython-hidapi intereface to read data from a Voltcraft VC870 power meter. To get the data, if first need to send a feature report to the device as thus:
buf = [0x00, 0x80, 0x25, 0x00, 0x00, 0x03]
res = hid.device().send_feature_report(buf);
On Windows 8.1 and Mac OS X Mavericks, this works fine and a non-negative value is returned. However, this same code on Linux returns a negative number. I believe this means the device did not understand the feature report as sent.
The code from hid (cython-hidapi) that is called is as follows:
def send_feature_report(self, buff):
'''Accept a list of integers (0-255) and send them to the device'''
# convert to bytes
if sys.version_info < (3, 0):
buff = ''.join(map(chr, buff))
else:
buff = bytes(buff)
cdef hid_device * c_hid = self._c_hid
cdef unsigned char* cbuff = buff # covert to c string
cdef size_t c_buff_len = len(buff)
cdef int result
with nogil:
result = hid_send_feature_report(c_hid, cbuff, c_buff_len)
return result
I am not very familiar with C types or byte level processing. I initially suspected that the line:
buff = ''.join(map(chr, buff))
was the culprit as chr(0x80) outputs out different values accross my systems. But I wonder if anyone can shed any more light as to what's wrong here and suggest a fix.