Open Xing-Fax opened 2 years ago
Hi xingchuanzhen, from the screenshots it looks like you've got a problem with the USB HID library on windows. I've got no windows in reach to test this (using Linux only), but from what I can see is that the HID library on windows also uses
ctypes.create_string_buffer
that call fails on your setup du to DLL missing or something similar. I've updated the docs that Windows is not tested. If you find a solution how to setup the HID library on Windows please let me know.
Sorry Leif
ok, although it didn't solve the problem successfully, but still thanks for the answer
hello ljakob
When I make changes to the code as follows(two changes)
After the program runs, my UT61E+ will beep twice, then the screen backlight will be turned on, and the following error will appear
I'm not sure if there is something wrong with my modification,But it seems to be able to establish communication with the UT61E+, such as lighting the backlight It is also possible that the code "from ctypes import *" is not suitable
After getting through the setup, installing everything needed and changing the ctypes import, I get the same error: The received bytes dont match what we would expect, since it is not AB CD ..). Here is my work in progress:
getName: this is calling _readResponse: and then I print "x" byte by byte: 0x1 0xab 0x7 0x20 0x20 0x36 0x33 0x32 0x1 0x7 0x30 0x30 0x30 0x3 0x99 0x0 0x0 0x0 0x0
I dont know what to expect from "getName", so the "name", but here is what I get like this (only the first byte array displayed:
measure = dmm.takeMeasurement() utname = dmm.getName()
and then print via:
x = self.dev.read(19) print("read x:", flush = True) for i in x: print(hex(i), flush = True)
takeMeasurement: _readResponse: read x: 0x1 **0xab** 0x7 0x20 0x20 0x36 0x33 0x32 0x1 0x7 0x30 0x30 0x30 0x3 0x99 0x0 0x0 0x0 0x0
Note the 0xAB at position 1 as well as the presumed length of 1 from HID at position 0. All the following byte arrays have, at position 1, the correct values. So when I go through all of the byte arrays and take index 1, this is what I get: AB CD 10 06 35 20 20 20 4F 2E 4C 20 03 00 30 34 30 03 A3
Here, the 7 bytes "20 20 20 4F 2E 4C 20" from hex to ACSII are " O.L ", which is exactly what is on the display.
So the issue is:
Why does HID only read 1 byte at a time?
Where do all the other bytes after index 1 come from?
Also, note this documentation here, which is where I (also) got the info that those 7 bytes are the display data.
AB CD 03 5E 01 D9 = code for get Measurement
That seems to be correct for both the UT61E+ and UT161B.
完成设置、安装所需的一切并更改 ctypes 导入后,我收到相同的错误:收到的字节与我们预期的不匹配,因为它不是 AB CD..)。这是我正在进行的工作:
getName: this is calling _readResponse: and then I print "x" byte by byte: 0x1 0xab 0x7 0x20 0x20 0x36 0x33 0x32 0x1 0x7 0x30 0x30 0x30 0x3 0x99 0x0 0x0 0x0 0x0
我不知道从“getName”中得到什么,所以“名称”,但这是我得到的(只显示第一个字节数组:
measure = dmm.takeMeasurement() utname = dmm.getName()
然后通过以下方式打印:
x = self.dev.read(19) print("read x:", flush = True) for i in x: print(hex(i), flush = True)
takeMeasurement: _readResponse: read x: 0x1 **0xab** 0x7 0x20 0x20 0x36 0x33 0x32 0x1 0x7 0x30 0x30 0x30 0x3 0x99 0x0 0x0 0x0 0x0
请注意位置 0 处的1xAB以及位置 1 处 HID 的假定长度 0。以下所有字节数组在第 1 位具有正确的值。因此,当我遍历所有字节数组并获取索引 1 时,这就是我得到的: AB CD 10 06 35 20 20 20 4F 2E 4C 20 03 00 30 34 30 03 A3
在这里,从十六进制到 ACSII 的 7 个字节“20 20 20 4F 2E 4C 20”是“O.L”,这正是显示屏上的内容。所以问题是:为什么 HID 一次只读取 1 个字节?索引 1 之后的所有其他字节从何而来?另外,请在此处注意此文档。
AB CD 03 5E 01 D9 = code for get Measurement
How to use your library?
How to use your library? Sorry, I can't help you for the time being, because this project is a project I wrote a long time ago, but the codes in the project are all correct (verified), and now the UT61E+ device is not with me, so I can't answer for you for the time being ,Thanks
Okay, got it working. As said before, it always reads 1 Byte of payload (1. Byte from HID was always 0x01, 2. Byte payload).
So this is what needs to change in ut61eplus.py
, starting at line 342. Note that I read 19x2 Bytes in a for-loop.
def _readResponse(self) -> bytes:
# pylint: disable=unsupported-assignment-operation,unsubscriptable-object
state = 0 # 0=init 1=0xAB received 2=0xCD received 3=we have length
data = bytes()
buf: bytes = None
index: int = None
sum: int = 0
numbytes = 19 # always read 19 Bytes https://www.mikrocontroller.net/attachment/556567/UT161B.pdf
while True:
# read data in bytes of 2 (1. is HID lenght, which always ready 1, so only one more byte after that)
for i in range(0, numbytes): # 19 byte-pairs in total to read
bytes_read = self.dev.read(2)
data += bytes_read[1:] # discard the HID-lenght byte, we only need the 2. Byte with data
# parse data
b: int
for b in data:
hello ljakob i might need some help from you
I don't know what's going on, but it doesn't work correctly on my device, the error is as follows