-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDHPInterface_API.bas
More file actions
919 lines (733 loc) · 32.5 KB
/
Copy pathDHPInterface_API.bas
File metadata and controls
919 lines (733 loc) · 32.5 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
Attribute VB_Name = "DHPInterface_API"
Public Function DHPInterface_RequestFirmwareVersion()
'Clear Buffer
If ClearBuffer <> 0 Then
DHPInterface_RequestFirmwareVersion = -1
Exit Function
End If
If boolAbortSendCommand = False Then
'Reset Cable, by Setting Low Speed VPW Mode:
rtnCode = DHPInterface_SetLowSpeedVPW
Debug.Print "Set Low Speed VPW rtncode = " & rtnCode
If Left(rtnCode, 1) = "-" Then
'Return with error message
DHPInterface_RequestFirmwareVersion = rtnCode
Exit Function
End If
End If
If boolAbortSendCommand = False Then
'Set the cable to echo all instructdions that are sent to the bus.
rtnCode = DHPInterface_SetMessageEcho
If Left(rtnCode, 1) = "-" Then
'Return with error message
DHPInterface_RequestFirmwareVersion = rtnCode
Exit Function
End If
End If
If boolAbortSendCommand = False Then
'--------------------Get Firmware ------------------------
'Display firmwave version
'Send Get vin Part #1
ReDim testArray(0)
'Create Initialize packet
testArray(0) = "&HB0"
'Init Flags and Counters
txtResponseString = DHPInterface_SendCommand("DHPInterface Request Firmware Version", testArray, 1, "&H92&H04")
Debug.Print "DHPInterface Request Firmware Version = " & txtResponseString
'Check response versus expected
If Left(txtResponseString, 1) <> "-" Then
DHPInterface_RequestFirmwareVersion = txtResponseString
Else
DHPInterface_RequestFirmwareVersion = txtResponseString
End If
End If
'Close com port
If frmMain.MSComm1.PortOpen = True Then
frmMain.MSComm1.PortOpen = False
End If
End Function
Public Function DHPInterface_WritePacket(arrayPacket() As Byte, arrayPacketLength)
'On Error GoTo WritePacketErrorHandler
'Check the data Packet and make sure it fits spec.
'Write data out
'frmMain.MSComm1.RTSEnable = True
'frmMain.MSComm1.DTREnable = True
frmMain.MSComm1.Output = arrayPacket()
DHPInterface_WritePacket = 0
Exit Function
WritePacketErrorHandler:
errValue = Err.Number
errString = Err.Description
errSource = Err.Source
DHPInterface_WritePacket = Err.Number
End Function
Public Function DHPInterface_SetLowSpeedVPW()
'----------------------------------------------------
'Create Low Speed packet
ReDim testArray(1)
'Create Initialize packet
testArray(0) = "&HC1"
testArray(1) = "&H00"
txtResponseString = DHPInterface_SendCommand("DHPInterface Set Low Speed VPW", testArray, 2, "&HC1&H00")
Debug.Print "DHPInterface Set Low Speed VPW = " & txtResponseString
'Check response versus expected
If Left(txtResponseString, 1) <> "-" Then
DHPInterface_SetLowSpeedVPW = "0"
End If
End Function
Public Function DHPInterface_SetMessageEcho()
'----------------------------------------------------
'Enable Echo Mode
ReDim testArray(2)
'Create Initialize packet
testArray(0) = "&H52"
testArray(1) = "&H06"
testArray(2) = "&H01"
txtResponseString = DHPInterface_SendCommand("DHPInterface Set Message Echo", testArray, 3, "&H62&H06&H01")
Debug.Print "DHPInterface Set Message Echo = " & txtResponseString
'Check response versus expected
If Left(txtResponseString, 1) <> "-" Then
DHPInterface_SetMessageEcho = "0"
End If
End Function
Public Function DHPInterface_ReadVin()
'INit variables
intReadRetries = 0
'Open Serial Port
If frmMain.MSComm1.PortOpen = False Then
'Display Status Information for frmReadVin
frmReadVin.lblCurrentTask.Caption = "Current Task : Initializing Serial Port"
frmReadVin.barCurrentTask.Value = 0
frmReadVin.barReadVinTask = 10
frmReadVin.StatusBar1.Panels(1).Text = "Initializing Serial Port"
frmReadVin.Refresh
'End Display Information
If OpenSerialPort <> 0 Then
MsgBox "Error " & errValue & " has occurred while attempting to open the com port! " & vbCrLf & "Error Details : " & errString, vbCritical, "VinEditor : Com Port Initialization Error!"
'Abort VIN Read
DHPInterface_ReadVin = errValue
Exit Function
End If
End If
'Clear Buffer
If ClearBuffer <> 0 Then
MsgBox "Error " & errValue & " has occurred while attempting to clear com buffer! " & vbCrLf & "Error Details : " & errString, vbCritical, "VinEditor : Com Buffer Initialization Error!"
'Abort VIN Read
DHPInterface_ReadVin = errValue
Exit Function
End If
'Reset Cable, by Setting Low Speed VPW Mode:
'Display Status Information for frmReadVin
frmReadVin.lblCurrentTask.Caption = "Current Task : Resetting Cable"
frmReadVin.barCurrentTask.Value = 0
frmReadVin.barReadVinTask = 10
frmReadVin.StatusBar1.Panels(1).Text = "Resetting Cable"
frmReadVin.Refresh
rtnCode = DHPInterface_SetLowSpeedVPW
Debug.Print "Set Low Speed VPW rtncode = " & rtnCode
If rtnCode <> 0 Then
'Return with error message
DHPInterface_ReadVin = rtnCode
Exit Function
End If
'Set the cable to echo all instructdions that are sent to the bus.
'Display Status Information for frmReadVin
frmReadVin.lblCurrentTask.Caption = "Current Task : Configuring Communication Session"
frmReadVin.barCurrentTask.Value = 0
frmReadVin.barReadVinTask = frmReadVin.barReadVinTask + 10
frmReadVin.StatusBar1.Panels(1).Text = "Configure Session"
frmReadVin.Refresh
rtnCode = DHPInterface_SetMessageEcho
If rtnCode <> 0 Then
'Return with error message
DHPInterface_ReadVin = rtnCode
Exit Function
End If
'Clear Buffer
If ClearBuffer <> 0 Then
MsgBox "Error " & errValue & " has occurred while attempting to clear com buffer! " & vbCrLf & "Error Details : " & errString, vbCritical, "VinEditor : Com Buffer Initialization Error!"
'Abort VIN Read
DHPInterface_ReadVin = errValue
Exit Function
End If
'--------------------Read VIN 1 ------------------------
'Get the Vin Data starting with Part #1
'Display Status Information for frmReadVin
frmReadVin.lblCurrentTask.Caption = "Current Task : Reading VIN Data "
frmReadVin.barCurrentTask.Value = 0
frmReadVin.barReadVinTask = frmReadVin.barReadVinTask + 20
frmReadVin.StatusBar1.Panels(1).Text = "Reading VIN Data"
frmReadVin.Refresh
'Send Get vin Part #1
ReDim testArray(5)
'Create Initialize packet
testArray(0) = "&H05"
testArray(1) = "&H6C"
testArray(2) = "&H10"
testArray(3) = "&HF1"
testArray(4) = "&H3C"
testArray(5) = "&H01"
'Init Flags and Counters
intDHPInterface_RequestFirmwareVersionPart1Attempts = 0
intReadRetries = 0
boolDHPInterface_RequestFirmwareVersionPart1 = False
Do Until boolDHPInterface_RequestFirmwareVersionPart1 = True Or intDHPInterface_RequestFirmwareVersionPart1Attempts > intMaxGenericRetries
DoEvents
'ClearBuffer
If ClearBuffer <> 0 Then
MsgBox "Error " & errValue & " has occurred while attempting to clear com buffer! " & vbCrLf & "Error Details : " & errString, vbCritical, "VinEditor : Com Buffer Initialization Error!"
'Abort VIN Read
DHPInterface_ReadVin = errValue
Exit Function
End If
'Write test packet
writepacketresponse = DHPInterface_WritePacket(testArray, 6)
'MsgBox "write packet response = " & writepacketresponse
If writepacketresponse = 0 Then
'Stop timer
frmMain.Timer1.Enabled = False
response = DHPInterface_ReadPacket("&H0C&H00&H6C&HF1&H10&H7C&H01")
If response <> "-1" Then
Debug.Print "Vin 1 Read response = " & response
boolDHPInterface_RequestFirmwareVersionPart1 = True
intDHPInterface_RequestFirmwareVersionPart1Attempts = 0
txtvinpart1 = Chr(CDec(Mid(response, 33, 4))) & Chr(CDec(Mid(response, 37, 4))) & Chr(CDec(Mid(response, 41, 4))) & Chr(CDec(Mid(response, 45, 4))) & Chr(CDec(Mid(response, 49, 4)))
frmMain.Refresh
frmMain.Text1.Text = txtvinpart1
Else
intDHPInterface_RequestFirmwareVersionPart1Attempts = intDHPInterface_RequestFirmwareVersionPart1Attempts + 1
End If
Else
intDHPInterface_RequestFirmwareVersionPart1Attempts = intDHPInterface_RequestFirmwareVersionPart1Attempts + 1
End If
Loop
'Check to see if failure occurred
If boolDHPInterface_RequestFirmwareVersionPart1 = False Then
DHPInterface_ReadVin = -2 'Failed Read part #1 of vin
Exit Function
End If
'-------------END Read Vin #1---------------------------------------------------
'--------------------Read VIN 2 ------------------------
'Get the Vin Data starting with Part #2
'Display Status Information for frmReadVin
frmReadVin.lblCurrentTask.Caption = "Current Task : Reading VIN Data "
frmReadVin.barReadVinTask = frmReadVin.barReadVinTask + 20
frmReadVin.StatusBar1.Panels(1).Text = "Reading VIN Data"
frmReadVin.Refresh
'Send Get vin Part #2
ReDim testArray(5)
'Create Initialize packet
testArray(0) = "&H05"
testArray(1) = "&H6C"
testArray(2) = "&H10"
testArray(3) = "&HF1"
testArray(4) = "&H3C"
testArray(5) = "&H02"
'Init Flags and Counters
intDHPInterface_RequestFirmwareVersionPart1Attempts = 0
intReadRetries = 0
boolDHPInterface_RequestFirmwareVersionPart1 = False
Do Until boolDHPInterface_RequestFirmwareVersionPart1 = True Or intDHPInterface_RequestFirmwareVersionPart1Attempts > intMaxGenericRetries
DoEvents
'ClearBuffer
If ClearBuffer <> 0 Then
MsgBox "Error " & errValue & " has occurred while attempting to clear com buffer! " & vbCrLf & "Error Details : " & errString, vbCritical, "VinEditor : Com Buffer Initialization Error!"
'Abort VIN Read
DHPInterface_ReadVin = errValue
Exit Function
End If
'Write test packet
writepacketresponse = DHPInterface_WritePacket(testArray, 6)
'MsgBox "write packet response = " & writepacketresponse
If writepacketresponse = 0 Then
'Stop timer
frmMain.Timer1.Enabled = False
response = DHPInterface_ReadPacket("&H0C&H00&H6C&HF1&H10&H7C&H02")
If response <> "-1" Then
Debug.Print "Vin 2 Read response = " & response
boolDHPInterface_RequestFirmwareVersionPart1 = True
intDHPInterface_RequestFirmwareVersionPart1Attempts = 0
txtvinpart1 = Chr(CDec(Mid(response, 29, 4))) & Chr(CDec(Mid(response, 33, 4))) & Chr(CDec(Mid(response, 37, 4))) & Chr(CDec(Mid(response, 41, 4))) & Chr(CDec(Mid(response, 45, 4))) & Chr(CDec(Mid(response, 49, 4)))
frmMain.Refresh
frmMain.Text1.Text = frmMain.Text1.Text & txtvinpart1
Else
intDHPInterface_RequestFirmwareVersionPart1Attempts = intDHPInterface_RequestFirmwareVersionPart1Attempts + 1
End If
Else
intDHPInterface_RequestFirmwareVersionPart1Attempts = intDHPInterface_RequestFirmwareVersionPart1Attempts + 1
End If
Loop
'Check to see if failure occurred
If boolDHPInterface_RequestFirmwareVersionPart1 = False Then
DHPInterface_ReadVin = -2 'Failed Read part #1 of vin
Exit Function
End If
'-------------END Read Vin #2---------------------------------------------------
'--------------------Read VIN 3 ------------------------
'Get the Vin Data starting with Part #3
'Display Status Information for frmReadVin
frmReadVin.lblCurrentTask.Caption = "Current Task : Reading VIN Data "
frmReadVin.barReadVinTask = frmReadVin.barReadVinTask + 20
frmReadVin.StatusBar1.Panels(1).Text = "Reading VIN Data"
frmReadVin.Refresh
'Send Get vin Part #3
ReDim testArray(5)
'Create Initialize packet
testArray(0) = "&H05"
testArray(1) = "&H6C"
testArray(2) = "&H10"
testArray(3) = "&HF1"
testArray(4) = "&H3C"
testArray(5) = "&H03"
'Init Flags and Counters
intDHPInterface_RequestFirmwareVersionPart1Attempts = 0
intReadRetries = 0
boolDHPInterface_RequestFirmwareVersionPart1 = False
Do Until boolDHPInterface_RequestFirmwareVersionPart1 = True Or intDHPInterface_RequestFirmwareVersionPart1Attempts > intMaxGenericRetries
DoEvents
'ClearBuffer
If ClearBuffer <> 0 Then
MsgBox "Error " & errValue & " has occurred while attempting to clear com buffer! " & vbCrLf & "Error Details : " & errString, vbCritical, "VinEditor : Com Buffer Initialization Error!"
'Abort VIN Read
DHPInterface_ReadVin = errValue
Exit Function
End If
'Write test packet
writepacketresponse = DHPInterface_WritePacket(testArray, 6)
'MsgBox "write packet response = " & writepacketresponse
If writepacketresponse = 0 Then
'Stop timer
frmMain.Timer1.Enabled = False
response = DHPInterface_ReadPacket("&H0C&H00&H6C&HF1&H10&H7C&H03")
If response <> "-1" Then
Debug.Print "Vin 3 Read response = " & response
boolDHPInterface_RequestFirmwareVersionPart1 = True
intDHPInterface_RequestFirmwareVersionPart1Attempts = 0
txtvinpart1 = Chr(CDec(Mid(response, 29, 4))) & Chr(CDec(Mid(response, 33, 4))) & Chr(CDec(Mid(response, 37, 4))) & Chr(CDec(Mid(response, 41, 4))) & Chr(CDec(Mid(response, 45, 4))) & Chr(CDec(Mid(response, 49, 4)))
frmMain.Refresh
frmMain.Text1.Text = frmMain.Text1.Text & txtvinpart1
Else
intDHPInterface_RequestFirmwareVersionPart1Attempts = intDHPInterface_RequestFirmwareVersionPart1Attempts + 1
End If
Else
intDHPInterface_RequestFirmwareVersionPart1Attempts = intDHPInterface_RequestFirmwareVersionPart1Attempts + 1
End If
Loop
'Check to see if failure occurred
If boolDHPInterface_RequestFirmwareVersionPart1 = False Then
DHPInterface_ReadVin = -3 'Failed Read part #2 of vin
Exit Function
Else
frmMain.Timer1.Enabled = False
frmReadVin.barReadVinTask.Value = frmReadVin.barReadVinTask.Max
frmReadVin.Refresh
'We're done reading the vin
strCableConnected = "Connected "
strPCMConnected = "Connected "
strVinNumber = frmMain.Text1.Text
UpdateStatusBar
frmMain.Refresh
DHPInterface_ReadVin = 0
End If
'-------------END Read Vin #3---------------------------------------------------
'Close com port
frmMain.MSComm1.PortOpen = False
End Function
Public Function DHPInterface_ReadPacket(strExpectedAnswer As String) As String
On Error GoTo DHPInterface_ReadPacketErrorHandler
'Declare Variables
Dim boolPacketComplete As Boolean
Dim intTimeout As Integer
Dim intRetries As Integer
Dim intMaxRetries As Integer
Dim strTempBuffer As String
'Initialize Variables
boolPacketComplete = False
boolTimedOut = False
intTimeout = 1000 '1000 msec = 1 second
intRetries = 0
intMaxRetries = 3
strTempBuffer = ""
'Activate timer
frmMain.Timer1.Enabled = True
frmMain.Timer1.Interval = intTimeout
MainPacketLoop:
Do While boolPacketComplete = False And intRetries < intMaxRetries
DoEvents
If boolTimedOut = True Then
boolTimedOut = False
intRetries = intRetries + 1
Else
intStartPos = InStr(1, varInBuffer, strExpectedAnswer)
If intStartPos > 0 Then
'Result matched return success and clear that item from buffer
boolPacketComplete = True
'Get data
SOFhex = Left(strExpectedAnswer, 4)
strTempBuffer = SOFhex
Select Case Mid(SOFhex, 3, 1)
Case "0"
charFrameType = "0"
intDataLength = Val(SOFhex)
Case "2"
charFrameType = "2"
intDataLength = Val("&H" & Right(SOFhex, 1))
Case "3"
charFrameType = "3"
intDataLength = Val("&H" & Right(SOFhex, 1))
Case "6"
charFrameType = "6"
intDataLength = Val("&H" & Right(SOFhex, 1))
Case "8"
charFrameType = "8"
intDataLength = Val("&H" & Right(SOFhex, 1))
Case "9"
charFrameType = "9"
intDataLength = Val("&H" & Right(SOFhex, 1))
Case "C"
charFrameType = "C"
intDataLength = Val("&H" & Right(SOFhex, 1))
Case Else
SOFhex = ""
intDataLength = 0
End Select
For x = intStartPos + 4 To intStartPos + (intDataLength * 4) Step 4
strTempBuffer = strTempBuffer & Mid(varInBuffer, x, 4)
Next x
'Buffer Debug.
'Debug.Print "Attemping to Remove value from Buffer"
'Debug.Print "Initial Buffer = " & varInBuffer
'Debug.Print "Removing : " & strTempBuffer
'Remove temp variable from buffer
If intStartPos = 1 Then
If Len(varInBuffer) = Len(strTempBuffer) Then
varInBuffer = ""
Else
varInBuffer = Right(varInBuffer, Len(varInBuffer) - Len(strTempBuffer))
End If
Else
varInBuffer = Left(varInBuffer, intStartPos - 1) & Mid(varInBuffer, intStartPos + Len(strTempBuffer), Len(varInBuffer) - Len(strTempBuffer) - 1)
End If
'Debug.Print "Buffer after removal = " & varInBuffer
'Debug.Print "---------------------"
End If
End If
Loop
'De-Activate timer
frmMain.Timer1.Enabled = False
'Determine why we left the loop and act accordingly
If boolPacketComplete = True Then
DHPInterface_ReadPacket = strTempBuffer
Else
DHPInterface_ReadPacket = "-1"
End If
Exit Function
DHPInterface_ReadPacketErrorHandler:
GoTo MainPacketLoop
End Function
Public Function DHPInterface_WriteVin()
'INit variables
intReadRetries = 0
'Open Serial Port
If frmMain.MSComm1.PortOpen = False Then
'Display Status Information for frmWriteVin
frmWriteVin.lblCurrentTask.Caption = "Current Task : Initializing Serial Port"
frmWriteVin.barCurrentTask.Value = 0
frmWriteVin.barWriteVinTask = 10
frmWriteVin.StatusBar1.Panels(1).Text = "Initializing Serial Port"
frmWriteVin.Refresh
'End Display Information
If OpenSerialPort <> 0 Then
MsgBox "Error " & errValue & " has occurred while attempting to open the com port! " & vbCrLf & "Error Details : " & errString, vbCritical, "VinEditor : Com Port Initialization Error!"
'Abort VIN Read
DHPInterface_WriteVin = errValue
Exit Function
End If
End If
'Clear Buffer
If ClearBuffer <> 0 Then
MsgBox "Error " & errValue & " has occurred while attempting to clear com buffer! " & vbCrLf & "Error Details : " & errString, vbCritical, "VinEditor : Com Buffer Initialization Error!"
'Abort VIN Read
DHPInterface_WriteVin = errValue
Exit Function
End If
'Reset Cable, by Setting Low Speed VPW Mode:
'Display Status Information for frmWriteVin
frmWriteVin.lblCurrentTask.Caption = "Current Task : Resetting Cable"
frmWriteVin.barCurrentTask.Value = 0
frmWriteVin.barWriteVinTask = 10
frmWriteVin.StatusBar1.Panels(1).Text = "Resetting Cable"
frmWriteVin.Refresh
rtnCode = DHPInterface_SetLowSpeedVPW
Debug.Print "Set Low Speed VPW rtncode = " & rtnCode
If rtnCode <> 0 Then
'Return with error message
DHPInterface_WriteVin = rtnCode
Exit Function
End If
'Set the cable to echo all instructdions that are sent to the bus.
'Display Status Information for frmWriteVin
frmWriteVin.lblCurrentTask.Caption = "Current Task : Configuring Communication Session"
frmWriteVin.barCurrentTask.Value = 0
frmWriteVin.barWriteVinTask = frmWriteVin.barWriteVinTask + 10
frmWriteVin.StatusBar1.Panels(1).Text = "Configure Session"
frmWriteVin.Refresh
rtnCode = DHPInterface_SetMessageEcho
If rtnCode <> 0 Then
'Return with error message
DHPInterface_WriteVin = rtnCode
Exit Function
End If
'--------------------Write VIN 1 ------------------------
'Get the Vin Data starting with Part #1
'Display Status Information for frmWriteVin
frmWriteVin.lblCurrentTask.Caption = "Current Task : Writing VIN Data "
frmWriteVin.barCurrentTask.Value = 0
frmWriteVin.barWriteVinTask = frmWriteVin.barWriteVinTask + 20
frmWriteVin.StatusBar1.Panels(1).Text = "Write VIN Data"
frmWriteVin.Refresh
'Send Get vin Part #1
ReDim testArray(11)
'Create Initialize packet
testArray(0) = "&H0B"
testArray(1) = "&H6C"
testArray(2) = "&H10"
testArray(3) = "&HF1"
testArray(4) = "&H3B"
testArray(5) = "&H01"
testArray(6) = "&H00"
testArray(7) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 1, 1))))
testArray(8) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 2, 1))))
testArray(9) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 3, 1))))
testArray(10) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 4, 1))))
testArray(11) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 5, 1))))
'Init Flags and Counters
intDHPInterface_RequestFirmwareVersionPart1Attempts = 0
intReadRetries = 0
boolDHPInterface_RequestFirmwareVersionPart1 = False
Do Until boolDHPInterface_RequestFirmwareVersionPart1 = True Or intDHPInterface_RequestFirmwareVersionPart1Attempts > intMaxGenericRetries
DoEvents
'ClearBuffer
If ClearBuffer <> 0 Then
MsgBox "Error " & errValue & " has occurred while attempting to clear com buffer! " & vbCrLf & "Error Details : " & errString, vbCritical, "VinEditor : Com Buffer Initialization Error!"
'Abort VIN Read
DHPInterface_WriteVin = errValue
Exit Function
End If
'Write test packet
writepacketresponse = DHPInterface_WritePacket(testArray, 12)
'MsgBox "write packet response = " & writepacketresponse
If writepacketresponse = 0 Then
'Stop timer
frmMain.Timer1.Enabled = False
response = DHPInterface_ReadPacket("&H06&H00&H6C&HF1&H10&H7B&H01")
If response <> "-1" Then
Debug.Print "Write Vin 1 response = " & response
boolDHPInterface_RequestFirmwareVersionPart1 = True
intDHPInterface_RequestFirmwareVersionPart1Attempts = 0
Else
intDHPInterface_RequestFirmwareVersionPart1Attempts = intDHPInterface_RequestFirmwareVersionPart1Attempts + 1
End If
Else
intDHPInterface_RequestFirmwareVersionPart1Attempts = intDHPInterface_RequestFirmwareVersionPart1Attempts + 1
End If
Loop
'Check to see if failure occurred
If boolDHPInterface_RequestFirmwareVersionPart1 = False Then
DHPInterface_WriteVin = -2 'Failed Read part #1 of vin
Exit Function
End If
'-------------END Write Vin #1---------------------------------------------------
'--------------------Write VIN 2 ------------------------
'Get the Vin Data starting with Part #2
'Display Status Information for frmWriteVin
frmWriteVin.lblCurrentTask.Caption = "Current Task : Writing VIN Data "
frmWriteVin.barWriteVinTask = frmWriteVin.barWriteVinTask + 40
frmWriteVin.StatusBar1.Panels(1).Text = "Write VIN Data"
frmWriteVin.Refresh
'Send Get vin Part #1
ReDim testArray(11)
'Create Initialize packet
testArray(0) = "&H0B"
testArray(1) = "&H6C"
testArray(2) = "&H10"
testArray(3) = "&HF1"
testArray(4) = "&H3B"
testArray(5) = "&H02"
testArray(6) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 6, 1))))
testArray(7) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 7, 1))))
testArray(8) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 8, 1))))
testArray(9) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 9, 1))))
testArray(10) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 10, 1))))
testArray(11) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 11, 1))))
'Init Flags and Counters
intDHPInterface_RequestFirmwareVersionPart1Attempts = 0
intReadRetries = 0
boolDHPInterface_RequestFirmwareVersionPart1 = False
Do Until boolDHPInterface_RequestFirmwareVersionPart1 = True Or intDHPInterface_RequestFirmwareVersionPart1Attempts > intMaxGenericRetries
DoEvents
'ClearBuffer
If ClearBuffer <> 0 Then
MsgBox "Error " & errValue & " has occurred while attempting to clear com buffer! " & vbCrLf & "Error Details : " & errString, vbCritical, "VinEditor : Com Buffer Initialization Error!"
'Abort VIN Read
DHPInterface_WriteVin = errValue
Exit Function
End If
'Write test packet
writepacketresponse = DHPInterface_WritePacket(testArray, 12)
'MsgBox "write packet response = " & writepacketresponse
If writepacketresponse = 0 Then
'Stop timer
frmMain.Timer1.Enabled = False
response = DHPInterface_ReadPacket("&H06&H00&H6C&HF1&H10&H7B&H02")
If response <> "-1" Then
Debug.Print "Write Vin 1 response = " & response
boolDHPInterface_RequestFirmwareVersionPart1 = True
intDHPInterface_RequestFirmwareVersionPart1Attempts = 0
Else
intDHPInterface_RequestFirmwareVersionPart1Attempts = intDHPInterface_RequestFirmwareVersionPart1Attempts + 1
End If
Else
intDHPInterface_RequestFirmwareVersionPart1Attempts = intDHPInterface_RequestFirmwareVersionPart1Attempts + 1
End If
Loop
'Check to see if failure occurred
If boolDHPInterface_RequestFirmwareVersionPart1 = False Then
DHPInterface_WriteVin = -2 'Failed Read part #1 of vin
Exit Function
End If
'-------------END Write Vin #2---------------------------------------------------
'--------------------Write VIN 3 ------------------------
'Write the vin data with section #3
'Display Status Information for frmWriteVin
frmWriteVin.lblCurrentTask.Caption = "Current Task : Writing VIN Data "
frmWriteVin.barWriteVinTask = frmWriteVin.barWriteVinTask + 20
frmWriteVin.StatusBar1.Panels(1).Text = "Write VIN Data"
frmWriteVin.Refresh
'Send Get vin Part #1
ReDim testArray(11)
'Create Initialize packet
testArray(0) = "&H0B"
testArray(1) = "&H6C"
testArray(2) = "&H10"
testArray(3) = "&HF1"
testArray(4) = "&H3B"
testArray(5) = "&H03"
testArray(6) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 12, 1))))
testArray(7) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 13, 1))))
testArray(8) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 14, 1))))
testArray(9) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 15, 1))))
testArray(10) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 16, 1))))
testArray(11) = "&H" & Hex(Asc(UCase(Mid(frmMain.Text1.Text, 17, 1))))
'Init Flags and Counters
intDHPInterface_RequestFirmwareVersionPart1Attempts = 0
intReadRetries = 0
boolDHPInterface_RequestFirmwareVersionPart1 = False
Do Until boolDHPInterface_RequestFirmwareVersionPart1 = True Or intDHPInterface_RequestFirmwareVersionPart1Attempts > intMaxGenericRetries
DoEvents
'ClearBuffer
If ClearBuffer <> 0 Then
MsgBox "Error " & errValue & " has occurred while attempting to clear com buffer! " & vbCrLf & "Error Details : " & errString, vbCritical, "VinEditor : Com Buffer Initialization Error!"
'Abort VIN Read
DHPInterface_WriteVin = errValue
Exit Function
End If
'Write test packet
writepacketresponse = DHPInterface_WritePacket(testArray, 12)
'MsgBox "write packet response = " & writepacketresponse
If writepacketresponse = 0 Then
'Stop timer
frmMain.Timer1.Enabled = False
response = DHPInterface_ReadPacket("&H06&H00&H6C&HF1&H10&H7B&H03")
If response <> "-1" Then
Debug.Print "Write Vin 1 response = " & response
boolDHPInterface_RequestFirmwareVersionPart1 = True
intDHPInterface_RequestFirmwareVersionPart1Attempts = 0
Else
intDHPInterface_RequestFirmwareVersionPart1Attempts = intDHPInterface_RequestFirmwareVersionPart1Attempts + 1
End If
Else
intDHPInterface_RequestFirmwareVersionPart1Attempts = intDHPInterface_RequestFirmwareVersionPart1Attempts + 1
End If
Loop
'Check to see if failure occurred
If boolDHPInterface_RequestFirmwareVersionPart1 = False Then
DHPInterface_WriteVin = -3 'Failed Read part #1 of vin
Exit Function
End If
'-------------END Write Vin #3---------------------------------------------------
'stop timer
frmMain.Timer1.Enabled = False
'Display Status Information for frmWriteVin
frmWriteVin.lblCurrentTask.Caption = "Current Task : Write Vin Data"
frmWriteVin.barCurrentTask = frmWriteVin.barCurrentTask.Max
frmWriteVin.barWriteVinTask = frmWriteVin.barWriteVinTask.Max
frmWriteVin.StatusBar1.Panels(1).Text = "Write Vin Data Completed"
frmWriteVin.Refresh
'End Display Information
MsgBox "Vin change successful. Please turn key off to save new Vin."
'We're done reading the vin
strCableConnected = "Connected "
strPCMConnected = "Connected "
strVinNumber = frmMain.Text1.Text
UpdateStatusBar
frmMain.Refresh
'Return Success
DHPInterface_WriteVin = 0
'close port
If frmMain.MSComm1.PortOpen = True Then
frmMain.MSComm1.PortOpen = False
End If
End Function
Function DHPInterface_SendCommand(strCommandName, arrayPacket() As Byte, arrayPacketLength, strMatchPattern As String)
'Open Serial Port
If frmMain.MSComm1.PortOpen = False Then
If OpenSerialPort <> 0 Then
DHPInterface_SendCommand = errValue
Exit Function
End If
End If
'Init Flags and Counters
intDHPInterface_SendCommandAttempts = 0
intReadRetries = 0
boolDHPInterface_SendCommand = False
boolAbortSendCommand = False
Do Until boolAbortSendCommand = True Or boolDHPInterface_SendCommand = True Or intDHPInterface_SendCommandAttempts > intMaxGenericRetries
DoEvents
'ClearBuffer
If ClearBuffer <> 0 Then
MsgBox "Error " & errValue & " has occurred while attempting to clear com buffer! " & vbCrLf & "Error Details : " & errString, vbCritical, "VinEditor : Com Buffer Initialization Error!"
'Abort VIN Read
DHPInterface_SendCommand = errValue
Exit Function
End If
'Write test packet
writepacketresponse = DHPInterface_WritePacket(arrayPacket, arrayPacketLength)
'MsgBox "write packet response = " & writepacketresponse
If writepacketresponse = 0 Then
'If not expecting a response, bypass and return success
If strMatchPattern = "" Then
DHPInterface_SendCommand = 0
Exit Function
End If
'Stop timer
frmMain.Timer1.Enabled = False
response = DHPInterface_ReadPacket(strMatchPattern)
If response <> "-1" Then
Debug.Print strCommandName & " response = " & response
boolDHPInterface_SendCommand = True
intDHPInterface_SendCommand = 0
DHPInterface_SendCommand = response
Else
intDHPInterface_SendCommandAttempts = intDHPInterface_SendCommandAttempts + 1
End If
Else
intDHPInterface_SendCommandAttempts = intDHPInterface_SendCommandAttempts + 1
End If
Loop
'Check to see if failure occurred
If boolDHPInterface_SendCommand = False Then
DHPInterface_SendCommand = -2 'Failed Read of Send Command
Exit Function
End If
End Function