-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathj2534.py
More file actions
1441 lines (1239 loc) · 63.3 KB
/
j2534.py
File metadata and controls
1441 lines (1239 loc) · 63.3 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#################################################################################################################################################################################################
#
#
# . .. .... ... .. ... .... ........ ......... . . .. ........... ....
# .. .
# : ... .... .... ..
# : ?YY! :YY7 :Y! .?J!~!J?. !YY^ ?J :JJ. .JJ. .JJY^ ~YJ? ~J?~~7J! ?Y. .Y? .7J~^~??. :
# . ~5~7Y. :5JJ? :5! ?5: :5J 7Y?Y^ JY .YJ .YJ. .YJ75: ^57YJ :5? 75~ ?5: .YJ ~5? :
# .. .Y? .Y? :5!.JJ :5! JY. .YJ 75:^5^ JY .J?J7 .YJ 7Y.:5~.YJ :57 !5! ?Y: .YJ :!??7~. :
# . ?57^^J5~ :5! .JJ~Y! JY. .YJ 75: ^Y~JJ :YJ .YJ ?YY! YJ :57 !5~ ?5: .YJ .757 :
# ... . !5!.:.:J5. :5! ?557 ^Y?^::?Y^ 75^ ^YYY .5J .YJ ~^ .YJ 7Y!::~Y?. :Y?^::?Y~ ^J7:.:7Y^ . . . ...
# .. :: .:. :. ::. .:::. .:. .:. :. :. :. .::^:. .:::. .::::. ..
# : ..
# . !?7 77 !7 .!!77!!^ .!7!7!. !77 !77. .~7!!7: .!!77!!^ !7 !7 .7~ :7!!!!. !7! :?^ :?^ :?^ ~??: ^?7: 7! ^7!!77^ 77!!!!. :
# : ~Y!Y~ JJ ?Y ?Y. .Y? ?Y JJJ7 ~Y?Y. ?Y. !5. ?Y. 7Y. :Y^ !Y. ^Y~ ~J~J^ ^Y~ ^5~ ^5~ :5!7Y. !5?Y: YJ ~5~ ^~. YY. :
# . .Y! !Y. JJ ?Y ?Y .57 !5. J?.Y~:5:!Y. JJ ^5^ ?Y 7Y. 7J .J~ :J7~~~ .J~ !J. ^Y~ ^Y~ ^Y~ JJ .Y7 ~5:^5^ J? 75. JJ!~~: ..
# : 7Y7^!Y? JJ ?Y ?Y .57 ?5. J? :Y5~ 7Y. JY ~5: ?Y 7J. .Y~~J :Y^ ?J!^!J7 ^Y~ ^Y~ ^Y~ ~Y?~~JY: ~5: ^Y!J? 75: .: JJ .
# . ^Y^ ~Y: ^J7~!J^ 7J ~J!~!J^ ?? .: !Y. :?7~~?! ?J 7J. !JJ^ :J7~~~: ~J: . ^J^ :J7~~~^ :J?~!!^ :Y~ .J7 .JJ ~Y: :YY? .7J!~!J7. JJ!~~!. :
# : ... .. ... ... . :
# . .
# : . ..:^^~~!!!!!!!!!!!~~^:.. .......................................................................................... .
# : .:^!!!!~^:... ..:^~!!!!^:. :
# .. .................. .:!7!~:. ..^~!!^. .................................................................................. :
# : :!7!^. .:^^.. :~7!^. ............................................... :
# : .!?!: .!?YYYYYJ?~. .:!7^. :
# : ............. ^?7: ^?YYYYYYYYYYYY?^ :!7: .:....::::::::::::::::::::::::::::.......................................... :
# : ~J!. :!!. :JYYYYYYYYYYYYYYYY?: ^!: .~7^ :
# : .......... ~J~. !YY~ ~YYJYYYYYYYYYYYYYYJYY^ .?Y7. ^7^ ..::::::::::::.... ............................................... :
# : :J7. .!:.JJ~ ^YYYYJ?!~^::::^~7?YYYYY: ^?Y~ !. ~?: .............:::::. .
# : !J: :Y~.7^:: .YYJ!: .:7YYJ ..:7^.Y! .7! ....:.. ..
# .. .J7 :Y? .^77. 7Y7. .?5^ ~7:. ^Y~ ^?: .... .
# .. :Y~ .^ ?J.^JJ~ .Y! :~!!!^ ^!!!~. ?? :?J~.?J .~ .?^ ... ..
# . :Y^ J: Y?77: !? :: ^. .J. :!??Y. J: .?^ .:. ..
# .. :Y^ !5..J^.:: J: .:~~: .^!~: !~ ^:.^J: ?? .J: .. :
# : .Y~ JY: .:J! :? ^^^~~^. .^^^:: .J 7?:. .JJ. :J. .::..!. ... ..
# : 7? .YY..?Y^ ?: ^. J: ~J?..JJ. !? ................................^::... :
# . :5. .: 7J~Y!. J. : . ?^ . .. ~! .7J^?7 . .J: ...::... ..
# . 7? ^? .YJ..7. J: :?~. :!7!^. .^7! ?^ .~ :JJ. 7: !7 ...... ...:... ..
# : Y^ ~Y~ ~.:Y7 .J. :^~!~~!7.~!~~~!^~ ^? 7?..! ^Y^ :J ...... ...... .
# . :5. :YY: :YJ. :?. . .:^^.:~^.. :. ^7 .JJ. .JJ. .J. .... ... .
# .. :Y. !Y? JY: .!^ . .Y! . ~^ :Y? ~Y~ J: .::::::.... .. ............ .. .
# .. ^Y . ~Y7Y^ ~ .:^!7??7 :Y7 .7??7!^:. ~ ~Y~J~ : J: ............:....... :..... ......................... .::. :
# .. :Y. !! .J? :Y: :~!?JYYYYYYYYJ. :5! .JYYYYYYYYJ?!^. .Y. J?. ~7 .Y. .^^............ :. ... :. .
# .. .Y: .5?..: 7Y: ~YYYYYYYYYYYYYY? : .JYJJJJJJJJYYYYJ. ^Y! ^ .7Y: :J :.... .^ .: .............. ... ^ :
# : J7 ~YY~ JY. .YYYYYYYYYYYYYYYY^ ~??. 7YJJJJJJJJJJJJJY! :Y? ^YY~ 77 ....::::::::::.... ^ : ..~: .
# : ~Y :J5?.!Y..~ ~YYYYYYYYYYYYYYYYY. .Y? ~YYYYYYJJJJJJJJJYJ ~..Y!.?Y?: .Y. ........... .. :. : .
# .. Y~ . :?J7Y. Y~ JYYYYYYYYYYYYYYYYY7 .Y? .YYYYYJJYJJJJJJJJJY: !J :J7J7: . 77 ^ ................... : ^ :
# : ^Y. ^7: .^?^ ?Y: !YYYYYYYYYJYYYYYYYY^ 7YY: JYJYJJYYYJJYJYJJYY7. ^Y7 !?^..^7. ^J. .:.......... ^ ^ ..!. :
# . 7J :JJ!:.. :YJ .!YYYYYYYYYYYYYYYYY..YYY7 7YJJJJJJJYYJYJYYJ!. JY. ..:7J7 .Y: :::::::::::::::..... .: :. :: ^ :
# . ?7 ~JYJ!: ~Y: !^ .!JYYYYYYYYYYJJYY7!YYYJ!YYYYYYJJJJJJYYJ~ ^! ~Y: :7JY7: .J^ .~ :. .^ ^ ..
# : ?7 .^7J?^!J J?. ^?YYYYYJJYYJJJYYJYYYYYYYYYJYYYYYY?^ :J? :J^^?J7^. .J^ ^ .. ^ .^ .: .
# . 7? .:...::~~ !Y!. .~7JYYYYYYYYYYYYYYYYYYYYYYYJ?~. .7J^ .~^::...:. :?: ^ . :..........................: ^. .
# . ~J: .~77!^:::. :!J7: .:~!7?JJJYYYYYJJJJ?7!^:. .^77^. .:.:^~77~. !7. .............. .:..............................................:: ..
# .. .?! .^!?JJJJ7!7?7!:. ..:::::::::::::. .:!??777JJJJJ?7~. :?^ .............................................. .
# . ~J^ .. ..:~7?JJ7~:^^~!^:~~~^:~7J?7!^:.. ....... .7!. ................. ... ....:::::::::::::::::::::::::::.:.........:.... ..
# : ......... !?^ :~!!77?JYYYJ?~. :!~: .^!^..:~?JYYYJ?7!!~~^. .7!. . ..
# .. .~?~. ..:^^:.. .!J~. :77: .:^^~^^.. ^7!. .. ... ... .
# . :!7^. .?~ :7~ :!7^ ... ..
# . .............. ^!7~. .:!!^. ....... . ............................. .. . .
# . :~!!~:. .^~!~: ..
# : .:~!!~^:. ..:^~!~^. :
# . .~7?J?J????????????????7~:. ..:^~~~~~~~^^^^^^~~~~!~~~^:. .:~!7!~: .^ ::. :. .^ .:. .^ ::. .: :: ^ .:: ^ .:. .^ ::. .^ :. .:: :
# : ~YYYYYYYYYYYYYYYYYYYYYYYYY5YY?7~^:......................:~7?JYYYYYYYY? ? ^: ! ^^ ? :~ !. ? ^: 7 .7 ! .7 !. 7 ^^ 7. .! !. ? .~ !. .7 :~ ! ^^ :
# : JYJJJYYYJJJJYJ?7!!!!!!!!!!!!!777777?JJ??77777777???JJYYYYYYYJJJJJJJJJY^ .7 .^.^ ^~ 7. ~.~ 7. .:.~ .7 :::: !: ~.^. !: ~.~ 7. ~.~ .7 :~ ~.^. :
# : JJJJJJJJYJYY!. .!YYYYYYYYYYYYYYYYYJJYYJJJJJJJJJJY^ :
# : JYJJJJYYYYY^ ^JJJJJJJJJJJJJJJJJJJ?: ~YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY^ :
# : JYJJJYYYYY^ !YYYYYYYYYYYYYYYYYYYYYY^ ^YYYYYYYYJJJJJJJJJJJJJJJJJJYYJY^ .7 ^~ !: .7 .7 .^.~ :! :::^ ^.:: 7. ~.~. .7 .~.~ .7 .^.^ ^^ ~.^. ~.~. :
# : JYJJJYYYJ: 75YYYYYYYYYYYYYYYYYYYYYYY~ ^YYYYYYYY~ .JYJY^ ? .! ~^ ? 7 ^: 7 .7 !. ! ! .~ !: 7 ^: 7 .~ ! 7 ~. ! :~ ! ^: ! ~: :
# : JYJJY7:. .......................... ..:!YYYY^ ?YJY^ .:. .: :: .:. :. ... .: .. .. :. ... :. ... .:. .. .: ... ... :
# : JJJYJ JYYY^ :! JYYY^ :
# : JYJYJ ~??7?7~ ~7????^ ?YYY^ ^..^..... :^ JYYY^ ^:^ .~ ^: ::^ .~ .^:. .::. ^: ^: ::^ ^:^ .~ .^:: .::: .::. ::^. ~. ::^ ^
# : JJJYJ !JJYYJ? :::::::::^. ?JJJYY~ ?YYY^ ^. ^. . .: ?YJY^ .~ !. .? ^~ 7 :^ 7 ~. 7 7 ! :~ :~ 7 ^:.! ~. 7 ~. 7 !. 7 7 .! 7 .~ !. ! ~. ^
# : JJJJJ ?YJY^ ..:7^ ?YJY^ ^.^ .! ^^ :.: .!. .::. .::. ^^ :^ :.^ ^.^ .! .::: .::: .::. :.^. ~: :.^ :
# : JJJYJ ?YJY^ ?YJY^ :
# : JYJYJ ^^^^^^^^^^^^^^^^^^^^^^^^^^. ?YYY!...............:JYJY^ ... .: .. .:. : .. .. .. .. ... .: .. .. :. .:. : ... ... :
# : JJJYJ .YYYYYYYYYYYYYYYYYYYYYYYYY5^ JYJJYYYYYYYYYYYYYYYYYJJJY^ .! !. .7 7 .~ 7 ^: 7 ^: ! ^^ ^~ ! :^ ! ^: ? :! ^~ ~^ 7 :^ ? .! ! .! !. :
# : JJJJY?~^::^?YJJJJJJJJJYJJYJJJYJJJYJJJY?^^^^^7YJJYYYJYYJYJJYJJJYJJJJJJY^ ~.~ .7 ^.:: ~.^. 7. .^.~ ^~ ^~ ~.^. ~.^. 7. :! :! ~^ ~.^. 7. ~.~ ~.~ :
# : JYJJJYYYYYYYJJJJJJJJJJYJJJYYJJJJJJJJJJYYYYYYYJJJJYJYYYYJJJJJJJYJJJJJJY: .
# : :JYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYJ^ .
# .. :~!0x416E6F6E796D6F7573204175746F6D6F7469766520416C6C69616E6365!~: :! :::^ 7. ~.~ ~.~ .^.^ ^~ ~.^. .7. ~.~ :! :^.^ ::.^ ~: ^.^. .7 .7 .^.^ .
# .. .7 !. ! !: .! ~.:~ ! ~. 7 :~ 7 :^ 7. .~ !. 7 ~. ! ~. 7 ^^ 7 .^ ? 7 ~. 7 ..
# . .^ .. :. ... ... :. :: .:. ^. ... .^. :.. .:. :: .:: .^. ^. :.. :
# ... ..
# . ... . ................................. #
#
#
#################################################################################################################################################################################################
'''
The Anonymous Automotive Alliance Presents
A J2534 Implementation.
In 32 bit Python.
Deployed 21/10/2025
Communication is Essential.
Without it what would we have?
'''
#################################################################################################################################################################################################
from enum import IntEnum, Flag
from abc import ABC, abstractmethod
from ctypes import *
from typing import List, Optional
import os
# ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class ConfigParameter(IntEnum):
DATA_RATE = 0x01
LOOPBACK = 0x03
NODE_ADDRESS = 0x04
NETWORK_LINE = 0x05
P1_MIN = 0x06
P1_MAX = 0x07
P2_MIN = 0x08
P2_MAX = 0x09
P3_MIN = 0x0A
P3_MAX = 0x0B
P4_MIN = 0x0C
P4_MAX = 0x0D
W1 = 0x0E
W2 = 0x0F
W3 = 0x10
W4 = 0x11
W5 = 0x12
TIDLE = 0x13
TINIL = 0x14
TWUP = 0x15
PARITY = 0x16
BIT_SAMPLE_POINT = 0x17
SYNC_JUMP_WIDTH = 0x18
W0_MIN = 0x19
T1_MAX = 0x1A
T2_MAX = 0x1B
T4_MAX = 0x1C
T5_MAX = 0x1D
ISO15765_BS = 0x1E
ISO15765_STMIN = 0x1F
DATA_BITS = 0x20
FIVE_BAUD_MOD = 0x21
BS_TX = 0x22
STMIN_TX = 0x23
T3_MAX = 0x24
ISO15765_WFT_MAX = 0x25
W1_MIN = 0X26
W2_MIN = 0X27
W3_MIN = 0X28
W4_MAX = 0X29
N_BR_MIN = 0X2A
ISO15765_PAD_VALUE = 0X2B
N_AS_MAX = 0X2C
N_AR_MAX = 0X2D
N_BS_MAX = 0X2E
N_CR_MAX = 0X2F
N_CS_MIN = 0X30
ECHO_PHYSCIAL_CHANNEL_TX = 0X31
CAN_MIXED_FORMAT = 0x00008000
J1962_PINS = 0x00008001
SW_CAN_HS_DATA_RATE = 0x00008010
SW_CAN_SPEEDCHANGE_ENABLE = 0x00008011
SW_CAN_RES_SWITCH = 0x00008012
ACTIVE_CHANNELS = 0x00008020
SAMPLE_RATE = 0x00008021
SAMPLES_PER_READING = 0x00008022
READINGS_PER_MSG = 0x00008023
AVERAGING_METHOD = 0x00008024
SAMPLE_RESOLUTION = 0x00008025
INPUT_RANGE_LOW = 0x00008026
INPUT_RANGE_HIGH = 0x00008027
UEB_T0_MIN = 0x00008028
UEB_T1_MAX = 0x00008029
UEB_T2_MAX = 0x0000802A
UEB_T3_MAX = 0x0000802B
UEB_T4_MIN = 0x0000802C
UEB_T5_MAX = 0x0000802D
UEB_T6_MAX = 0x0000802E
UEB_T7_MIN = 0x0000802F
UEB_T7_MAX = 0x00008030
UEB_T9_MIN = 0x00008031
J1939_PINS = 0x0000803D
J1708_PINS = 0x0000803E
J1939_T1 = 0x0000803F
J1939_T2 = 0x00008040
J1939_T3 = 0x00008041
J1939_T4 = 0x00008042
J1939_BRDCST_MIN_DELAY = 0x00008043
TP2_0_T_BR_INT = 0x00008044
TP2_0_T_E = 0x00008045
TP2_0_MNTC = 0x00008046
TP2_0_T_CTA = 0x00008047
TP2_0_MNCT = 0x00008048
TP2_0_MNTB = 0x00008049
TP2_0_MNT = 0x0000804A
TP2_0_T_Wait = 0x0000804B
TP2_0_T1 = 0x0000804C
TP2_0_T3 = 0x0000804D
TP2_0_IDENTIFER = 0x0000804E
TP2_0_RXIDPASSIVE = 0x0000804F
class IJ2534(ABC):
@abstractmethod
def LoadLibrary(self, device: 'J2534Device') -> bool:
pass
@abstractmethod
def FreeLibrary(self) -> bool:
pass
@abstractmethod
def PassThruOpen(self, name: c_void_p, deviceId: c_uint) -> 'J2534Err':
pass
@abstractmethod
def PassThruClose(self, deviceId: c_uint) -> 'J2534Err':
pass
@abstractmethod
def PassThruConnect(self, deviceId: c_uint, protocolId: 'ProtocolID', flags: 'ConnectFlag', baudRate: 'BaudRate', channelId: c_uint) -> 'J2534Err':
pass
@abstractmethod
def PassThruDisconnect(self, channelId: c_int) -> 'J2534Err':
pass
@abstractmethod
def PassThruReadMsgs(self, channelId: c_int, msgs: c_void_p, numMsgs: c_int, timeout: c_int) -> 'J2534Err':
pass
@abstractmethod
def PassThruStartPeriodicMsg(self, channelId: c_int, msg: c_void_p, msgId: c_int, timeInterval: c_int) -> 'J2534Err':
pass
@abstractmethod
def PassThruStopPeriodicMsg(self, channelId: c_int, msgId: c_int) -> 'J2534Err':
pass
@abstractmethod
def PassThruStartMsgFilter(self, channelid: c_int, filterType: 'FilterType', maskMsg: c_void_p, patternMsg: c_void_p, flowControlMsg: c_void_p, filterId: c_int) -> 'J2534Err':
pass
@abstractmethod
def PassThruStopMsgFilter(self, channelId: c_int, filterId: c_int) -> 'J2534Err':
pass
@abstractmethod
def PassThruSetProgrammingVoltage(self, deviceId: c_int, pinNumber: 'PinNumber', voltage: c_uint) -> 'J2534Err':
pass
@abstractmethod
def PassThruReadVersion(self, deviceId: c_int, firmwareVersion: c_void_p, dllVersion: c_void_p, apiVersion: c_void_p) -> 'J2534Err':
pass
@abstractmethod
def PassThruGetLastError(self, errorDescription: c_void_p) -> 'J2534Err':
pass
@abstractmethod
def PassThruIoctl(self, channelId: c_int, ioctlID: c_int, input: c_void_p, output: c_void_p) -> 'J2534Err':
pass
@abstractmethod
def PassThruQueueMsgs(self, channelId: c_int, msg: c_void_p, numMsgs: c_int) -> 'J2534Err':
pass
@abstractmethod
def PassThruScanForDevices(self, DeviceCount: c_int) -> 'J2534Err':
pass
@abstractmethod
def PassThruGetNextDevice(self, Device: 'SDEVICE') -> 'J2534Err':
pass
@abstractmethod
def PassThruLogicalConnect(self, PhyscialChannelId: c_int, protocolId: 'ProtocolID', flags: 'ConnectFlag', ChannelDescriptor: c_void_p, LogicalChannelId: c_int) -> 'J2534Err':
pass
@abstractmethod
def PassThruLogicalDisconnect(self, LogicalChannelId: c_int) -> 'J2534Err':
pass
@abstractmethod
def PassThruSelect(self, ChannelSetPtr: c_void_p, SelectType: c_uint, Timeout: c_uint) -> 'J2534Err':
pass
@abstractmethod
def PassThruWriteMsgs(self, channelId: c_int, msg: c_void_p, numMsgs: c_int, timeout: c_int) -> 'J2534Err':
pass
class IJ2534Extended(IJ2534):
@abstractmethod
def GetConfig(self, channelId: c_int, config: List['SConfig']) -> 'J2534Err':
pass
@abstractmethod
def SetConfig(self, channelId: c_int, config: List['SConfig']) -> 'J2534Err':
pass
@abstractmethod
def SW_CAN_BusSpeed(self, ChannelID: c_int, Option: c_int) -> 'J2534Err':
pass
@abstractmethod
def ReadBatteryVoltage(self, deviceId: c_int, voltage: c_int) -> 'J2534Err':
pass
@abstractmethod
def ReadProgrammingVoltage(self, deviceId: c_int, voltage: c_int) -> 'J2534Err':
pass
@abstractmethod
def FiveBaudInit(self, channelId: c_int, targetAddress: c_byte, keyword1: c_byte, keyword2: c_byte) -> 'J2534Err':
pass
@abstractmethod
def FastInit(self, channelId: c_int, txMsg: 'PassThruMsg', rxMsg: 'PassThruMsg') -> 'J2534Err':
pass
@abstractmethod
def ClearTxBuffer(self, channelId: c_int) -> 'J2534Err':
pass
@abstractmethod
def ClearRxBuffer(self, channelId: c_int) -> 'J2534Err':
pass
@abstractmethod
def ClearPeriodicMsgs(self, channelId: c_int) -> 'J2534Err':
pass
@abstractmethod
def ClearMsgFilters(self, channelId: c_int) -> 'J2534Err':
pass
@abstractmethod
def ClearFunctMsgLookupTable(self, channelId: c_int) -> 'J2534Err':
pass
@abstractmethod
def AddToFunctMsgLookupTable(self, channelId: c_int) -> 'J2534Err':
pass
@abstractmethod
def DeleteFromFunctMsgLookupTable(self, channelId: c_int) -> 'J2534Err':
pass
@abstractmethod
def ReadAllMessages(self, channelId: c_int, numMsgs: c_int, timeout: c_int, messages: List['PassThruMsg'], readUntilTimeout: bool) -> 'J2534Err':
pass
class Ioctl(IntEnum):
GET_CONFIG = 0x01
SET_CONFIG = 0x02
READ_VBATT = 0x03
FIVE_BAUD_INIT = 0x04
FAST_INIT = 0x05
CLEAR_TX_BUFFER = 0x07
CLEAR_RX_BUFFER = 0x08
CLEAR_PERIODIC_MSGS = 0x09
CLEAR_MSG_FILTERS = 0x0A
CLEAR_FUNCT_MSG_LOOKUP_TABLE = 0x0B
ADD_TO_FUNCT_MSG_LOOKUP_TABLE = 0x0C
DELETE_FROM_FUNCT_MSG_LOOKUP_TABLE = 0x0D
READ_PROG_VOLTAGE = 0x0E
BUS_ON = 0x0F
SW_CAN_HS = 0x8000 # Request swcan Highspeed
SW_CAN_NS = 0x8001 # Request swcan low speed
SET_POLL_RESPONSE = 0x8002 # aldl
BECOME_MASTER = 0x8003 # aldl
START_REPEAT_MESSAGE = 0x8004
QUERY_REPEAT_MESSAGE = 0x8005
STOP_REPEAT_MESSAGE = 0x8006
GET_ConnectedDevice_CONFIG = 0x8007
SET_ConnectedDevice_CONFIG = 0x8008
PROTECT_J1939_ADDR = 0x8009
REQUEST_CONNECTION = 0x800A
TEARDOWN_CONNECTION = 0x800B
GET_Device_INFO = 0x800C
GET_PROTOCOL_INFO = 0x800D
class GET_DEVICE_INFO_Defines(IntEnum):
SERIAL_NUMBER = 0x00000001
J1850PWM_SUPPORTED = 0x00000002
J1850VPW_SUPPORTED = 0x00000003
ISO9141_SUPPORTED = 0x00000004
ISO14230_SUPPORTED = 0x00000005
CAN_SUPPORTED = 0x00000006
ISO15765_SUPPORTED = 0x00000007
SCI_A_ENGINE_SUPPORTED = 0x00000008
SCI_A_TRANS_SUPPORTED = 0x00000009
SCI_B_ENGINE_SUPPORTED = 0x0000000A
SCI_B_TRANS_SUPPORTED = 0x0000000B
SW_ISO15765_SUPPORTED = 0x0000000C
SW_CAN_SUPPORTED = 0x0000000D
GM_UART_SUPPORTED = 0x0000000E
UART_ECHO_BYTE_SUPPORTED = 0x0000000F
HONDA_DIAGH_SUPPORTED = 0x00000010
J1939_SUPPORTED = 0x00000011
J1708_SUPPORTED = 0x00000012
TP2_0_SUPPORTED = 0x00000013
J2610_SUPPORTED = 0x00000014
ANALOG_IN_SUPPORTED = 0x00000015
MAX_NON_VOLATILE_STORAGE = 0x00000016
SHORT_TO_GND_J1962 = 0x00000017
PGM_VOLTAGE_J1962 = 0x00000018
J1850PWM_PS_J1962 = 0x00000019
J1850VPW_PS_J1962 = 0x0000001A
ISO9141_PS_K_LINE_J1962 = 0x0000001B
ISO9141_PS_L_LINE_J1962 = 0x0000001C
ISO14230_PS_K_LINE_J1962 = 0x0000001D
ISO14230_PS_L_LINE_J1962 = 0x0000001E
CAN_PS_J1962 = 0x0000001F
ISO15765_PS_J1962 = 0x00000020
SW_CAN_PS_J1962 = 0x00000021
SW_ISO15765_PS_J1962 = 0x00000022
GM_UART_PS_J1962 = 0x00000023
UART_ECHO_BYTE_PS_J1962 = 0x00000024
HONDA_DIAGH_PS_J1962 = 0x00000025
J1939_PS_J1962 = 0x00000026
J1708_PS_J1962 = 0x00000027
TP2_0_PS_J1962 = 0x00000028
J2610_PS_J1962 = 0x00000029
J1939_PS_J1939 = 0x0000002A
J1708_PS_J1939 = 0x0000002B
ISO9141_PS_K_LINE_J1939 = 0x0000002C
ISO9141_PS_L_LINE_J1939 = 0x0000002D
ISO14230_PS_K_LINE_J1939 = 0x0000002E
ISO14230_PS_L_LINE_J1939 = 0x0000002F
J1708_PS_J1708 = 0x00000030
FT_CAN_SUPPORTED = 0x00000031
FT_ISO15765_SUPPORTED = 0x00000032
FT_CAN_PS_J1962 = 0x00000033
FT_ISO15765_PS_J1962 = 0x00000034
J1850PWM_SIMULTANEOUS = 0x00000035
J1850VPW_SIMULTANEOUS = 0x00000036
ISO9141_SIMULTANEOUS = 0x00000037
ISO14230_SIMULTANEOUS = 0x00000038
CAN_SIMULTANEOUS = 0x00000039
ISO15765_SIMULTANEOUS = 0x0000003A
SCI_A_ENGINE_SIMULTANEOUS = 0x0000003B
SCI_A_TRANS_SIMULTANEOUS = 0x0000003C
SCI_B_ENGINE_SIMULTANEOUS = 0x0000003D
SCI_B_TRANS_SIMULTANEOUS = 0x0000003E
SW_ISO15765_SIMULTANEOUS = 0x0000003F
SW_CAN_SIMULTANEOUS = 0x00000040
GM_UART_SIMULTANEOUS = 0x00000041
UART_ECHO_BYTE_SIMULTANEOUS = 0x00000042
HONDA_DIAGH_SIMULTANEOUS = 0x00000043
J1939_SIMULTANEOUS = 0x00000044
J1708_SIMULTANEOUS = 0x00000045
TP2_0_SIMULTANEOUS = 0x00000046
J2610_SIMULTANEOUS = 0x00000047
ANALOG_IN_SIMULTANEOUS = 0x00000048
PART_NUMBER = 0x00000049
FT_CAN_SIMULTANEOUS = 0x0000004A
FT_ISO15765_SIMULTANEOUS = 0x0000004B
class RxStatus(Flag):
NONE = 0x00000000
TX_MSG_TYPE = 0x00000001
START_OF_MESSAGE = 0x00000002
RX_BREAK = 0x00000004
TX_INDICATION_SUCCESS = 0x00000008
ISO15765_PADDING_ERROR = 0x00000010
ERROR_INDICATION = 0x20
BUFFER_OVERFLOW = 0x40
ISO15765_ADDR_TYPE = 0x00000080
CAN_29BIT_ID = 0x00000100
TX_FAILED = 0x200
SW_CAN_HV_TX = 0x00000400
SW_CAN_NS_RX = 0x00040000
SW_CAN_HS_RX = 0x00020000
SW_CAN_HV_RX = 0x00010000
class ConnectFlag(Flag):
NONE = 0x0000
ISO9141_K_LINE_ONLY = 0x1000
CAN_ID_BOTH = 0x0800
ISO9141_NO_CHECKSUM = 0x0200
CAN_29BIT_ID = 0x0100
FULL_DUPLEX = 0x1
class TxFlag(Flag):
NONE = 0x00000000
SCI_TX_VOLTAGE = 0x00800000
SCI_MODE = 0x00400000
WAIT_P3_MIN_ONLY = 0x00000200
CAN_29BIT_ID = 0x00000100
ISO15765_ADDR_TYPE = 0x00000080
ISO15765_FRAME_PAD = 0x00000040
SW_CAN_HV_TX = 0x00000400
class ProtocolID(IntEnum):
J1850VPW = 0x01
J1850PWM = 0x02
ISO9141 = 0x03
ISO14230 = 0x04
CAN = 0x05
ISO15765 = 0x06
SCI_A_ENGINE = 0x07
SCI_A_TRANS = 0x08
SCI_B_ENGINE = 0x09
SCI_B_TRANS = 0x0A
ISO15765_LOGICAL = 0x200
# J2534-2 protocols
J1850VPW_PS = 0x8000
J1850PWM_PS = 0x8001
ISO9141_PS = 0x8002
ISO14230_PS = 0x8003
CAN_PS = 0x8004
ISO15765_PS = 0x8005
J2610_PS = 0x8006
SW_ISO15765_PS = 0x8007
SW_CAN_PS = 0x8008
GM_UART_PS = 0x8009
UART_ECHO_BYTE_PS = 0x800A
HONDA_DIAGH_PS = 0x800B
J1939_PS = 0x800C
J1708_PS = 0x800D
TP2_0_PS = 0x800E
FT_CAN_PS = 0x800F
FT_ISO15765_PS = 0x8010
class BaudRate(IntEnum):
ISO9141_10400 = 10400
ISO9141_10000 = 10000
ISO14230_10400 = 10400
ISO14230_10000 = 10000
J1850PWM_41600 = 41600
J1850PWM_83300 = 83300
J1850VPW_10400 = 10400
J1850VPW_41600 = 41600
CAN_125000 = 125000
CAN_250000 = 250000
CAN_500000 = 500000
CAN_33333 = 33333
CAN_83333 = 83333
ISO15765_125000 = 125000
ISO15765_250000 = 250000
ISO15765_500000 = 500000
GMUART_8192 = 8192
GMUART_160 = 160
class PinNumber(IntEnum):
AUX = 0
PIN_1 = 1
PIN_3 = 3
PIN_6 = 6
PIN_9 = 9
PIN_11 = 11
PIN_12 = 12
PIN_13 = 13
PIN_14 = 14
PIN_15 = 15
class PinVoltage(IntEnum):
FEPS_VOLTAGE = 18000
SHORT_TO_GROUND = 0xFFFFFFFE
VOLTAGE_OFF = 0xFFFFFFFF
class FilterType(IntEnum):
PASS_FILTER = 0x01
BLOCK_FILTER = 0x02
FLOW_CONTROL_FILTER = 0x03
class J2534Err(IntEnum):
STATUS_NOERROR = 0x00
ERR_NOT_SUPPORTED = 0x01
ERR_INVALID_CHANNEL_ID = 0x02
ERR_INVALID_PROTOCOL_ID = 0x03
ERR_NULL_PARAMETER = 0x04
ERR_INVALID_FLAGS = 0x06
ERR_FAILED = 0x07
ERR_ConnectedDevice_NOT_CONNECTED = 0x08
ERR_TIMEOUT = 0x09
ERR_INVALID_MSG = 0x0A
ERR_INVALID_TIME_INTERVAL = 0x0B
ERR_EXCEEDED_LIMIT = 0x0C
ERR_INVALID_MSG_ID = 0x0D
ERR_ConnectedDevice_IN_USE = 0x0E
ERR_INVALID_IOCTL_ID = 0x0F
ERR_BUFFER_EMPTY = 0x10
ERR_BUFFER_FULL = 0x11
ERR_BUFFER_OVERFLOW = 0x12
ERR_PIN_INVALID = 0x13
ERR_CHANNEL_IN_USE = 0x14
ERR_MSG_PROTOCOL_ID = 0x15
ERR_INVALID_FILTER_ID = 0x16
ERR_NO_FLOW_CONTROL = 0x17
ERR_NOT_UNIQUE = 0x18
ERR_INVALID_BAUDRATE = 0x19
ERR_INVALID_ConnectedDevice_ID = 0x1A
ERR_ConnectedDevice_NOT_OPEN = 0X1B
ERR_NULL_REQUIRED = 0X1C
ERR_FILTER_TYPE_NOT_SUPPORTED = 0X1D
ERR_IOCTL_PARAM_ID_NOT_SUPPORTED = 0X1E
ERR_VOLTAGE_IN_USE = 0X1F
ERR_PIN_IN_USE = 0X20
ERR_INIT_FAILED = 0X21
ERR_OPEN_FAILED = 0X22
ERR_BUFFER_TOO_SMALL = 0X23
ERR_LOG_CHAN_NOT_ALLOWED = 0X24
ERR_SELECT_TYPE_NOT_SUPPORTED = 0X25
ERR_CONCURRENT_API_CALL = 0X26
ERR_OEM_VOLTAGE_TOO_HIGH = 0x77
ERR_OEM_VOLTAGE_TOO_LOW = 0x78
ERR_ACCESS_VIOLATION = 0x1000
ERR_DLL_NOT_LOADED = 0x1001
ERR_RESOURCE_IN_USE = 0x1002
ERR_OUT_OF_MEMORY = 0x1999
ERR_ALDL_HEARTBEAT_NOT_FOUND = 0x5000
ERR_NO_RESPONSE_FROM_MODULE = 0x5001
class J2534Device:
def __init__(self):
self.Vendor = ""
self.Name = ""
self.FunctionLibrary = ""
self.ConfigApplication = ""
self.CAN = 0
self.ISO14230 = 0
self.ISO15765 = 0
self.ISO9141 = 0
self.J1850PWM = 0
self.J1850VPW = 0
self.SCI_A_ENGINE = 0
self.SCI_A_TRANS = 0
self.SCI_B_ENGINE = 0
self.SCI_B_TRANS = 0
self.CAN_PS = 0
self.FT_CAN_PS = 0
self.FT_ISO15765_PS = 0
self.GM_UART_PS = 0
self.ISO14230_PS = 0
self.ISO15765_PS = 0
self.ISO9141_PS = 0
self.SW_CAN_PS = 0
self.SW_ISO15765_PS = 0
self.J1850VPW_PS = 0
def __str__(self):
return self.Name
class NativeMethods:
if os.name == 'nt':
_kernel32 = windll.kernel32
@staticmethod
def LoadLibrary(dllToLoad: str) -> c_void_p:
return NativeMethods._kernel32.LoadLibraryW(dllToLoad)
@staticmethod
def GetProcAddress(hModule: c_void_p, procedureName: str) -> c_void_p:
return NativeMethods._kernel32.GetProcAddress(hModule, procedureName.encode('ascii'))
@staticmethod
def FreeLibrary(hModule: c_void_p) -> bool:
return bool(NativeMethods._kernel32.FreeLibrary(hModule))
else:
# For non-Windows systems, use ctypes.CDLL
_loaded_libs = {}
@staticmethod
def LoadLibrary(dllToLoad: str) -> c_void_p:
try:
lib = CDLL(dllToLoad)
handle = c_void_p(id(lib))
NativeMethods._loaded_libs[handle.value] = lib
return handle
except:
return c_void_p(0)
@staticmethod
def GetProcAddress(hModule: c_void_p, procedureName: str) -> c_void_p:
if hModule.value in NativeMethods._loaded_libs:
lib = NativeMethods._loaded_libs[hModule.value]
try:
func = getattr(lib, procedureName)
return cast(func, c_void_p)
except:
return c_void_p(0)
return c_void_p(0)
@staticmethod
def FreeLibrary(hModule: c_void_p) -> bool:
if hModule.value in NativeMethods._loaded_libs:
del NativeMethods._loaded_libs[hModule.value]
return True
return False
class J2534DllWrapper:
def __init__(self):
self.m_pDll = c_void_p(0)
# Define delegate types
self.PassThruOpen = None
self.PassThruClose = None
self.PassThruScanForDevices = None
self.PassThruGetNextDevice = None
self.PassThruConnect = None
self.PassThruDisconnect = None
self.PassThruReadMsgs = None
self.PassThruWriteMsgs = None
self.PassThruQueueMsgs = None
self.PassThruLogicalConnect = None
self.PassThruLogicalDisconnect = None
self.PassThruSelect = None
self.PassThruStartPeriodicMsg = None
self.PassThruStopPeriodicMsg = None
self.PassThruStartMsgFilter = None
self.PassThruStartPassBlockMsgFilter = None
self.PassThruStopMsgFilter = None
self.PassThruSetProgrammingVoltage = None
self.PassThruReadVersion = None
self.PassThruGetLastError = None
self.PassThruIoctl = None
# Define function prototypes
self.Open = None
self.Close = None
self.ScanForDevices = None
self.GetNextDevice = None
self.Connect = None
self.Disconnect = None
self.ReadMsgs = None
self.WriteMsgs = None
self.WriteQueueMsgs = None
self.ConnectLogical = None
self.DisconnectLogical = None
self.SelectChannelToCheck = None
self.StartPeriodicMsg = None
self.StopPeriodicMsg = None
self.StartMsgFilter = None
self.StartPassBlockMsgFilter = None
self.StopMsgFilter = None
self.SetProgrammingVoltage = None
self.ReadVersion = None
self.GetLastError = None
self.Ioctl = None
def LoadJ2534Library(self, path: str) -> bool:
self.m_pDll = NativeMethods.LoadLibrary(path)
if not self.m_pDll:
return False
# Load PassThruOpen
pAddressOfFunctionToCall = NativeMethods.GetProcAddress(self.m_pDll, "PassThruOpen")
if pAddressOfFunctionToCall:
self.Open = CFUNCTYPE(c_int, c_void_p, POINTER(c_uint))(pAddressOfFunctionToCall.value)
else:
return False
# Load PassThruClose
pAddressOfFunctionToCall = NativeMethods.GetProcAddress(self.m_pDll, "PassThruClose")
if pAddressOfFunctionToCall:
self.Close = CFUNCTYPE(c_int, c_uint)(pAddressOfFunctionToCall.value)
else:
return False
# Load PassThruConnect
pAddressOfFunctionToCall = NativeMethods.GetProcAddress(self.m_pDll, "PassThruConnect")
if pAddressOfFunctionToCall:
self.Connect = CFUNCTYPE(c_int, c_uint, c_int, c_int, c_int, POINTER(c_uint))(pAddressOfFunctionToCall.value)
else:
return False
# Load PassThruDisconnect
pAddressOfFunctionToCall = NativeMethods.GetProcAddress(self.m_pDll, "PassThruDisconnect")
if pAddressOfFunctionToCall:
self.Disconnect = CFUNCTYPE(c_int, c_int)(pAddressOfFunctionToCall.value)
else:
return False
# Load PassThruReadMsgs
pAddressOfFunctionToCall = NativeMethods.GetProcAddress(self.m_pDll, "PassThruReadMsgs")
if pAddressOfFunctionToCall:
self.ReadMsgs = CFUNCTYPE(c_int, c_int, c_void_p, POINTER(c_int), c_int)(pAddressOfFunctionToCall.value)
else:
return False
# Load PassThruWriteMsgs
pAddressOfFunctionToCall = NativeMethods.GetProcAddress(self.m_pDll, "PassThruWriteMsgs")
if pAddressOfFunctionToCall:
self.WriteMsgs = CFUNCTYPE(c_int, c_int, c_void_p, POINTER(c_int), c_int)(pAddressOfFunctionToCall.value)
else:
return False
# Load PassThruStartPeriodicMsg
pAddressOfFunctionToCall = NativeMethods.GetProcAddress(self.m_pDll, "PassThruStartPeriodicMsg")
if pAddressOfFunctionToCall:
self.StartPeriodicMsg = CFUNCTYPE(c_int, c_int, c_void_p, POINTER(c_int), c_int)(pAddressOfFunctionToCall.value)
else:
return False
# Load PassThruStopPeriodicMsg
pAddressOfFunctionToCall = NativeMethods.GetProcAddress(self.m_pDll, "PassThruStopPeriodicMsg")
if pAddressOfFunctionToCall:
self.StopPeriodicMsg = CFUNCTYPE(c_int, c_int, c_int)(pAddressOfFunctionToCall.value)
else:
return False
# Load PassThruStartMsgFilter
pAddressOfFunctionToCall = NativeMethods.GetProcAddress(self.m_pDll, "PassThruStartMsgFilter")
if pAddressOfFunctionToCall:
self.StartMsgFilter = CFUNCTYPE(c_int, c_int, c_int, c_void_p, c_void_p, c_void_p, POINTER(c_int))(pAddressOfFunctionToCall.value)
# Load PassThruStartMsgFilter (as StartPassBlockMsgFilter)
pAddressOfFunctionToCall = NativeMethods.GetProcAddress(self.m_pDll, "PassThruStartMsgFilter")
if pAddressOfFunctionToCall:
self.StartPassBlockMsgFilter = CFUNCTYPE(c_int, c_int, c_int, POINTER(PassThruMsg), POINTER(PassThruMsg), c_int, POINTER(c_int))(pAddressOfFunctionToCall.value)
else:
return False
# Load PassThruStopMsgFilter
pAddressOfFunctionToCall = NativeMethods.GetProcAddress(self.m_pDll, "PassThruStopMsgFilter")
if pAddressOfFunctionToCall:
self.StopMsgFilter = CFUNCTYPE(c_int, c_int, c_int)(pAddressOfFunctionToCall.value)
else:
return False
# Load PassThruSetProgrammingVoltage
pAddressOfFunctionToCall = NativeMethods.GetProcAddress(self.m_pDll, "PassThruSetProgrammingVoltage")
if pAddressOfFunctionToCall:
self.SetProgrammingVoltage = CFUNCTYPE(c_int, c_int, c_uint, c_uint)(pAddressOfFunctionToCall.value)
else:
return False
# Load PassThruReadVersion
pAddressOfFunctionToCall = NativeMethods.GetProcAddress(self.m_pDll, "PassThruReadVersion")
if pAddressOfFunctionToCall:
self.ReadVersion = CFUNCTYPE(c_int, c_int, c_void_p, c_void_p, c_void_p)(pAddressOfFunctionToCall.value)
else:
return False
# Load PassThruGetLastError
pAddressOfFunctionToCall = NativeMethods.GetProcAddress(self.m_pDll, "PassThruGetLastError")
if pAddressOfFunctionToCall:
self.GetLastError = CFUNCTYPE(c_int, c_void_p)(pAddressOfFunctionToCall.value)
else:
return False
# Load PassThruIoctl
pAddressOfFunctionToCall = NativeMethods.GetProcAddress(self.m_pDll, "PassThruIoctl")
if pAddressOfFunctionToCall:
self.Ioctl = CFUNCTYPE(c_int, c_int, c_int, c_void_p, c_void_p)(pAddressOfFunctionToCall.value)
else:
return False
return True
def FreeLibrary(self) -> bool:
if self.m_pDll:
NativeMethods.FreeLibrary(self.m_pDll)
return True
class J2534Functions(IJ2534):
def __init__(self):
self._ConnectedDevice = None
self._J2534DllWrapper = None
self._IsDLLLoaded = False
def __str__(self):
return "Deployed publicly for the greater automotive good by the Anonymous Automotive Alliance, Oct 2025."
@property
def IsDLLLoaded(self) -> bool:
return self._IsDLLLoaded
@property
def DeviceName(self) -> str:
return self._ConnectedDevice.Name if self._ConnectedDevice else ""
def LoadLibrary(self, device: J2534Device) -> bool:
try:
self._ConnectedDevice = device
self._J2534DllWrapper = J2534DllWrapper()
self._IsDLLLoaded = self._J2534DllWrapper.LoadJ2534Library(self._ConnectedDevice.FunctionLibrary)
return self._IsDLLLoaded
except Exception:
self._IsDLLLoaded = False
return self._IsDLLLoaded
def FreeLibrary(self) -> bool:
self._IsDLLLoaded = False
if self._J2534DllWrapper:
return self._J2534DllWrapper.FreeLibrary()
return True
def PassThruOpen(self, name: c_void_p, deviceId: c_uint) -> J2534Err:
try:
if not self.IsDLLLoaded:
return J2534Err.ERR_DLL_NOT_LOADED
result = J2534Err(self._J2534DllWrapper.Open(name, byref(deviceId)))
return result
except Exception:
return J2534Err.ERR_ACCESS_VIOLATION
def PassThruClose(self, deviceId: c_uint) -> J2534Err:
try:
if not self.IsDLLLoaded:
return J2534Err.ERR_DLL_NOT_LOADED
return J2534Err(self._J2534DllWrapper.Close(deviceId))
except Exception:
return J2534Err.ERR_ACCESS_VIOLATION
def PassThruScanForDevices(self, DeviceCount: c_int) -> J2534Err:
try:
if not self.IsDLLLoaded:
return J2534Err.ERR_DLL_NOT_LOADED
return J2534Err(self._J2534DllWrapper.ScanForDevices(byref(DeviceCount)))
except Exception:
return J2534Err.ERR_ACCESS_VIOLATION
def PassThruGetNextDevice(self, Device: 'SDEVICE') -> J2534Err:
try:
if not self.IsDLLLoaded:
return J2534Err.ERR_DLL_NOT_LOADED
return J2534Err(self._J2534DllWrapper.GetNextDevice(byref(Device)))
except Exception:
return J2534Err.ERR_ACCESS_VIOLATION
def PassThruQueueMsgs(self, channelId: c_int, msgs: c_void_p, numMsgs: c_int) -> J2534Err:
try:
if not self.IsDLLLoaded:
return J2534Err.ERR_DLL_NOT_LOADED
return J2534Err(self._J2534DllWrapper.WriteQueueMsgs(channelId, msgs, byref(numMsgs)))
except Exception:
return J2534Err.ERR_ACCESS_VIOLATION
def PassThruLogicalConnect(self, PhyscialChannelId: c_int, protocolId: ProtocolID, flags: ConnectFlag, ChannelDescriptor: c_void_p, LogicalChannelId: c_int) -> J2534Err:
try:
if not self.IsDLLLoaded:
return J2534Err.ERR_DLL_NOT_LOADED
return J2534Err(self._J2534DllWrapper.ConnectLogical(PhyscialChannelId, protocolId, flags, byref(ChannelDescriptor), byref(LogicalChannelId)))
except Exception:
return J2534Err.ERR_ACCESS_VIOLATION
def PassThruLogicalDisconnect(self, LogicalChannelId: c_int) -> J2534Err:
try:
if not self.IsDLLLoaded:
return J2534Err.ERR_DLL_NOT_LOADED
return J2534Err(self._J2534DllWrapper.DisconnectLogical(LogicalChannelId))
except Exception:
return J2534Err.ERR_ACCESS_VIOLATION
def PassThruSelect(self, ChannelSetPtr: c_void_p, SelectType: c_uint, Timeout: c_uint) -> J2534Err:
try:
if not self.IsDLLLoaded:
return J2534Err.ERR_DLL_NOT_LOADED
return J2534Err(self._J2534DllWrapper.SelectChannelToCheck(byref(ChannelSetPtr), SelectType, Timeout))
except Exception:
return J2534Err.ERR_ACCESS_VIOLATION
def PassThruConnect(self, deviceId: c_uint, protocolId: ProtocolID, flags: ConnectFlag, baudRate: BaudRate, channelId: c_uint) -> J2534Err:
try:
if not self.IsDLLLoaded:
return J2534Err.ERR_DLL_NOT_LOADED
return J2534Err(self._J2534DllWrapper.Connect(deviceId, protocolId, flags, baudRate, byref(channelId)))
except Exception:
return J2534Err.ERR_ACCESS_VIOLATION
def PassThruDisconnect(self, channelId: c_int) -> J2534Err:
try:
if not self.IsDLLLoaded:
return J2534Err.ERR_DLL_NOT_LOADED
return J2534Err(self._J2534DllWrapper.Disconnect(channelId))
except Exception:
return J2534Err.ERR_ACCESS_VIOLATION
def PassThruReadMsgs(self, channelId: c_int, msgs: c_void_p, numMsgs: c_int, timeout: c_int) -> J2534Err:
try:
if not self.IsDLLLoaded:
return J2534Err.ERR_DLL_NOT_LOADED
return J2534Err(self._J2534DllWrapper.ReadMsgs(channelId, msgs, byref(numMsgs), timeout))
except Exception:
return J2534Err.ERR_ACCESS_VIOLATION