Offline
Newbie
Karma: 0
Posts: 7
|
 |
« on: May 01, 2012, 05:21:19 am » |
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: 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
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #1 on: May 01, 2012, 05:24:07 am » |
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. if (incomingByte == 83) // "S" Why? You got something against the much more intuitive if (incomingByte == 'S')
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #2 on: May 01, 2012, 06:02:43 am » |
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
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #3 on: May 01, 2012, 06:07:41 am » |
Are you saying it is THAT that holds the data in a buffer and doesn't send it until you press enter? Yes. Any way around that? Sure. Don't use the Serial Monitor.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #4 on: May 01, 2012, 07:10:01 am » |
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
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #5 on: May 01, 2012, 07:26:25 am » |
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
Online
Shannon Member
Karma: 120
Posts: 10199
|
 |
« Reply #6 on: May 01, 2012, 04:31:07 pm » |
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  ).
|
|
|
|
« Last Edit: May 01, 2012, 04:32:56 pm by Coding Badly »
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #7 on: May 01, 2012, 06:47:11 pm » |
(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
Tesla Member
Karma: 51
Posts: 6592
Arduino rocks
|
 |
« Reply #8 on: May 01, 2012, 10:53:16 pm » |
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? 
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Online
Shannon Member
Karma: 120
Posts: 10199
|
 |
« Reply #9 on: May 02, 2012, 12:39:41 am » |
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. 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
|
|
|
|
|
|