welshwizard
06-11-2002, 10:19 PM
I found these @ http://www.vbforums.com/ (i assume i can say that as it is not a competing gsm/nokia forum).
need to output to com port
after reading loads of pages about how to use mscomm from here, i see it is really needed what you are outputting to etc to get real help
basically i need to output:
1F 00 10 40 00 04 00 01 6E 01 34 11 b7
followed by:
1F 00 10 7F 05
to com1 which is connected by m bus data cable to a Nokia phone. the phone will then return some data which i want displayed in a text box.
so far i managed to write:
code:--------------------------------------------------------------------------------Private Sub Command1_Click()
MSComm1.PortOpen = True
MSComm1.Output = "1F 00 10 40 00 04 00 01 6E 01 34 11 b7"
For i = 1 To 1000
Next i
MSComm1.Output = "1F 00 10 7F 05"
For i = 1 To 1000
Next i
Text1.Text = (MSComm1.Input)
End Sub
Private Sub MSComm1_OnComm()
MSComm1.Settings = "9600,o,8,1"
MSComm1.RTSEnable = True
MSComm1.DTREnable = False
MSComm1.PortOpen = False
End Sub--------------------------------------------------------------------------------
which does output (tested with portmon) but i get no input
also some source to do the same kind of thing (but outputting different m bus commands) i have is:
code:--------------------------------------------------------------------------------MSComm1.Settings = "9600,o,8,1"
MSComm1.RTSEnable = True
MSComm1.DTREnable = False
MSComm1.PortOpen = True
'hier is het test mode
thex ("1F 00 10 40 00 04 00 01 64 02 31 1D")
pause (100)
thex ("1F 00 10 7F 02")
MSComm1.PortOpen = False
MSComm1.PortOpen = True
thex ("1F 00 10 40 00 04 00 01 64 02 31 1D")
pause (100)
thex ("1F 00 10 7F 02")
MSComm1.PortOpen = False
'version bilgisi
MSComm1.PortOpen = True
buffer2$ = ""
thex ("1F 00 10 D1 00 05 00 01 00 03 00 32 EB")
pause (100)
thex ("1F 00 10 7F 03")
pause (100)
buffer2$ = ""
Do
DoEvents
buffer2$ = buffer2$ & MSComm1.Input
temp = Len(buffer2$)
If temp < 54 Then temp = 54
If temp = 54 Then GoTo erro
Loop While temp < 54
j = 1
For i = 1 To temp
arrayhex(j) = Mid(buffer2$, i, 1)
temp_ = arrayhex(j)
arraynum(j) = Asc(arrayhex(j))
j = j + 1
Next i
For i = 1 To temp
leitura1 = leitura1 + arrayhex(i)
Next i
geral = Mid(leitura1, 30, 31)
Text1 = geral
versao = Mid(leitura1, 30, 7)
Text2 = versao
tipo = Mid(leitura1, 47, 5)
Text3 = tipo
MSComm1.PortOpen = False
pause (100)
MSComm1.PortOpen = True
'Imei vragen
thex ("1F 00 10 40 00 03 00 01 66 33 18")
pause (100)
thex ("1F 00 10 7F 04")
pause (100)
buffer2$ = ""
Do
DoEvents
buffer2$ = buffer2$ & MSComm1.Input
temp = Len(buffer2$)
Loop While temp < 45
j = 1
For i = 1 To temp
arrayhex(j) = Mid(buffer2$, i, 1)
arraynum(j) = Asc(arrayhex(j))
j = j + 1
Next i
For i = 1 To temp
leitura2 = leitura2 + arrayhex(i)
Next i
imei = Mid(leitura2, 28, 6) + "-" + Mid(leitura2, 34, 2) + "-" +
Mid(leitura2, 37, 6) + "-" + Mid(leitura2, 42, 1)
Text4 = imei
MSComm1.PortOpen = False
pause (400)
MSComm1.PortOpen = True
'security code lezen
thex ("1F 00 10 40 00 04 00 01 6E 01 34 11 b7")
encrypt:
pause (100)
thex ("1F 00 10 7F 05")
pause (100)
Do
DoEvents
buffer2$ = ""
buffer2$ = buffer2$ & MSComm1.Input
temp = Len(buffer2$)
Loop While temp < 1
j = 1
For i = 1 To temp
arrayhex(j) = Mid(buffer2$, i, 1)
temp_ = arrayhex(j)
arraynum(j) = Asc(arrayhex(j))
j = j + 1
Next i
For i = 1 To temp
leitura3 = leitura3 + arrayhex(i)
Next i
lockcode = Mid(leitura3, 31, 5)
Text5 = lockcode
MSComm1.PortOpen = False
pause (300)
MSComm1.PortOpen = True
'level lezen (security l1.l2.l3.l4)
thex ("1F 00 10 40 00 04 00 01 8A 00 13 d3")
pause (100)
thex ("1F 00 10 7F 07")
buffer2$ = ""
buffer2$ = ""
Do
DoEvents
buffer2$ = buffer2$ & MSComm1.Input
temp = Len(buffer2$)
Loop While temp < 1
j = 1
For i = 1 To temp
arrayhex(j) = Mid(buffer2$, i, 1)
temp_ = arrayhex(j)
arraynum(j) = Asc(arrayhex(j))
j = j + 1
Next i
For i = 1 To temp
teste1 = Hex(arraynum(i))
If teste1 = "0" Then teste1 = "0" + teste1
If teste1 = "1" Then teste1 = "0" + teste1
If teste1 = "2" Then teste1 = "0" + teste1
If teste1 = "3" Then teste1 = "0" + teste1
If teste1 = "4" Then teste1 = "0" + teste1
If teste1 = "5" Then teste1 = "0" + teste1
If teste1 = "6" Then teste1 = "0" + teste1
If teste1 = "7" Then teste1 = "0" + teste1
If teste1 = "8" Then teste1 = "0" + teste1
If teste1 = "9" Then teste1 = "0" + teste1
If teste1 = "A" Then teste1 = "0" + teste1
If teste1 = "B" Then teste1 = "0" + teste1
If teste1 = "C" Then teste1 = "0" + teste1
If teste1 = "D" Then teste1 = "0" + teste1
If teste1 = "E" Then teste1 = "0" + teste1
If teste1 = "F" Then teste1 = "0" + teste1
leitura4 = leitura4 + teste1
Next i
locks = Mid(leitura4, 61, 2)
locks = Val("&h" + locks)
lockss = dec2bin(locks)
If lockss = "0" Then lockss = "0000"
If lockss = "1" Then lockss = "0001"
If lockss = "10" Then lockss = "0010"
If lockss = "11" Then lockss = "0011"
If lockss = "100" Then lockss = "0100"
If lockss = "101" Then lockss = "0101"
If lockss = "110" Then lockss = "0110"
If lockss = "111" Then lockss = "0111"
za = Len(lockss)
lock1 = Mid(lockss, za, 1)
lock2 = Mid(lockss, za - 1, 1)
lock3 = Mid(lockss, za - 2, 1)
lock4 = Mid(lockss, za - 3, 1)
If lock1 = 1 Then lock11 = "close"
If lock1 = 0 Then lock11 = "Open"
If lock2 = 1 Then lock22 = "close"
If lock2 = 0 Then lock22 = "Open"
If lock3 = 1 Then lock33 = "close"
If lock3 = 0 Then lock33 = "Open"
If lock4 = 1 Then lock44 = "close"
If lock4 = 0 Then lock44 = "Open"
Text6.SelText = "Lock 1 ...................................... " +
lock11 &
vbCrLf
pause (200)
Text6.SelText = "Lock 2 ...................................... " +
lock22 &
vbCrLf
pause (200)
Text6.SelText = "Lock 3 ...................................... " +
lock33 &
vbCrLf
pause (200)
Text6.SelText = "Lock 4 ...................................... " +
lock44 &
vbCrLf
MSComm1.PortOpen = False
pause (300)
MSComm1.PortOpen = True
' reset phone
thex ("1F 00 10 40 00 04 00 01 64 03 42 6F")
pause (100)
thex ("1F 00 10 7F 1C")
pause (100)
MSComm1.PortOpen = False--------------------------------------------------------------------------------
but i dont know what thex and pause are for plus some of the stuff makes no sense to me as i only been learning for a few days i put a loop as pause but dont know if thats correct.
any help would be nice
need to output to com port
after reading loads of pages about how to use mscomm from here, i see it is really needed what you are outputting to etc to get real help
basically i need to output:
1F 00 10 40 00 04 00 01 6E 01 34 11 b7
followed by:
1F 00 10 7F 05
to com1 which is connected by m bus data cable to a Nokia phone. the phone will then return some data which i want displayed in a text box.
so far i managed to write:
code:--------------------------------------------------------------------------------Private Sub Command1_Click()
MSComm1.PortOpen = True
MSComm1.Output = "1F 00 10 40 00 04 00 01 6E 01 34 11 b7"
For i = 1 To 1000
Next i
MSComm1.Output = "1F 00 10 7F 05"
For i = 1 To 1000
Next i
Text1.Text = (MSComm1.Input)
End Sub
Private Sub MSComm1_OnComm()
MSComm1.Settings = "9600,o,8,1"
MSComm1.RTSEnable = True
MSComm1.DTREnable = False
MSComm1.PortOpen = False
End Sub--------------------------------------------------------------------------------
which does output (tested with portmon) but i get no input
also some source to do the same kind of thing (but outputting different m bus commands) i have is:
code:--------------------------------------------------------------------------------MSComm1.Settings = "9600,o,8,1"
MSComm1.RTSEnable = True
MSComm1.DTREnable = False
MSComm1.PortOpen = True
'hier is het test mode
thex ("1F 00 10 40 00 04 00 01 64 02 31 1D")
pause (100)
thex ("1F 00 10 7F 02")
MSComm1.PortOpen = False
MSComm1.PortOpen = True
thex ("1F 00 10 40 00 04 00 01 64 02 31 1D")
pause (100)
thex ("1F 00 10 7F 02")
MSComm1.PortOpen = False
'version bilgisi
MSComm1.PortOpen = True
buffer2$ = ""
thex ("1F 00 10 D1 00 05 00 01 00 03 00 32 EB")
pause (100)
thex ("1F 00 10 7F 03")
pause (100)
buffer2$ = ""
Do
DoEvents
buffer2$ = buffer2$ & MSComm1.Input
temp = Len(buffer2$)
If temp < 54 Then temp = 54
If temp = 54 Then GoTo erro
Loop While temp < 54
j = 1
For i = 1 To temp
arrayhex(j) = Mid(buffer2$, i, 1)
temp_ = arrayhex(j)
arraynum(j) = Asc(arrayhex(j))
j = j + 1
Next i
For i = 1 To temp
leitura1 = leitura1 + arrayhex(i)
Next i
geral = Mid(leitura1, 30, 31)
Text1 = geral
versao = Mid(leitura1, 30, 7)
Text2 = versao
tipo = Mid(leitura1, 47, 5)
Text3 = tipo
MSComm1.PortOpen = False
pause (100)
MSComm1.PortOpen = True
'Imei vragen
thex ("1F 00 10 40 00 03 00 01 66 33 18")
pause (100)
thex ("1F 00 10 7F 04")
pause (100)
buffer2$ = ""
Do
DoEvents
buffer2$ = buffer2$ & MSComm1.Input
temp = Len(buffer2$)
Loop While temp < 45
j = 1
For i = 1 To temp
arrayhex(j) = Mid(buffer2$, i, 1)
arraynum(j) = Asc(arrayhex(j))
j = j + 1
Next i
For i = 1 To temp
leitura2 = leitura2 + arrayhex(i)
Next i
imei = Mid(leitura2, 28, 6) + "-" + Mid(leitura2, 34, 2) + "-" +
Mid(leitura2, 37, 6) + "-" + Mid(leitura2, 42, 1)
Text4 = imei
MSComm1.PortOpen = False
pause (400)
MSComm1.PortOpen = True
'security code lezen
thex ("1F 00 10 40 00 04 00 01 6E 01 34 11 b7")
encrypt:
pause (100)
thex ("1F 00 10 7F 05")
pause (100)
Do
DoEvents
buffer2$ = ""
buffer2$ = buffer2$ & MSComm1.Input
temp = Len(buffer2$)
Loop While temp < 1
j = 1
For i = 1 To temp
arrayhex(j) = Mid(buffer2$, i, 1)
temp_ = arrayhex(j)
arraynum(j) = Asc(arrayhex(j))
j = j + 1
Next i
For i = 1 To temp
leitura3 = leitura3 + arrayhex(i)
Next i
lockcode = Mid(leitura3, 31, 5)
Text5 = lockcode
MSComm1.PortOpen = False
pause (300)
MSComm1.PortOpen = True
'level lezen (security l1.l2.l3.l4)
thex ("1F 00 10 40 00 04 00 01 8A 00 13 d3")
pause (100)
thex ("1F 00 10 7F 07")
buffer2$ = ""
buffer2$ = ""
Do
DoEvents
buffer2$ = buffer2$ & MSComm1.Input
temp = Len(buffer2$)
Loop While temp < 1
j = 1
For i = 1 To temp
arrayhex(j) = Mid(buffer2$, i, 1)
temp_ = arrayhex(j)
arraynum(j) = Asc(arrayhex(j))
j = j + 1
Next i
For i = 1 To temp
teste1 = Hex(arraynum(i))
If teste1 = "0" Then teste1 = "0" + teste1
If teste1 = "1" Then teste1 = "0" + teste1
If teste1 = "2" Then teste1 = "0" + teste1
If teste1 = "3" Then teste1 = "0" + teste1
If teste1 = "4" Then teste1 = "0" + teste1
If teste1 = "5" Then teste1 = "0" + teste1
If teste1 = "6" Then teste1 = "0" + teste1
If teste1 = "7" Then teste1 = "0" + teste1
If teste1 = "8" Then teste1 = "0" + teste1
If teste1 = "9" Then teste1 = "0" + teste1
If teste1 = "A" Then teste1 = "0" + teste1
If teste1 = "B" Then teste1 = "0" + teste1
If teste1 = "C" Then teste1 = "0" + teste1
If teste1 = "D" Then teste1 = "0" + teste1
If teste1 = "E" Then teste1 = "0" + teste1
If teste1 = "F" Then teste1 = "0" + teste1
leitura4 = leitura4 + teste1
Next i
locks = Mid(leitura4, 61, 2)
locks = Val("&h" + locks)
lockss = dec2bin(locks)
If lockss = "0" Then lockss = "0000"
If lockss = "1" Then lockss = "0001"
If lockss = "10" Then lockss = "0010"
If lockss = "11" Then lockss = "0011"
If lockss = "100" Then lockss = "0100"
If lockss = "101" Then lockss = "0101"
If lockss = "110" Then lockss = "0110"
If lockss = "111" Then lockss = "0111"
za = Len(lockss)
lock1 = Mid(lockss, za, 1)
lock2 = Mid(lockss, za - 1, 1)
lock3 = Mid(lockss, za - 2, 1)
lock4 = Mid(lockss, za - 3, 1)
If lock1 = 1 Then lock11 = "close"
If lock1 = 0 Then lock11 = "Open"
If lock2 = 1 Then lock22 = "close"
If lock2 = 0 Then lock22 = "Open"
If lock3 = 1 Then lock33 = "close"
If lock3 = 0 Then lock33 = "Open"
If lock4 = 1 Then lock44 = "close"
If lock4 = 0 Then lock44 = "Open"
Text6.SelText = "Lock 1 ...................................... " +
lock11 &
vbCrLf
pause (200)
Text6.SelText = "Lock 2 ...................................... " +
lock22 &
vbCrLf
pause (200)
Text6.SelText = "Lock 3 ...................................... " +
lock33 &
vbCrLf
pause (200)
Text6.SelText = "Lock 4 ...................................... " +
lock44 &
vbCrLf
MSComm1.PortOpen = False
pause (300)
MSComm1.PortOpen = True
' reset phone
thex ("1F 00 10 40 00 04 00 01 64 03 42 6F")
pause (100)
thex ("1F 00 10 7F 1C")
pause (100)
MSComm1.PortOpen = False--------------------------------------------------------------------------------
but i dont know what thex and pause are for plus some of the stuff makes no sense to me as i only been learning for a few days i put a loop as pause but dont know if thats correct.
any help would be nice