serial port comunication problem in linux

F

findyasir

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);
 
P

Phlip

findyasir said:
I am having problem comunication with serial port in linux.

Use Google to find the best forum for that question. This newsgroup is only
qualified to discuss platform-neutral C++ things.
 
V

Victor Bazarov

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

That's simple: you're posting to a wrong newsgroup. You need one of
'comp.os.linux.development' forums. Here you are OT. Your problem has
nothing to do with C++ _language_.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top