on Fri, Apr 19, 2002 at 12:09:59PM +0000, Dryden wrote:
What would be the best way to send char's and strings to a serial port?
[...]
Would I use the file handling commands and open /dev/S0 (what ever the Comm ports are called under Linux) and then use fprintf(serial_port, "command")??? Would i have any problems doing this f5rom a normal user account on my system or would I need to be root?
You don't need to be root. Check the permissions for /dev/ttySx. The UID that you want to access the port needs read and write permissions.
#include <unistd.h> #include <stdio.h> #include <fcntl.h>
int main() { FILE *fp; int fd; char dev[] = "/dev/ttyS0";
/* * O_NOCTTY is needed under Linux and non-BSD unices otherwise the * tty device might become the processes controlling tty. */ if ((fd = open(dev, O_RDWR|O_NOCTTY, 0)) == -1 || (fp = fdopen(fd, "w+")) == NULL) err(1, "unable to open `%s'", dev);
fprintf(fp, "hello world\n");
fclose(fp); return 0; }