Comm port problem
Posted: Thu Nov 24, 2005 7:53 pm
I have a strange problem when reading from a comm port.
If I am starting with a fresh boo of the computer I can not read data from the comm port unless I first go into Windows HyperTerminal to read from the comm port. Then my program works just fine (until you reboot).
Below is a sample of the code I am using, can someone tell me what I am missing.
Thanks,
Jeff
***Open Comm Port
local cDcb, nBytes
local nComm := OpenComm( "Com"+alltrim(str(Config->Comm)), 1024, 128 )
if ! BuildCommDcb( "COM"+alltrim(str(Config->Comm))+":9600,n,8,1", @cDcb )
nError = GetCommError( nComm )
MsgInfo( "BuildCommDcb Error: " + Str( nError ) )
endif
if ! SetCommState( cDcb )
nError = GetCommError( nComm )
MsgInfo( "SetCommState Error: " + Str( nError ) )
endif
***Read Comm Port here
if ReadComm( nComm , @cDataRead) <> 0
**do my data storage here
endif
***Close Comm Port
if FlushComm( nComm, 0 ) != 0
nError = GetCommError( nComm )
MsgInfo( "FlushComm Error: " + Str( nError ) )
endif
if ! CloseComm( nComm )
nError = GetCommError( nComm )
MsgInfo( "CloseComm Error: " + Str( nError ) )
endif
If I am starting with a fresh boo of the computer I can not read data from the comm port unless I first go into Windows HyperTerminal to read from the comm port. Then my program works just fine (until you reboot).
Below is a sample of the code I am using, can someone tell me what I am missing.
Thanks,
Jeff
***Open Comm Port
local cDcb, nBytes
local nComm := OpenComm( "Com"+alltrim(str(Config->Comm)), 1024, 128 )
if ! BuildCommDcb( "COM"+alltrim(str(Config->Comm))+":9600,n,8,1", @cDcb )
nError = GetCommError( nComm )
MsgInfo( "BuildCommDcb Error: " + Str( nError ) )
endif
if ! SetCommState( cDcb )
nError = GetCommError( nComm )
MsgInfo( "SetCommState Error: " + Str( nError ) )
endif
***Read Comm Port here
if ReadComm( nComm , @cDataRead) <> 0
**do my data storage here
endif
***Close Comm Port
if FlushComm( nComm, 0 ) != 0
nError = GetCommError( nComm )
MsgInfo( "FlushComm Error: " + Str( nError ) )
endif
if ! CloseComm( nComm )
nError = GetCommError( nComm )
MsgInfo( "CloseComm Error: " + Str( nError ) )
endif