Results 1 to 7 of 7
Hi.
I'm just learning the c language, and I've read lots and lots of google search and forum listings. But I can not find what I need.
I want to ...
- 08-15-2009 #1
serial port programming in c
Hi.
I'm just learning the c language, and I've read lots and lots of google search and forum listings. But I can not find what I need.
I want to control one simple LED with the serialport. I want to set the time the led will light.
Does anyone know how to do this? Or know the url to a good tutorial?
j1s
- 08-15-2009 #2Debian GNU/Linux -- You know you want it.
- 08-15-2009 #3
- 08-15-2009 #4
With the text at hand being read and understood by you, I can't see what step you have trouble with.
Debian GNU/Linux -- You know you want it.
- 08-15-2009 #5
The first time I read it, it seemed understandable, but it didn't get to me.

I will now concentrate, and read it again.
Thanks for your time!
Appreciate it!!
- 08-17-2009 #6Just Joined!
- Join Date
- Aug 2009
- Location
- Obera, Misiones, Argentina
- Posts
- 3
Maybe you could try these examples; they explain how to work with functions like open(), read(), write() and close().
For example, if you want to use the serial port device ttyS0, you have to do
.
.
.
serial_fd = open ("/dev/ttyS0",B9600);//9600 bauds
if (serial_fd==-1) {
printf ("Error opening the serial device: "/dev/ttyS0");
perror("OPEN");
exit(0);
}
//Now the port is ready to work
//Write anything you want to the port;
//It`s stored in buf
write (serial_fd, &buf, buf_size);
printf ("String sent------> %s\n",buf);
//We can read from port too, this is the way
n=read(serial_fd,data,buf_size);
.
.
//Finally, you close the port
close(serial_fd);
Pay attention that you have to configure the serial port with settings that you'll find in header file "termios.h"
I hope that's helpful.
- 08-18-2009 #7
Thank you, curi.
This was most helpful, and explained in a simple way.
Thanks for your time and effort!


Reply With Quote