Find the answer to your Linux question:
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 ...
  1. #1
    j1s
    j1s is offline
    Just Joined! j1s's Avatar
    Join Date
    Nov 2006
    Location
    Norway
    Posts
    90

    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

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Debian GNU/Linux -- You know you want it.

  3. #3
    j1s
    j1s is offline
    Just Joined! j1s's Avatar
    Join Date
    Nov 2006
    Location
    Norway
    Posts
    90
    Thanks but - Been there, done that...


  4. #4
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    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.

  5. #5
    j1s
    j1s is offline
    Just Joined! j1s's Avatar
    Join Date
    Nov 2006
    Location
    Norway
    Posts
    90
    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!!

  6. #6
    Just 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.

  7. #7
    j1s
    j1s is offline
    Just Joined! j1s's Avatar
    Join Date
    Nov 2006
    Location
    Norway
    Posts
    90
    Thank you, curi.

    This was most helpful, and explained in a simple way.

    Thanks for your time and effort!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...