Having a guy help me with some code, however, he doesnt know VB6 and only has freebasic

I need to convert the following into VB6 so I can make a user interface (comport selection etc) but not sure how to do it.

Even a step in the correct direction would be great!

Much appreciated, thank you.


Dim resp1 As String
Dim resp2 As String
Dim resp3 As String
Dim x As uinteger

declare sub getreply()

Open Com "COM1:9600,N,8,1,CS0,DS0,DT" As #1
Open "progress.txt" For Output As #2
input "enter start number (add &h at the beginning for a hex #)"; x
Print "starting at "; Hex(x)
x = Int(x)
If x < 0 Then GoTo FinishThat
If x > 65535 Then GoTo FinishThat
Print #2, "seed key tryer"
Print #2, "starting at "; Hex(x)
Print #1, "atz"
getreply()
sleep 2500
Print #1, "at sh 6c 10 f1"
getreply()
x = x + &H27020000
sleep 350
MainLoop:
Print #1, "27 01"
sleep 500
getreply()
Print #1, Hex(x)
sleep 500
getreply()
If resp2 = "67 02 34 " Then GoTo FinishThis
If resp2 = "67 02 37 " Then x = x - 1
Print #2, Hex(x)
Print #2, resp2
x = x + 1
If x = &H27030000 Then GoTo FinishThat
Print #1, "27 01"
sleep 500
getreply()
Print #1, Hex(x)
sleep 500
getreply()
If resp2 = "67 02 34 " Then GoTo FinishThis
If resp2 = "67 02 37 " Then x = x - 1
x = x + 1
If x = &H27030000 Then GoTo FinishThat
sleep 11000
GoTo MainLoop

FinishThis:
x = x - &H27020000
Print #2, Hex(x); " this is your key"
Close #1
Close #2
End

FinishThat:
Print #2, "your key was not found"
Close #1
Close #2
End

Sub getreply()
resp1 = "0"
Do While resp1 = "0"
Input #1, resp1
Loop
Print #2, resp1
resp2 = "0"
Do While resp2 = "0"
Input #1, resp2
Loop
Print #2, resp2
resp3 = "0"
Do While resp3 = "0"
Input #1, resp3
Loop
Print #2, resp3
End Sub


I should ad (not sure how freebasic works) but this current code opens in a dos window, I am wanting to use a regular windows interface to add buttons etc.

Thank you,

I do have an old Automotive scanner that I was able to port some code from to connect to the ECU.
It is the following code that I am having a hard time converting

Open "hack.txt" For Output As #2
input "enter start number (add &h at the beginning for a hex #)"; x
Print "starting at "; Hex(x)
x = Int(x)
If x < 0 Then GoTo FinishThat
If x > 65535 Then GoTo FinishThat
Print #2, "seed key tryer"
Print #2, "starting at "; Hex(x)
Print #1, "atz"
getreply()
sleep 2500
Print #1, "at sh 6c 10 f1"
getreply()
x = x + &H27020000
sleep 350
MainLoop:
Print #1, "27 01"
sleep 500
getreply()
Print #1, Hex(x)
sleep 500
getreply()
If resp2 = "67 02 34 " Then GoTo FinishThis
If resp2 = "67 02 37 " Then x = x - 1
Print #2, Hex(x)
Print #2, resp2
x = x + 1
If x = &H27030000 Then GoTo FinishThat
Print #1, "27 01"
sleep 500
getreply()
Print #1, Hex(x)
sleep 500
getreply()
If resp2 = "67 02 34 " Then GoTo FinishThis
If resp2 = "67 02 37 " Then x = x - 1
x = x + 1
If x = &H27030000 Then GoTo FinishThat
sleep 11000
GoTo MainLoop

FinishThis:
x = x - &H27020000
Print #2, Hex(x); " this is your key"
Close #1
Close #2
End

FinishThat:
Print #2, "your key was not found"
Close #1

I understand some, but not all and am having issues getting started.

My current code is the following (I need to add the prev code now)

Private Sub cmd_findkey_Click()

' if already opened then close it
MSComm1.CommPort = cboComm
    If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
        
    MSComm1.Settings = "9600,N,8,1" ' 9600 baud, no parity, 8 data
                                                           ' and 1 stop bit
    MSComm1.InputLen = 0 ' Read entire buffer when Input
     
    ' Trigger the OnComm event whenever data is received
    MSComm1.RThreshold = 1
     
    MSComm1.PortOpen = True ' Open port

