serial port comunication problem in linux
Hi all,
I am having problem comunication with serial port in linux. I have
tested the serial port with attaching a serial modem and dialing the
numbers with wvdial. it works okie but when i connect HSM to the serial
port it sends the message but i did not get a reply. mean it always
being blocked in the read function. The same hsm is working fine in
unix. so there is no problem with hsm. I am using the code as given
below for test. is there some extra configuration required. can any
body help what i m doing wrong :S
i will highly appreciate ur help.
Best Regards
Yasir Mehmood
main()
{
int fd,c, res,i;
FILE *td;
struct termios oldtio,newtio;
char buf[255];
printf("Going to open HSM port:\n");
td=fopen("test.log","a");
fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY );
if (fd <0) {
fprintf(td,"Can not open the comport:\n");
printf("Can not open the comport:\n");
perror("/dev/ttyS0");
exit(-1);
}
tcgetattr(fd,&oldtio); /* save current port settings */
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = B9600 | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
/* set input mode (non-canonical, no echo,...) */
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0; /* inter-character timer unused */
newtio.c_cc[VMIN] = 1; /* blocking read until 5 chars
received */
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
fprintf(td,"Going to send the Data to Hsm:\n");
printf("Going to send the Data to Hsm:\n");
if(write(fd,"00703C3C30",10)<=0){
fprintf(td,"Message Can not be sent to Hsm:\n");
printf("Message Can not be sent to Hsm:\n");
}
fprintf(td,"Message sent to Hsm:\n");
printf("Message sent to Hsm:\n");
fprintf(td,"\n***********************************************:\n");
printf("\n***********************************************:\n");
fprintf(td,"Going to read Data from Hsm:\n");
printf("Going to read Data from Hsm:\n");
res = read(fd,buf,254);
buf[res]=0;
fprintf(td,"Byte Read :%d\n",res);
printf("Byte Read :%d\n",res);
fprintf(td,"Data Read :%s\n", buf);
printf("Data Read :%s\n", buf);
tcsetattr(fd,TCSANOW,&oldtio);