I was messing around with serial communication today, I am
having a problem. I used the code below to open COM1, then I
connected on the other end with Hyper-Terminal. The program
below will not read anything I am typing on the other end. To
find out if it was the program, I tried using Hyper-Terminal on
both ends of the connection and it worked just fine... That
means it has to be the program, right!? What am I doing wrong:
$INCLUDE "C:\VTECH\INCS\WIN32API.INC"
GLOBAL Text AS ASCIIZ * 10000
GLOBAL BufferLength AS LONG
GLOBAL BytesRead AS LONG
GLOBAL ComEvent AS LONG
GLOBAL ComHandle AS LONG
FUNCTION OpenCom AS LONG
LOCAL TimeOuts AS CommTimeOuts
ComHandle = CreateFile("COM1", _
%GENERIC_READ OR %GENERIC_WRITE, _
BYVAL %NULL, _
BYVAL %NULL, _
%OPEN_EXISTING, _
BYVAL %NULL, _
BYVAL %NULL)
IF ComHandle = %INVALID_HANDLE_VALUE THEN STDOUT "Could not open COM1."
TimeOuts.ReadIntervalTimeout = 50
TimeOuts.ReadTotalTimeoutConstant = 300
i% = SetCommTimeouts(ComHandle, TimeOuts)
i% = PurgeComm(ComHandle, %PURGE_TXCLEAR)
i% = PurgeComm(ComHandle, %PURGE_RXCLEAR)
i% = SetCommMask(ComHandle, %EV_RXCHAR)
END FUNCTION
FUNCTION PBMAIN AS LONG
OpenCom
BufferLength = 8000
DO WHILE INKEY$ = ""
IF ReadFile(ComHandle, Text, BufferLength, BytesRead, BYVAL %NULL) THEN
IF LEN(Text) > 0 THEN
Text = LEFT$(Text, BytesRead)
STDOUT Text;
END IF
END IF
LOOP
CloseHandle ComHandle
END FUNCTION
------------------
having a problem. I used the code below to open COM1, then I
connected on the other end with Hyper-Terminal. The program
below will not read anything I am typing on the other end. To
find out if it was the program, I tried using Hyper-Terminal on
both ends of the connection and it worked just fine... That
means it has to be the program, right!? What am I doing wrong:
$INCLUDE "C:\VTECH\INCS\WIN32API.INC"
GLOBAL Text AS ASCIIZ * 10000
GLOBAL BufferLength AS LONG
GLOBAL BytesRead AS LONG
GLOBAL ComEvent AS LONG
GLOBAL ComHandle AS LONG
FUNCTION OpenCom AS LONG
LOCAL TimeOuts AS CommTimeOuts
ComHandle = CreateFile("COM1", _
%GENERIC_READ OR %GENERIC_WRITE, _
BYVAL %NULL, _
BYVAL %NULL, _
%OPEN_EXISTING, _
BYVAL %NULL, _
BYVAL %NULL)
IF ComHandle = %INVALID_HANDLE_VALUE THEN STDOUT "Could not open COM1."
TimeOuts.ReadIntervalTimeout = 50
TimeOuts.ReadTotalTimeoutConstant = 300
i% = SetCommTimeouts(ComHandle, TimeOuts)
i% = PurgeComm(ComHandle, %PURGE_TXCLEAR)
i% = PurgeComm(ComHandle, %PURGE_RXCLEAR)
i% = SetCommMask(ComHandle, %EV_RXCHAR)
END FUNCTION
FUNCTION PBMAIN AS LONG
OpenCom
BufferLength = 8000
DO WHILE INKEY$ = ""
IF ReadFile(ComHandle, Text, BufferLength, BytesRead, BYVAL %NULL) THEN
IF LEN(Text) > 0 THEN
Text = LEFT$(Text, BytesRead)
STDOUT Text;
END IF
END IF
LOOP
CloseHandle ComHandle
END FUNCTION
------------------
Comment