A question about programming RS-232
Сергей Собко
bug2bug at bug2bug.tk
Sun Sep 3 10:24:09 PDT 2006
Hello.
I have a question I can't deal myself.
And nobody can help me in resolving my problem.
Problem:
I have a hand-made device, I want to control from FreeBSD 6.1
(I am porting this application from Windows equivalent).
But I don't know, in what device /dev/ I should write to get reults.
I tryed to write bytes into /dev/ttyd0, /dev/cuad0, but got nothing. :(
Code:
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
int main(void) {
int t = 0, num = 10, fd, i, iOut; char *ch;
struct termios my_termios;
ch = (char *)malloc(6);
memset(ch, 250, 6);
fd = open("/dev/ttyd0", O_RDWR | O_NONBLOCK);
printf("Opened com port\n");
if(fd < 0) return 0;
// tcflush(fd, TCIFLUSH);
my_termios.c_cflag = CS8 | CLOCAL;
if(cfsetspeed(&my_termios, B9600) < 0) return 0;
if(tcsetattr(fd, TCSANOW, &my_termios) < 0) return 0;
iOut = write(fd, ch, 6);
if(iOut < 0) return 0;
printf("Number of bytes = %d\n", iOut);
printf("Writed %s!\n", ch);
close(fd);
printf("Closed!\n");
return 0;
}
P.S. Please, help me.
P.P.S. Sorry for such stupid and annoying questions
P.P.P.S. Sorry for my bad English as I'm from Russia and I'm only 16 ;)
More information about the freebsd-questions
mailing list