-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathread.py
executable file
·49 lines (40 loc) · 1.06 KB
/
read.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python3
import sys
import time
import logging
import usb
log = logging.getLogger(__name__)
d = usb.core.find(idVendor=0x0fe7, idProduct=0x4001)
if d is None:
log.error("No Mitutoyo device matching 0fe7:4001 found")
sys.exit(1)
if d.is_kernel_driver_active(0):
d.detach_kernel_driver(0)
#except usb.USBError as e:
# pass # kernel driver is already detached
# #log.warning(str(e))
d.reset()
d.set_configuration(1)
c = d.get_active_configuration()
epin = d.get_active_configuration().interfaces()[0].endpoints()[0]
bmRequestType=0x40 # Vendor Host-to-Device
bRequest=0x01
wValue=0xA5A5
wIndex=0
d.ctrl_transfer(bmRequestType, bRequest, wValue, wIndex)
bmRequestType=0xC0 # Vendor Device-to-Host
bRequest=0x02
wValue=0
wIndex=0
length=1
res1 = d.ctrl_transfer(bmRequestType, bRequest, wValue, wIndex, length)
log.debug("Device Vendor resp: {}".format(res1))
bmRequestType=0x40 #0b01000000
bRequest=0x03
wValue=0
wIndex=0
data = b"1\r"
d.ctrl_transfer(bmRequestType, bRequest, wValue, wIndex, data)
MAX_PKT=64
reading = epin.read(MAX_PKT)
print(reading)