[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question: My dial program and HSMODEM



In <199510140828.JAA29005@connectum.skurup.se>, Reine Jonsson <ljord@connectum.skurup.se> wrote:

> I use Bconout(1,value) to send
> a char to my modem.
> The basic routines is added last in this
> mail.
> The programs works fine without HSMODEM
> and at 19200 baud-rate.
> 
> When I run HSMODEM in my autofolder
> I'm able to communicate with my modem
> if I do:
> 
> echo atdtphone-number > /dev/modem2
> 
> but not if I use my dial-program.
> 
> Question nr 1: What shall I do to make
> it work?

Why not forget about the BIOS functions and write a more
portable appliation instead?  As an illustration:

#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>

int	open_modem (char *device_name);

void
main (void)
{
	int	fd;
	ssize_t	len;
	char	b[100], *s = "ATDTplus-phone-number\r";

	if ((fd = open_modem("/dev/modem")) < 0) abort();
	if (write(fd, s, strlen(s)) < 0) abort();
	len = read(fd, b, sizeof(b));
	close(fd);
	if (len < 0) abort();
	b[len] = '\0';
	printf("%s\n", b);
}

int
open_modem (char *device_name)
{
	int		fd;
	struct termios	ts;

	if ((fd = open(device_name, O_RDWR|O_NOCTTY)) < 0)
		return -1;
	if (!isatty(fd)) {
		close(fd); return -1;
	}
	/* get line info */
	if (tcgetattr(fd, &ts)) {
		close(fd); return -1;
	}
	/* set input speed to 38400bps */
	if (cfsetispeed(&ts, B38400)) {
		close(fd); return -1;
	}
	/* set output speed to 38400bps */
	if (cfsetospeed(&ts, B38400)) {
		close(fd); return -1;
	}
	/* initialise control modes */
	ts.c_cflag &= ~CLOCAL;	/* obey status lines */
	ts.c_cflag |= CREAD;	/* enable receiver */
	ts.c_cflag &= ~CSIZE;
	ts.c_cflag |= CS8;	/* 8 data bits */
	ts.c_cflag &= ~CSTOPB;	/* 1 stop bit */
	ts.c_cflag |= HUPCL;	/* hang up on close */
	ts.c_cflag &= ~PARENB;	/* no parity bit */
	/* initialise local modes */
	ts.c_lflag &= ~ECHO;	/* local echo off */
	ts.c_lflag &= ~ICANON;	/* canonical mode off */
	ts.c_lflag |= ISIG;	/* generate signals */
	<etc. etc.>
	/* initialise input modes */
	ts.c_iflag |= BRKINT;
	ts.c_iflag &= ~IGNBRK;
	<etc.>
	if (tcsetattr(fd, TCSANOW, &ts)) {
		close(fd); return -1;
	}
	return fd;
}


Waldi