lstConnection.Text = lstConnection.Text & "Opening Com  " & MSComm1.CommPort & " Port" & vbCrLf
lstConnection.Text = lstConnection.Text & "Com Port " & MSComm1.CommPort & "  Open" & vbCrLf
SendMessage lstConnection.hWnd, WM_VSCROLL, SB_BOTTOM, 0

MSComm1.Output = "AT Z" & vbCrLf
'lstConnection.Text = lstConnection.Text & MSComm1.Output  <--- this is write only? how to print the MSComm output to test box?
    If (MSComm1.CommEvent = comEvReceive) Then
     '   Do
  '      Attente (250)
        
           MyStrg = MSComm1.Input
            
            lstConnection.Text = lstConnection.Text & MyStrg
        SendMessage lstConnection.hWnd, WM_VSCROLL, SB_BOTTOM, 0
        Else
    lstConnection.Text = lstConnection.Text & "No Response from ECU"
End If
Attente (1000)
Attente (1000)
MSComm1.Output = "AT E0" & vbCrLf

    If (MSComm1.CommEvent = comEvReceive) Then
     '   Do
  '      Attente (250)
        
           MyStrg = MSComm1.Input
            
            lstConnection.Text = lstConnection.Text & MyStrg
        SendMessage lstConnection.hWnd, WM_VSCROLL, SB_BOTTOM, 0
End If


        End If
End Sub

I am starting to get some, but not all,

Not quite sure what this is doing either?

Sub getreply()
resp1 = "0"
Do While resp1 = "0"
Input #1, resp1
Loop
Print #2, resp1
resp2 = "0"
Do While resp2 = "0"
Input #1, resp2
Loop
Print #2, resp2
resp3 = "0"
Do While resp3 = "0"
Input #1, resp3
Loop
Print #2, resp3
End Sub

I do figure that
print #1 sends out on mscomm1 and
print #2 writes to the text file ?

Any one able to help?

Having a guy help me with some code, however, he doesnt know VB6 and only has freebasic

I need to convert the following into VB6 so I can make a user interface (comport selection etc) but not sure how to do it.

Even a step in the correct direction would be great!

Much appreciated, thank you.


Dim resp1 As String
Dim resp2 As String
Dim resp3 As String
Dim x As uinteger

declare sub getreply()

Open Com "COM1:9600,N,8,1,CS0,DS0,DT" As #1
Open "progress.txt" For Output As #2
input "enter start number (add &h at the beginning for a hex #)"; x
Print "starting at "; Hex(x)
x = Int(x)
If x < 0 Then GoTo FinishThat
If x > 65535 Then GoTo FinishThat
Print #2, "seed key tryer"
Print #2, "starting at "; Hex(x)
Print #1, "atz"
getreply()
sleep 2500
Print #1, "at sh 6c 10 f1"
getreply()
x = x + &H27020000
sleep 350
MainLoop:
Print #1, "27 01"
sleep 500
getreply()
Print #1, Hex(x)
sleep 500
getreply()
If resp2 = "67 02 34 " Then GoTo FinishThis
If resp2 = "67 02 37 " Then x = x - 1
Print #2, Hex(x)
Print #2, resp2
x = x + 1
If x = &H27030000 Then GoTo FinishThat
Print #1, "27 01"
sleep 500
getreply()
Print #1, Hex(x)
sleep 500
getreply()
If resp2 = "67 02 34 " Then GoTo FinishThis
If resp2 = "67 02 37 " Then x = x - 1
x = x + 1
If x = &H27030000 Then GoTo FinishThat
sleep 11000
GoTo MainLoop

FinishThis:
x = x - &H27020000
Print #2, Hex(x); " this is your key"
Close #1
Close #2
End

FinishThat:
Print #2, "your key was not found"
Close #1
Close #2
End

Sub getreply()
resp1 = "0"
Do While resp1 = "0"
Input #1, resp1
Loop
Print #2, resp1
resp2 = "0"
Do While resp2 = "0"
Input #1, resp2
Loop
Print #2, resp2
resp3 = "0"
Do While resp3 = "0"
Input #1, resp3
Loop
Print #2, resp3
End Sub


I should ad (not sure how freebasic works) but this current code opens in a dos window, I am wanting to use a regular windows interface to add buttons etc.

Not sure if I can help. I have VS 2008. What are you trying to do? FYI I have been writing programs in Basic for about 20 yrs. What type of strings do your variables represent? Are they user inputs? or Information from a DB?

I will check back, daily. Hope I can help. You should put more documentation in your code. I went back to look a bit more and it seems you are getting user input. getreply() appears to be the function. What are you trying to do with that input?

joekbit

I am trying to find a key from a Cars Ecm with an Elm327 device on usb, basically keep trying new keys til one is correct, it is the getreply() and freebasic code I am not really understanding and trying to convert to VB6

So far this is what I have
send ATZ
get reply (not sure what all getreply() is doing )
print reply to textbox and a text file
send AT SH 6C 10 F1
get reply? and print to textbox and a text file
send 27 01
getreply print to textbox and a text file
send a Hex key (user defined from text)
getreply print to textbox and a text file
if reply is 67 02 34 then print to textbox and text file "this is your key" hexkey
if reply is 67 02 37 then send hexkey + 1
loop

That is the basic idea.

I am trying to find a key from a Cars Ecm with an Elm327 device on usb, basically keep trying new keys til one is correct, it is the getreply() and freebasic code I am not really understanding and trying to convert to VB6

So far this is what I have
send ATZ
get reply (not sure what all getreply() is doing )
print reply to textbox and a text file
send AT SH 6C 10 F1
get reply? and print to textbox and a text file
send 27 01
getreply print to textbox and a text file
send a Hex key (user defined from text)
getreply print to textbox and a text file
if reply is 67 02 34 then print to textbox and text file "this is your key" hexkey
if reply is 67 02 37 then send hexkey + 1
loop

That is the basic idea.

Well after doing a search I now see what you are trying to do. According to
http://www.autoditto.com/odbii-scan-tool-elm-327-scanner.html

there are a number of different protocols to correctly read from the scanner to a computer.
That is where you need to start. Does your system support any of the protos? The link above lists the dif protos. You should research them and the documentation related to your computer.

You will also notice they mention 3rd party software.

Here is a link that says the soft ware is free

http://scantool.imechatronics.com/downloads.htm

It has a full list of OS's, that is going to be your best bet. From there you may be able to get a better idea of what you should be seeing and reverse engeneer your code. If you really want to write it yourself.

Yes, my Elm uses the proper protocols
I am able to connect to vehicle and read info, I have even built a small automotive scanner.

I am trying to move on now, to getting the Seed/Key pair to be able to reprogram the Ecu

The freebasic code posted in first post works, however I am in need to convert to VB6 as that is what I made the scanner in and this next section will be part of that.

I think if I can grasp what the getreply() sub is doing, I will be able to convert the rest.

Sub getreply()
resp1 = "0"
Do While resp1 = "0"
Input #1, resp1
Loop
Print #2, resp1
resp2 = "0"
Do While resp2 = "0"
Input #1, resp2
Loop
Print #2, resp2
resp3 = "0"
Do While resp3 = "0"
Input #1, resp3
Loop
Print #2, resp3
End Sub

Anyone can help?

Well, I have been able to get the code commented on somewhat, now to covert to VB6

Dim resp1 As  String
Dim resp2 As String
Dim resp3 As String
Dim x As Uinteger

Declare Sub getreply()



x = Int(x)
If x < 0 Then Goto FinishThat        'exit if x < 0 or
If x > 65535 Then Goto FinishThat    'x > 65535

Print #2, "seed key tryer"           'print text to file
Print #2, "starting at "; Hex(x)     ' ' ' ' ' ' ' '

Print #1, "atz"   'sends: atz <0dh> <0ah> to serial port
'(<0dh> <0ah> = carriage return/line feed)

getreply() 'calls getreplay sub

Sleep 2500 'delay for 2.5 seconds

Print #1, "at sh 6c 10 f1" 'sends: at sh 6c 10 f1 <0dh> <0ah> to serial port

getreply() 'calls getreply sub

x = x + &H27020000 'adds &h27020000 to entered number

Sleep 350 'delay for 350 mSec

MainLoop:

Print #1, "27 01" 'sends: 27 01 <0dh> <0ah> to serial port

Sleep 500 'delay for .5 seconds

getreply() 'calls getreply sub

Print #1, Hex(x) ' send hex string of value x to serial port with <0dh> <0ah>

Sleep 500 'delay for .5 seconds

getreply() 'callse getreply sub

'check for specific responses
If resp2 = "67 02 34 " Then Goto FinishThis
If resp2 = "67 02 37 " Then x = x - 1
Print #2, Hex(x)
Print #2, resp2
x = x + 1
If x = &H27030000 Then Goto FinishThat
Print #1, "27 01"
Sleep 500
getreply()
Print #1, Hex(x)
Sleep 500
getreply()
If resp2 = "67 02 34 " Then Goto FinishThis
If resp2 = "67 02 37 " Then x = x - 1
x = x + 1
If x = &H27030000 Then Goto FinishThat
Sleep 11000
Goto MainLoop

FinishThis:
x = x - &H27020000
Print #2, Hex(x); " this is your key"
Close #1
Close #2
End

FinishThat:
Print #2, "your key was not found"
Close #1
Close #2
End

Sub getreply()
   
resp1 = "0"          'set resp1 to the string "0"
Do While resp1 = "0" 'while the string hasn't changed
Input #1, resp1      'get input from serial port into resp1
Loop
Print #2, resp1      'output the resonse to a file

resp2 = "0"          'repeat the previous routine
Do While resp2 = "0"
Input #1, resp2      'get input from serial port into resp2
Loop
Print #2, resp2

resp3 = "0"          'repeat the previous routine
Do While resp3 = "0"
Input #1, resp3      'get input from serial port into resp3
Loop
Print #2, resp3
End Sub

I see you have posted at the freebasic.net. That may be your best bet for this.

Let me see if I have this right. The ELM uses freeebasic programming. Is it working correct? If it is then all you need to do is open / read the information stored on the elm if it has a hard memory so to speak. The actual code it uses is irrelivent. The only thing you need to know is how or what type of file format it stores that information in. With that you can write code in VB6 to read the file. I would imagine, but I may not be correct, it is likely a simple txt format. I say this because they have no real GUI's just a simple text output screen and possibly a printer similar to a cash register.

Just throwing out some ideas. You may want to call the company and ask.

The elm device then communicates to the Car(elm device in generic, no software for it) I have another program that I made to scan the automotive data, I am now trying to find the hidden key.

this is what I have so far,but instead of adding one it just sends the number 1, then number 2 then 3 etc?

fKey = "&H" + txtKeyStart.Text
Do
 MSComm1.Output = fKey & vbCrLf

Attente (1000)
    If (MSComm1.CommEvent = comEvReceive) Then

  '      Attente (250)
        
           MyStrg = MSComm1.Input
            
            lstConnection.Text = lstConnection.Text & MyStrg
        SendMessage lstConnection.hWnd, WM_VSCROLL, SB_BOTTOM, 0
      If MyStrg = "67 02 34" Then
      corrkey = 1
      lstConnection.Text = lstConnection.Text & "Your Key Is " & fKey & vbCrLf
      Else
     lstConnection.Text = lstConnection.Text & "Incorrect Key Tried " & fKey & vbCrLf
      fKey = Val(fKey)
      lstConnection.Text = lstConnection.Text & "test " & fKey & vbCrLf
      fKey = fKey + 1
      lstConnection.Text = lstConnection.Text & "test " & fKey & vbCrLf
      fKey = Hex(fKey)
      lstConnection.Text = lstConnection.Text & "Trying Key " & fKey & vbCrLf
      SendMessage lstConnection.hWnd, WM_VSCROLL, SB_BOTTOM, 0
      End If
      
        End If
        
        
Loop While corrkey = 0

What I am having issue with right now is looping, I send Hex data, if it fails (which it will everytime without the device connected) I need to subtract 1 from the Hex and retry.

Basically this is what I need to do (if someone can help me start then I can customize it later)

User inputs Hex (txtKeyStart.Text example FFFE )
Fkey = txtKeyStart.Text
Make Hex Integer
Check to be sure Integer is between 0 and 65535
Add &H27020000

Send Hex

MSComm1.Output = fKey & vbCrLf


    If (MSComm1.CommEvent = comEvReceive) Then

 
        
           MyStrg = MSComm1.Input
            
            result.Text =  MyStrg

      If MyStrg = "67 02 34" Then   ' SUCCESS ANYTHING ELSE INCLUDING ERROR GOTO ELSE

Else
' Subtract 1 from Fkey resend and loop till 67 02 34 is Returned (which if you do not have the Device it never will, but can test the loop code.

Maybe If I attach what I have it will make it easier to understand what I am trying to do.

It is pretty messy right now, as I have been hacking away at it to try and fix, seem to make it worse, a lot of the printing to textbox is just so I can see what is happening for debugging.

Ok, I have figured out some more,
Its not that I need to add &H27020000 to the fKey, I need to have 27 02 befor fKey

so if fKey is FF FE I need to send 27 02 FF FE

Starting to understand it a bit more :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.