Serial port

Serial port

Postby Marc Vanzegbroeck » Tue Apr 21, 2009 4:33 pm

Hi,

I want to open a COM4 port and want to send
Code: Select all  Expand view
++++.ATH0.ATZ.$10110000B8CF9D.


Than I have to wait for
Code: Select all  Expand view
$0511



I try with this code
Code: Select all  Expand view
function test()

local cDcb, nBytes
local nComm := OpenComm( 'COM4', 2400, 128 )
local nError

msginfo('1')
if ! BuildCommDcb( "COM4:2400,n,8,1", @cDcb )
nError = GetCommError( nComm )
Msgwait( " BuildCommDcb Error: " + Str( nError ),'',.3 )
endif

msginfo('2')
if ! SetCommState( cDcb )
nError = GetCommError( nComm )
Msgwait( "SetCommState Error: " + Str( nError ),'',.3 )
return .t.
endif

msginfo('3')
if ( nBytes := WriteComm( nComm, '++++.ATH0.ATZ.$10110000B8CF9D.') ) < 0
nError = GetCommError( nComm )
Msgwait( "WriteComm Error: " + Str( nError ),'',.1 )
else
Msgwait('Sent !!!',.1 )
endif

msginfo('4')
if FlushComm( nComm, 0 ) != 0
nError = GetCommError( nComm )
Msgwait( " FlushComm Error: " + Str( nError ),'',.01 )
endif

msginfo('5')
if ! CloseComm( nComm )
nError = GetCommError( nComm )
Msgwait( "CloseComm Error: " + Str( nError ),'',.01 )
endif

return nil
 


But the programs hangs after msginfo('2')

What can there be wrong?

Regards,
Marc
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Serial port

Postby yunbg1 » Tue Apr 28, 2009 5:30 am

if ! SetCommState( nComm, cDcb )

'cDcb' function check SetCommState.
FWH User
FWPPC User
FWLinux User
yunbg1
 
Posts: 107
Joined: Sun Nov 13, 2005 12:40 am
Location: Winnipeg Canada


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 105 guests