473,670 Members | 2,343 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 6475
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
4001
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
2116
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
7309
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
8184
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
5494
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
7845
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
16369
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
1807
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
5637
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
8469
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
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
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...
1
8592
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7419
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6213
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
5684
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4211
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...
2
2042
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.