LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-02-2005, 11:25 PM   #1
novice_din
LQ Newbie
 
Registered: Feb 2005
Posts: 12

Rep: Reputation: 0
Lightbulb serial port programming!!!


Hi! I dont know if this is the right place to ask this question.

I am writing a serial communications program(C). This program will open port and initialize modem. However, looks like my modem do not support auto answer. I tried to initialized it wth ATS0=1 so that it will answer automatically after first ring but it is not working so I have to is ATA command to manually answer the connection. My problem is how will I know if remote pc is trying to connect to my server. The environment is linux. I tried ioctl(fd, TIOCMGET...) to get the modem status but not successful. Any idea will be greatly appreciated...

code snippet;

int fd=open("/dev/ttyS0"...)

write(fd, "ATS0=1\r",7) --> modem should be set to auto answer...but not

---------------
since the remote pc already initiated the connection but nobody answered then it gets a NO CARRIER response from the modem...


Thanks in advance.... any ideas will be appreciated!!!
 
Old 02-03-2005, 01:25 AM   #2
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Last time I used a modem, it would send the string "RING" when it detected an incoming call. Does your modem not do this?
 
Old 02-03-2005, 08:09 AM   #3
novice_din
LQ Newbie
 
Registered: Feb 2005
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks for your reply... I am not getting any response from my modem until I issue a "ATA".
 
Old 02-03-2005, 08:38 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
I don't have a direct answer to your question, but I hope this may be of some help.

A nice document about serial programming:
http://www.easysw.com/~mike/serial/

Some code I used once to wait (sleeping) for one (or more) serial control lines to change state (from hi->low, or low->hi). IRCC this isn't mentioned in the document above, I gues because its pobably Linux-specific.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <linux/serial.h>

/* ... */

int fd;
unsigned int status, oldstate, newstate, changed, mask;

/* Assuming fd is an open file descriptor for (one of) the
 * serial port(s) (/dev/ttyS[0-9]).
 */

/* To wait for *any* of the 4 control lines to change state,
 * use this instead of the line below:
 * mask = TIOCM_CAR | TIOCM_DSR | TIOCM_CTS | TIOCM_RNG;
 */
mask = TIOCM_RNG;

/* Get current status of the control lines in mask */
if (ioctl(fd, TIOCMGET, &status) == -1) {
    perror("ioctl(TIOCMGET)");
    exit(1);
}
oldstate = status & mask; /* Save current status of control lines */


/* The ioctl() call below sleeps, and does not return until one 
 * of the  serial control lines specified in mask changes state,
 * or it was interrupted by some signal.
 */
rewait:  /* Goto-label for when we get a signal. */
if (ioctl(fd, TIOCMIWAIT, mask) == -1) {
    if (errno == EINTR) {
        /* Signal received. Handle this case. Here we're
         * just restarting the ioctl-wait call.
         */
        goto rewait;
    } else {
        /* Error condition */
        perror("ioctl(TIOCMIWAIT)");
        exit(1);
    }
}


/* Get new status of the control lines in mask */
if (ioctl(fd, TIOCMGET, &status) == -1) {
    perror("ioctl(TIOCMGET)");
    exit(1);
}
newstate = status & mask;

/* XOR old with new status to find the one(s) that changed */
changed  = newstate ^ oldstate;

/* Do something with the result of al this */
if (changed & TIOCM_RNG) {   /* RNG line has changed */
    if (newstate  & TIOCM_RNG) {
        printf("RNG went from: 0 --> 1\n");
    } else {
        printf("RNG went from: 1 --> 0\n");
    }
}

Last edited by Hko; 02-03-2005 at 08:40 AM.
 
Old 02-03-2005, 09:50 PM   #5
novice_din
LQ Newbie
 
Registered: Feb 2005
Posts: 12

Original Poster
Rep: Reputation: 0
Looks like the problem is with the device driver that is controlling the serial port. I have tried this code before but I the modem status is not changing... i have seen similar problem on the web and they patched the device driver. How can I check the version of the device driver? I will try first if I can access the port/irq directly. I am still looking for the equivalent of inp() /*win32 */ or inputb() /*turboc */. Any idea? Thanks again and I appreciate all your inputs...
 
  


Reply


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
serial port programming: Java or C? ar1 Programming 5 05-19-2005 03:55 PM
Problem of serial port programming fingerling54 Linux - Software 4 05-18-2005 04:22 PM
programming to 'real' serial port in C++ microsoft/linux Programming 3 03-15-2005 09:12 AM
Serial port communication programming SeanatIL Programming 3 07-17-2004 09:26 PM
Programming the Serial Port karans Linux - Networking 2 11-03-2003 02:54 AM


All times are GMT -5. The time now is 01:41 AM.

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