-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.py
103 lines (80 loc) · 3.17 KB
/
test.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from j2534 import J2534
from j2534 import Protocol_ID
from j2534 import Ioctl_ID
import ctypes
devID = None
channelID = None
protocol = Protocol_ID.ISO15765
baudrate = 500000;
interface = J2534()
print("Opening Pass through device")
result, devID = interface.PassThruOpen()
print(" " + result.name)
print()
#if result.value != 0:
# devID = 12345678
print("Getting device information")
result, firmwareVersion, dllVersion, apiVersion = interface.PassThruReadVersion(devID)
print(" " + result.name)
print(" firmware: " + str(firmwareVersion.value))
print(" dllVersion: " + str(dllVersion.value))
print(" apiVersion: " + str(apiVersion.value))
print()
print("Connecting to pass through device")
result, channelID = interface.PassThruConnect(devID, protocol.value, baudrate)
print(" " + result.name)
print()
print("Setting up a flow contorl filter for ISO15765")
result = interface.PassThruStartMsgFilter(channelID, protocol.value)
print(" " + result.name)
print()
print("Clearing the rxBuffer")
result = interface.PassThruIoctl(channelID, Ioctl_ID.CLEAR_RX_BUFFER)
print(" " + result.name)
print()
#print("Reading buffer (since it should be empty)")
#result, response, numMessages = interface.PassThruReadMsgs(channelID, protocol.value, 1, 10)
#print(" " + result.name)
#print(" " + str(response))
#print()
data = b'\x01\x0C'
print("Sending bytes to Get current engine speed: " + str(data.hex()))
result = interface.PassThruWriteMsgs(channelID, data, protocol.value)
#result = interface.PassThruIoctl(channelID, Ioctl_ID.CLEAR_RX_BUFFER)
print(" Transmit: " + result.name)
response = None
while response == None:
result, response, numMessages = interface.PassThruReadMsgs(channelID, protocol.value, 1, 10)
print(" Receive: " + result.name + ", Num Messages: " + str(numMessages.value))
print(" Response: " + str(response.hex()))
print()
data = b'\x01\x0a'
print("Sending bytes to read Fuel pressure (0x01 0a): " + str(data.hex()))
result = interface.PassThruWriteMsgs(channelID, data, protocol.value)
#result = interface.PassThruIoctl(channelID, Ioctl_ID.CLEAR_RX_BUFFER)
print(" Transmit: " + result.name)
response = None
while response == None:
result, response, numMessages = interface.PassThruReadMsgs(channelID, protocol.value, 1, 10)
print(" Receive: " + result.name + ", Num Messages: " + str(numMessages.value))
print(" Response: " + str(response.hex()))
print()
data = b'\x01\x13'
print("Sending bytes to read O2 sensors (0x01 13): " + str(data.hex()))
result = interface.PassThruWriteMsgs(channelID, data, protocol.value)
#result = interface.PassThruIoctl(channelID, Ioctl_ID.CLEAR_RX_BUFFER)
response = None
print(" Transmit: " + result.name)
while response == None:
result, response, numMessages = interface.PassThruReadMsgs(channelID, protocol.value, 1, 10)
print(" Receive: " + result.name + ", Num Messages: " + str(numMessages.value))
print(" Response: " + str(response.hex()))
print()
print("Disconnecting from pass through device")
result = interface.PassThruDisconnect(channelID)
print(" " + result.name)
print()
print("Closing Pass through device")
result = interface.PassThruClose(devID)
print(" " + result.name)
print()