469,935 Members | 1,653 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,935 developers. It's quick & easy.

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

May 22 '06 #1
2 6215
findyasir wrote:
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.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
May 22 '06 #2
fi*******@gmail.com wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 22 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by code | last post: by
2 posts views Thread by bernatik | last post: by
15 posts views Thread by xkenneth | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.