473,385 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 6450
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: code | last post by:
Hi folks, I would like to read and write to a ISO-Reader card (RFID) connected to /dev/ttyS0 (COM1). Writing works fine, all commands I write to the device will be executed. To every command...
2
by: bernatik | last post by:
hi all I am trying to control special device through serial port from Linux. For that purpose I need to control DTR signal. I am watching the signal on a oscilloscope, so I know exactly what is...
1
by: raza | last post by:
i have to access the serial port for controlling hardware, i have found the php_ser.dll for serial communication. but this dll is for windows only. i need to do the same job on linux plateform.i need...
15
by: xkenneth | last post by:
Hi, I'm writing a couple python applications that use the serial port (RS-232) quite extensively. Is there any way I can monitor all activity on the serial port and have it printed as the...
4
by: Adamant | last post by:
Hi All, I'm new to programming for PPC's and .NET, coming from a VB6 / Delphi background. I've been looking around as apparantly there is an easy way to perform serial port comunication in...
2
by: shamik | last post by:
hii friends does anybody know how to do serial communication (through) serial port in linux using c++? I am using redhat-9. it would be better if someone can provide with eg. codes of client and...
8
by: Vivek Menon | last post by:
Hi, I am using a C program to write/read from a serial port. The writing part is working perfectly fine. However, I am not able to read the values correctly and display them. To debug this issue I...
1
by: jpetho | last post by:
Hi Everybody!! I want to poll the srial port under Linux. Is this possile? Please help me to do that!! Thank you! Julia Petho
1
by: lutherchp | last post by:
A baffling end to my week! I open my serial port on my Debian PC (Debian version 5.0.1) I have a decent Null Modem lead going to another PC (I'll call it PC#2), with its port open with the same...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.