473,837 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,&o ldtio); /* 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,TC SANOW,&newtio);
fprintf(td,"Goi ng to send the Data to Hsm:\n");
printf("Going to send the Data to Hsm:\n");
if(write(fd,"00 703C3C30",10)<= 0){
fprintf(td,"Mes sage Can not be sent to Hsm:\n");
printf("Message Can not be sent to Hsm:\n");
}
fprintf(td,"Mes sage sent to Hsm:\n");
printf("Message sent to Hsm:\n");

fprintf(td,"\n* *************** *************** *************** *:\n");
printf("\n***** *************** *************** ************:\n ");

fprintf(td,"Goi ng to read Data from Hsm:\n");
printf("Going to read Data from Hsm:\n");
res = read(fd,buf,254 );
buf[res]=0;
fprintf(td,"Byt e Read :%d\n",res);
printf("Byte Read :%d\n",res);
fprintf(td,"Dat a Read :%s\n", buf);
printf("Data Read :%s\n", buf);
tcsetattr(fd,TC SANOW,&oldtio);

May 22 '06 #1
2 6490
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
4011
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 there is a response. For example: #001 LED 1 1 CR (command led1=1)
2
2123
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 happening. terminology from: (http://www.easysw.com/~mike/serial/serial.html) when DTR is in SPACE level and I call ioctl to set it to SPACE level,
1
7318
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 the dll for linux that can receive or transmit data on serial port .so help me
15
8202
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 transactions occur? I'm trying to reverse engineer a microcontroller serial routine and I'd like to see any response the chip sends back. Regards, Ken
4
5500
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 VB.net (2005) using the .Net Compact Framework 2.0. I've seen a lot of third-party components about but am reluctant to
2
7857
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 server to send and recieve data. please tell me step by step procedure. regards shamik
8
16394
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 am also seeing the values on minicom. Now I have used fcntl() function and then read refp = fcntl(fd, F_SETFL, 0); res = read(fd,buf,1024); /* Read the value sent on the serial port buf=0; /* set end of string, so we can printf */...
1
1817
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
5654
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 parameters. I send a series of bytes from the Debian PC which comes through, no problem. I reply from PC#2, but the read buffer of the Debian PC's port shows nothing. What's more, the message gets sent directly back to the PC#2, with certain bytes...
0
9846
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10886
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10580
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10277
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7817
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5674
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5853
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4479
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4052
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.