Pages: [1]   Go Down
Author Topic: Reading RS232, buffers, line feeds etc  (Read 926 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to read a single character from the RS232 port to turn on or off debug / interest features in my program.

Here's the code I am using:

Code:
if (Serial.available() > 0)
{
        // read the incoming byte:
       int incomingByte = Serial.read();

        if (incomingByte == 83)  // "S"
           // do something

        if (incomingByte == 115) // "s"
           // do something else
}

Now that works, BUT I have to type the character I want, followed by a carriage return.

What code can I use instead to just read a byte unbuffered so I don't need to type the carriage return?

On other platforms and devices I've used a getchar() function but I can't find anything similar for the arduino
           
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What code can I use instead to just read a byte unbuffered so I don't need to type the carriage return?
Nothing on the Arduino is going to affect the program on the PC that is sending the data.

Code:
        if (incomingByte == 83)  // "S"
Why? You got something against the much more intuitive
Code:
        if (incomingByte == 'S')
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using the Serial monitor built into the arduino programming environment.

Are you saying it is THAT that holds the data in a buffer and doesn't send it until you press enter?  Any way around that?

I've also tried with Windows Hyperterminal but I can't get that to work at all.  It receives data and displays it on the screen but any attempt to send characters to the arduino does not work, my program does not see any data and does nothing.

Any other suggestions.

Re the latter point, yes, stupid me I tend to miss the obvious sometimes.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Are you saying it is THAT that holds the data in a buffer and doesn't send it until you press enter?
Yes.

Quote
Any way around that?
Sure. Don't use the Serial Monitor.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, got it working now with Hyper terminal

It just bought back memories of just how rubbish hyper terminal is.  The problem was I had flow control set to hardware. And hyper terminal being a typical poorly written windoze application, it seems you can't edit the port parameters once you have set up a connection, so you have to create a new connection and you get one try at getting the port parameters correct.

But it's doing what I want it to now.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's why I never use HyperTerminal. If the Serial Monitor doesn't serve my purpose, I fire up Visual Studio, and create a C# application that does.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12285
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


http://sites.google.com/site/terminalbpp/
...is a good replacement for Serial Monitor.  Bear in mind, under heavy traffic, it occasionally corrupts in-bound data.

I agree with PaulS.  It's fairly easy to build your own (but I disagree about the development tool  smiley-grin).
« Last Edit: May 01, 2012, 04:32:56 pm by Coding Badly » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
(but I disagree about the development too
It's the only tool I can use to do my day job. Since I like to make money, I've become fairly adept at using the tool, so I use it for other stuff, too.
Logged

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8894
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It just bought back memories of just how rubbish hyper terminal is.  The problem was I had flow control set to hardware. And hyper terminal being a typical poorly written windoze application, it seems you can't edit the port parameters once you have set up a connection, so you have to create a new connection and you get one try at getting the port parameters correct.

If we put some kechup on your hyperterminal sh*t sandwich will that make you happy?  smiley-cool
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12285
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It's the only tool I can use to do my day job.

Bummer.  Well, sort of.  C# is nice.  I don't have anything bad to say about it.

Quote
Since I like to make money, I've become fairly adept at using the tool, so I use it for other stuff, too.

Yeah, money is good.  And it's nice not to have to constantly refer to reference manuals.

But, man, I am loving Python + Arduino!
Logged

Pages: [1]   Go Up
Jump to: