PDA

View Full Version : Cannot get COMM to receive



fgasoi
17-02-2010, 22:20
Folks;

I have an application where I have to read data being sent by a gas turbine controller. It is at 4800 baud, 8N1 with no flow control. My main script is not working, so I tried something simpler, but it does not work either. I am hooked up for testing to another PC running Hyperterminal so I can send one character at a time from the keyboard - I just want to see my program echo, and it does not. Here is the code. (I put in an escape via the local keyboard.) The error code displayed is zero.


USES "CONSOLE"
USES "COMM"

DIM hcomm AS long
DIM NBytes AS long
DIM InBuff AS STRING

'---Get Comms file number and assign

hcomm = COMM_FREEFILE

'---Set up all comms parameters

COMM_SET( hcomm, %COMM_BAUD, 4800 )
COMM_SET( hcomm, %COMM_BYTE, 8 )
COMM_SET( hcomm, %COMM_NULL, FALSE )
COMM_SET( hcomm, %COMM_PARITY, FALSE )
COMM_SET( hcomm, %COMM_PARITYTYPE, 0 )
COMM_SET( hcomm, %COMM_STOP, 0 )
COMM_SET( hcomm, %COMM_RXBUFFER, 64 )

'---Open the port

COMM_OPEN( 2, hcomm )

console_printat("ERROR = " & err, 30, 6)
DO
NBytes = COMM_Get(hComm, %comm_RXQUE)
COMM_recv(hComm, nBytes, InBuff)
console_printat(InBuff, 20, 10)
IF LEN( CONSOLE_INKEYB ) > 0 THEN 'Allow any key to abort
CONSOLE_CLS
CONSOLE_PRINTAT( "ABORTED", 37, 12 )
CONSOLE_WAITKEY( 3 )
COMM_CLOSE( hcomm )
STOP
ENDIF
LOOP

Thanks for any help. The debugger does not allow me to look at the RXBUFFER so I don't know how far it is getting, but Hyperterminal receives my sent data properly.

Rick

fgasoi
17-02-2010, 22:26
Sorry people - I just found it. Not really obvious from the help pages, but of course the com port has to say "COM2" rather than just 2.

Rick

ErosOlmi
17-02-2010, 22:36
Exactly, I was just replying about that ;)

Change from

COMM_Open( 2, hcomm )
to

COMM_Open( "COM2", hcomm )

Also, possibly, if you have to post some thinBasic or other languages source code surround the source code wit code UBB code tag or better use the combobox just above the posting area called "Syntax highlight (geShi)" and it will insert code tags for you.

Ciao
Eros

Michael Clease
17-02-2010, 22:43
Can I also suggest you open the port then set the settings.

replace FALSE with %FALSE.

ErosOlmi
17-02-2010, 22:47
Michael,

setting must be set before opening the port as stated in help file: COMM_Open (http://www.thinbasic.com/public/products/thinBasic/help/html/comm_open.htm)
This is a must.

%FALSE and FALSE are in thinBasic synonymous. I'm too used to always type %FALSE but they are the same.

Eros

fgasoi
17-02-2010, 23:44
Hate to tell you guys, but even setting the parameters after opening the port, it still works. I will change it, however.

Rick

Michael Clease
18-02-2010, 02:09
Eros in the PB help it doesnt state the parameters must be set before opening a port, it only states no comms is allowed.

ErosOlmi
18-02-2010, 08:51
Michael,

you are right:
"Set the parameters needed to communicate with a serial port. This must always be done before you can send and receive data through the port"

I confused it with port opening.
I will amend thinBasic help

Thanks
Eros