Post by monini64 on Oct 2, 2018 19:27:57 GMT -5
this is a very small program, this is a kwp2000 fast init
'Open the port briefly using an API call to determine the handle given by Windows
'We will use this handle later in Liberty, its the only way to get it.
'substitute your own port number
lpFileName$ = "Com1"
dwCreationDistribution = _OPEN_EXISTING
hTemplateFile = _NULL
dwFlagsAndAttributes=_FILE_FLAG_OVERLAPPED
dim comandos$(21)
comandos$(1)="818cf1817F"
comandos$(2)="828CF1108190"
comandos$(3)="828CF110FA09"
comandos$(4)="828CF127FA20"
comandos$(5)="868cf127fb06cfdd"
comandos$(6)="828CF1212040"
comandos$(7)="828CF1212B4B"
comandos$(8)="828CF1213C5C"
comandos$(9)="828CF12182A2"
comandos$(10)="828CF12183A3"
comandos$(11)="828CF12190B0"
comandos$(12)="828CF121C0E0"
comandos$(13)="828CF121F010"
comandos$(14)="828CF1A191AA"
comandos$(15)="828CF11A92AB"
comandos$(16)="828CF11A93AC"
comandos$(17)="828CF196AF"
comandos$(18)="828CF11A97B0"
comandos$(19)="828CF11A98B1"
comandos$(20)="828CF11A99B2"
comandos$(21)="818CF18280"
DATA 7,6,6,10,9,60,39,8,12,10,23,12,23,17,17,7,12,11,16,10,5
'en c
'HANDLE WINAPI CreateFile(
' _In_ LPCTSTR lpFileName,
' _In_ DWORD dwDesiredAccess,
' _In_ DWORD dwShareMode,
' _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
' _In_ DWORD dwCreationDisposition,
' _In_ DWORD dwFlagsAndAttributes,
' _In_opt_ HANDLE hTemplateFile
');
calldll #kernel32, "CreateFileA", _
lpFileName$ as ptr, _
dwDesiredAccess as ulong, _
dwShareMode as ulong, _
lpSecurityAttributes as ulong, _
dwCreationDistribution as ulong, _
dwFlagsAndAttributes as ulong, _
hTemplateFile as ulong, _
hFileHandle as ulong
'in c
'BOOL WINAPI CloseHandle(
' _In_ HANDLE hObject
');
calldll #kernel32, "CloseHandle", _
hFileHandle as ulong, _
result as long
'OMMTIMEOUTS timeouts = { 0 };
'timeouts.ReadIntervalTimeout = 50; // in milliseconds
'timeouts.ReadTotalTimeoutConstant = 50; // in milliseconds
'timeouts.ReadTotalTimeoutMultiplier = 10; // in milliseconds
'timeouts.WriteTotalTimeoutConstant = 50; // in milliseconds
'timeouts.WriteTotalTimeoutMultiplier = 10; // in milliseconds
'hFileHandle now contains
'the #handle, a number, that identifies the port
'*********************************************************************************************************
'Opens a handle to a communications device.
open lpFileName$;":10400,n,8,1,ds0,cs0,rs" for random as #hFileHandle
'************************ INICIALIZACION *****************************************
CALLDLL #kernel32, "EscapeCommFunction", hFileHandle as ulong, _SETBREAK as long,_
result as long
'delay here, either a while wend loop to get 25ms or
CallDLL #kernel32, "SleepEx",25 As ULong,false as long,ret As Void
CALLDLL #kernel32, "EscapeCommFunction", hFileHandle as ulong, _CLRBREAK as long,_
result as long
CallDLL #kernel32, "SleepEx",25 As ULong,false as long,ret As Void
FOR numerodelectura=1 to 21
read bytesleer
call escribircomando numerodelectura
dataRead$ = input$(#hFileHandle, lof(#hFileHandle))
call recibirbytes bytesleer
next numerodelectura
goto [end]
sub espera
CallDLL #kernel32, "Sleep",25 As ULong,ret As Void
CallDLL #kernel32, "Sleep",25 As ULong,ret As Void
CallDLL #kernel32, "Sleep",25 As ULong,ret As Void
CallDLL #kernel32, "Sleep",25 As ULong,ret As Void
CallDLL #kernel32, "Sleep",25 As ULong,ret As Void
CallDLL #kernel32, "Sleep",25 As ULong,ret As Void
CallDLL #kernel32, "Sleep",25 As ULong,ret As Void
CallDLL #kernel32, "Sleep",25 As ULong,ret As Void
end sub
sub control
for a = 1 to len(dataRead$)
print dechex$(asc(mid$(dataRead$,a,1)))
next a
end sub
sub recibirbytes numerosbytes
control = 0
While lof(#hFileHandle)=0 or lof(#hFileHandle)<numerosbytes
control = control +1
if control=150000 then goto [break11]
wend
[break11]
print control,lof(#hFileHandle)
dataRead$ = input$(#hFileHandle,lof(#hFileHandle))
print "************************ control primer mensaje ***********************************"
for a = 1 to len(dataRead$)
print dechex$(asc(mid$(dataRead$,a,1)))
next a
end sub
sub escribircomando numeroCOMANDO
A=len(comandos$(numeroCOMANDO))
' mid$(string$, poscision, cantidad)
for posicion=1 to A step 2
a$=mid$(comandos$(numeroCOMANDO),posicion,2)
print #hFileHandle, CHR$(hexdec(a$));
CallDLL #kernel32, "Sleep",8 As ULong,ret As Void
next posicion
end sub
[end]
close #hFileHandle
end
[fin]
end