Serial Programming
Hi, I'm trying to create a program that can access serial port as I/O. I've created a null modem device which can be attached to serial port as I/O. The device's input is in a form of buttons while the output is in LEDs. When I tried it in minicom, it worked. So I started to write the application in C++. I've looked at the Serial Programming How-To and tried copy-pasted the canonical input into my application. It didn't work. I tried the asynchronous and still it didn't work. Even when I pressed the button, it didn't throw SIGIO at all. But in minicom, it worked. If i pressed a button, it sends a message (like "Test", etc). Can anybody help me?
|
Not sure, but it sounds like you non-canonical I/O.
Here's some document that has some more information: http://www.easysw.com/~mike/serial/serial.html Hop this helps a bit. |
Well, I can understand if it's the input from serial. But the output is also somewhat didn't work. You see in the serial device controller, there's a program that will detect I/O from / to the serial. If I send (write) eg. "fls 1 1 1", it will cause the first LED to blink with 1 second on and 1 off. In minicom, it worked. But when I tried it in my program (with: write(fd,"fls 1 1 1",9);), it didn't work. Can anybody help me?
|
In minicom, you probably hit <enter> before it works. So you must do the same thing in your program
Code:
write(fd,"fls 1 1 1\n",10) I don't know what your device reacts on, it might need '\r\n' instead of '\n'. But that's trial-and-error or consulting the documentation. |
Quote:
Quote:
Code:
|
I don't know.
You use something that I've never used (sigaction) so I can not really comment on your code. A possible error might be that your program does not send the complete string. You can check how many bytes were written. In this thread I've posted my init routine. Maybe it helps. |
Quote:
BTW, I've looked at your thread and I see that it is pretty much the same as my code (beside the signal handler). Thanks anyway. |
BTW, another question. What is the difference between using minicom and coding serial port in C / C++? Is it only the flags's initialization values or there was something else? If it's only the flags's, how do I know the minicom's flags in C that can be used in a raw C code?
BTW here's the minicom's config that actually worked: Quote:
|
All times are GMT -5. The time now is 09:24 PM. |