Hi!
I am trying to make a eeprom programmer - communication through COM port. But when i trying to read something from it - my app freezes :( and nothing happens. So if anyone could help me with working examples on how this can be achived I'll appreciate it. here what I've done so far:
OpenComPort proc num:DWORD
LOCAL hCom:DWORD
LOCAL buff[64]:BYTE
LOCAL dcb:DCB
LOCAL to:COMMTIMEOUTS
mov dcb.DCBlength,sizeof DCB
mov dcbold.DCBlength,sizeof DCB
invoke wsprintf,addr buff,offset opcpf,num
invoke CreateFile,addr buff,GENERIC_READ or GENERIC_WRITE,0,0,OPEN_EXISTING,0,0
mov hCom,eax
.if eax!=INVALID_HANDLE_VALUE
invoke lstrcat,addr buff,offset parf
invoke GetCommState,hCom,addr dcbold
invoke BuildCommDCB,addr buff,addr dcb
invoke SetCommState,hCom,addr dcb
invoke GetCommTimeouts,hCom,offset oldto
mov to.ReadIntervalTimeout,100 ;100 miliseconds between two characters
mov to.ReadTotalTimeoutMultiplier,150 ;150 for every byte to read
mov to.ReadTotalTimeoutConstant,150 ;+150 for every read operation
mov to.WriteTotalTimeoutMultiplier,250 ;250 for every byte to write
mov to.WriteTotalTimeoutConstant,250 ;+250 for every Write operation
invoke SetCommTimeouts,hCom,addr to
.else
push eax
invoke MessageBox,0,addr buff,0,MB_OK
pop eax
.endif
mov eax,hCom
ret
OpenComPort endp
CloseComPort proc hCom:DWORD
.if hCom!=INVALID_HANDLE_VALUE
invoke SetCommTimeouts,hCom,offset oldto
invoke SetCommState,hCom,offset dcbold
invoke CloseHandle,hCom
.endif
ret
CloseComPort endp
ComReadEprom proc portnum:DWORD
LOCAL hCom:DWORD
LOCAL buff[128]:BYTE
LOCAL xbuf[128]:BYTE
LOCAL _ins[8]:BYTE ;87h 23h PG OF 08
LOCAL dum:DWORD
invoke OpenComPort,portnum
mov hCom,eax
.if eax!=INVALID_HANDLE_VALUE
mov _ins,87h
mov _ins[1],23h
mov _ins[4],08h
xor cx,cx
.while cx<BINSIZE2
push ecx
mov _ins[2],ch
mov _ins[3],cl
invoke WriteFile,hCom,addr _ins,5,addr dum,0
.if eax!=0
invoke ReadFile,hCom,addr buff,10,addr dum,0
.if eax==0
pushad
invoke Bin2Hex,addr _ins,addr xbuf,10
invoke MessageBox,0,addr xbuf,0,MB_OK
popad
.endif
.endif
pop ecx
add cx,8
.endw
invoke CloseComPort,hCom
.endif
ret
ComReadEprom endp
Posted on 2001-08-23 10:40:43 by Yuk
Try to use a debugger to see where your program freeze.
Posted on 2001-08-24 07:32:52 by Dr. Manhattan