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
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.
[code=thinbasic]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[/code]
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
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
Exactly, I was just replying about that
Change from
[code=thinbasic]COMM_Open( 2, hcomm )[/code]
to
[code=thinbasic]COMM_Open( "COM2", hcomm )[/code]
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
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Can I also suggest you open the port then set the settings.
replace FALSE with %FALSE.
Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370
Michael,
setting must be set before opening the port as stated in help file: COMM_Open
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
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Hate to tell you guys, but even setting the parameters after opening the port, it still works. I will change it, however.
Rick
Eros in the PB help it doesnt state the parameters must be set before opening a port, it only states no comms is allowed.
Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370
Michael,
you are right:I confused it with port opening."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 will amend thinBasic help
Thanks
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Bookmarks