hi,,
anybody can help me,,
I have a problem with my serial program.
My serial program connect to one of hardware,but the program can't send data.
I think the problem is structure of termios is'nt correct.
I want to connect to the that hardware with :
1. BAUD = 19200
2. DATABITS = 8
3. PARITY = EVEN
4. STOPBITS = 1
AND
5. FLOW CONTROL = NONE
This my procedure :
int openSerial(char addr[])
{
int fd,res,ii,i;
char devicename[30];
char data[10];
int ret=-1;
struct termios newio;
data[0]=4;
data[1]=addr[0];
data[2]=81;
data[3]=10;
data[4]=0;
strcpy(devicename,"/dev/ttyS0");
fd = open(devicename, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fd < 0)
{
perror(devicename);
}
else {
if (tcgetattr(fd, &newio)) printf("Error Get Attr\n");
memset(&newio, 0, sizeof(struct termios));
cfmakeraw(&newio);
cfsetspeed(&newio, (speed_t)B19200);
newio.c_cflag |= CREAD | CLOCAL
newio.c_cflag |= (newio.c_cflag & ~CSIZE) | CS8;//databits
newio.c_cflag |= 0;//stopbits=2
//parity=even
newio.c_cflag &= ~(PARENB | PARODD);
newio.c_cflag |= PARENB;
newio.c_iflag =0;
newio.c_oflag =0;
newio.c_cc[VMIN] =1;
newio.c_cc[VTIME] =0;
//tcflush(newio,TCIFLUSH);
if (tcsetattr(fd, TCSANOW, &newio)) printf("Set Error\n");
if (tcgetattr(fd, &newio)) printf("Error Get Attr\n");
printf("Sending data\n");
write(fd,data,strlen(data));
close(fd);
}
return ret;
}
Thanx...
I wait the answer now..hehe
problem with structure serial(termios)
-
- Posts: 1
- Joined: Wed Apr 09, 2008 7:15 pm
- Contact:
Who is online
Users browsing this forum: No registered users and 1 guest