BBC BASIC for Windows
Programming >> Communication and Input/Output >> Serial Port and ESC code
http://bb4w.conforums.com/index.cgi?board=communication&action=display&num=1340743249

Serial Port and ESC code
Post by tuk091 on Jun 26th, 2012, 8:40pm

Hi All,
I am writing a control programme which uses Relays controled via a serial port. Unfortunately i am struggling to get the ESC code sent to the port. I am using a simple piece of code
k$=CHR$(27)
BPUTS#1,k$

Unfortuately when i use the esc code it does not seen to sent it to the port. If i change it to another character it works fine.

I know the basic RS232 port works as i have tested with test programme.

So i was just wondering if there was anything special i need to know to send an ESC code to the port.

Many thanks for any help in advance.

Regards

viv



Re: Serial Port and ESC code
Post by admin on Jun 26th, 2012, 9:24pm

on Jun 26th, 2012, 8:40pm, tuk091 wrote:
I am using a simple piece of code
k$=CHR$(27)
BPUTS#1,k$

That code will send two characters: an ESC (CHR$27) followed by a Line Feed (CHR$10). To send just a single ESC character you can use a numeric variable rather than a string:

Code:
      k=27
      BPUT#1,k 

which you can simplify as follows:

Code:
      BPUT #1,27 

or you can add a semicolon to your code to suppress the LF:

Code:
      k$=CHR$(27)
      BPUT#1,k$; 

Richard.
Re: Serial Port and ESC code
Post by tuk091 on Jun 26th, 2012, 10:03pm

Richard,
Many thanks i give that a try.

Regards

viv

Re: Serial Port and ESC code
Post by tuk091 on Jun 27th, 2012, 05:32am

Hi Richard
It fixed issue . Many thanks

Viv

Re: Serial Port and ESC code
Post by Designer on Jul 3rd, 2012, 12:12pm

Viv,

Hi.

Just starting out on BBC BASIC. Can you please share the test program code for sending and receiving a couple of bytes of data.

Regards

Zeb
Re: Serial Port and ESC code
Post by admin on Jul 3rd, 2012, 9:09pm

on Jul 3rd, 2012, 12:12pm, Designer wrote:
Can you please share the test program code for sending and receiving a couple of bytes of data.

Sending code something like:

Code:
      port% = OPENOUT("COM1:9600,n,8,1")
      BPUT #port%,dat1%
      BPUT #port%,dat2%
      CLOSE #port% 

Receiving code something like:

Code:
      port% = OPENIN("COM2:9600,n,8,1")
      dat1% = BGET#port%
      dat2% = BGET#port%
      CLOSE #port% 

This code waits for the data to arrive. If you need to be doing something else whilst waiting, you can monitor how many bytes have arrived using EXT#port% and only read them when they're ready.

Richard.
Re: Serial Port and ESC code
Post by Designer on Jul 5th, 2012, 07:09am

Richard.

Thanks. Will try it out and report.

Zeb