OK, This is driving me nuts. I'm trying to set up communications on a serial port. I have a device that is sending SLIP encoded 43 byte packets every 200ms (from what I can tell, there is no flow control). To initialize communications, I do this:

.data
szCom1 db "COM1",0
hPort:DWORD
PortBuffer db 100 dup (?)
.code
invoke CreateFile,addr szCom1,GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL
mov    hPort,eax
invoke GetCommState,hPort,addr DCBold
mov    DCBold.BaudRate,9600
mov    DCBold.ByteSize,8
mov    DCBold.Parity,NOPARITY
mov    DCBold.StopBits,ONESTOPBIT
invoke SetCommState,hPort,addr DCBold
invoke SetupComm,hPort,100,100
To read the data, I'm using a timer set to 500ms. and on the WM_TIMER message, I do this:

LOCAL nBytes:DWORD

invoke ReadFile,hPort,addr PortBuffer,100,addr nBytes,NULL
End result... I get nothing ! ReadFile returns 1 and no bytes read. According to the SDK, this indicates that the file pointer is past the end of the file. I don't understand this, but I then tried:

invoke SetFilePointer,hPort,0,NULL,FILE_BEGIN
and got INVALID_SET_FILE_POINTER (BTW not defined in Windows.inc v1.25) Ihave been all through the SDK in the communications section and tried almost all of the functions and am getting nowhere FAST ! Has anyone successfully used API functions with serial ports and could you please help me ? This message was edited by anon, on 3/13/2001 4:35:23 PM This message was edited by anon, on 3/13/2001 4:41:53 PM
Posted on 2001-03-13 15:32:00 by anon
I did some things with the serial port and had the effect, that I must read all bytes single (1 byte) in a loop. f.e. ReadFile ReadFile,hPort,addr PortBuffer,1,addr nBytes,NULL beaster
Posted on 2001-03-15 07:04:00 by beaster
Thanks for the reply :) As it turns out, my code was fine after setting CommTimeouts. The real problem was the device was defective and not sending any data to read. Don't you just love it ? Got a replacement and everything works now.
Posted on 2001-03-15 08:42:00 by anon