hi,
i'm trying
1.to write a string to a serial port,
2. read this string from the port again
i'm using Serial Programming Guide for POSIX Operating Systems - Michael R Sweet as a reference.
this is the code snippet that i have put together:
Code:
int file= open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
if(file == 0)
{
perror("open_port: Unable to open /dev/ttyS0 - ");
}
else
fcntl(file, F_SETFL, 0);
while(1)
{
printf("enter input data:\n");
scanf("%s",&input);
chkin=write(file,input,sizeof input);
if(chkin<0)
{
printf("cannot write to port\n");
}
fcntl(file, F_SETFL, FNDELAY);
chkin=read(file,line,sizeof line);
if(chkin<0)
{
printf("cannot read from port\n");
}
printf("line=%s\n",line);
printf("do you want to send the next packet?(y/n):\n");
scanf("%s",&nextpacket);
if((strcmp(nextpacket,"y")!=0))
break;
}
the program is writing fine to the serial socket, but the read is not happening.
where am i going wrong?
a lot of the examples on this i have come across do some configuring at the port. is this essential?
thank you.