LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Closed Thread
 
Search this Thread
Old 11-28-2003, 04:44 AM   #1
neelc20
LQ Newbie
 
Registered: Nov 2003
Distribution: RedHat 8.0
Posts: 4

Rep: Reputation: 0
Detecting connection break on serial port listener on linux


Hi,

Can anyone let me know how to detect the client connection break on a serial port listener on linux?
I have written an application that opens the serial port and is able to read and write data. My serial port listener is running on Linux and I am using HyperTerminal (WIN-NT/2K) for communication on client side.

The problem: Now when I DISCONNECT the client from the CALL menu in HyperTerminal, I am not able to detect the disconnection at the listener. Here is my sample piece of code. Please suggest something, if you have any idea or working on it.

Thanking you in advance.


Sample code follows:
--------------------------------------------------------------------

#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */

int main()
{
// open serial port for communication
int serialFd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY );
if (fd == -1)
{
//printf("Could not open the port\n\n");
perror("open_port: Unable to open /dev/ttyS0 - ");
}
else
fcntl(fd, F_SETFL, 0);

struct termios options;

//get the port options
tcgetattr(serialFd, &options);

cfsetispeed(&options, B9600);
cfsetospeed(&options, B9600);
options.c_cflag |= (CLOCAL | CREAD);

// setting for 8bits, No parity, 1 Stop bit
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;

// choosing raw input
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
// ignore input parity check
options.c_lflag &= ~INPCK;
// check parity errors and strip parity bits
options.c_lflag |= (IGNPAR | ISTRIP);
//diabling software flow control
options.c_lflag &= ~(IXON | IXOFF | IXANY);
// choosing processed output and map NL to CR-NL
options.c_lflag |= (OPOST | ONLCR);

// set the configured options of the port
tcsetattr(serialFd, TCSANOW, &options);

// set port mode to no delay
fcntl(serialFd, F_SETFL, FNDELAY);

write(serialFd, "Welcome to PORT COM1", 20 ) ;

int flag = 0;
char buf[256];
memset(buf, 0, 256);
while (flag == false) /* loop for input */
{
int res = read(serialFd, buf, 255);
buf[res]=0;
write(fd, "Buffer read :%s\n", buf);
if (buf[0]=='z')
flag = true;
}
return 0;
}
 
Old 11-28-2003, 01:56 PM   #2
Joey.Dale
Member
 
Registered: Jun 2003
Location: Tampa, Fl
Distribution: Gentoo, Slackware
Posts: 828

Rep: Reputation: 30
please don't post the same thread in more than one fourm see the rules
 
Old 11-29-2003, 11:22 AM   #3
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

http://www.linuxquestions.org/rules.php

The original is here:
http://www.linuxquestions.org/questi...hreadid=120675
 
Old 11-29-2003, 03:29 PM   #4
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,535

Rep: Reputation: 148Reputation: 148
I'm closing this thread, please post all replies to http://www.linuxquestions.org/questi...hreadid=120675
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
linux serial port to router console port connection? frankie_fix Linux - General 3 02-26-2007 09:32 PM
serial port network connection eantoranz Linux - Networking 2 10-31-2005 08:05 AM
How to probe if a serial port has a valid connection? RedDrake Linux - General 2 09-01-2005 07:05 PM
setting up com port for serial connection to monitor network switch help murf562 Linux - Hardware 1 10-30-2004 09:46 AM
Detecting connection break on serial port listener on linux neelc20 Programming 6 12-04-2003 01:08 AM


All times are GMT -5. The time now is 06:44 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration