Serial Communication on a dial-up line

Hello,

I have developed a serial communication program for data transfer on
RS232 serial connectivity between two computers running QNX 4.25. The serial
program modules are as follows :

The program at one end is running in MASTER mode. This program’s role is to
transmit query command packets on the serial line. It then waits for a
response packet from SLAVE. If SLAVE does not respond within 800milliSec,
MASTER indicates a timeout error and prepares next quey packet for
transmission.

At the other end communciation program runs in SLAVE (listening) mode. This
module normally remains blocked on incoming serial data . If a valid
packet is received on serial port, SLAVE transmits a response packet with
data to MASTER.

Both the modules are tested and found working on a dedicated serial
connection. Now I wish to use the same program modules over a serial,
dial-up line. Do I need to make major modifications in my source code? I
have used Watcom C compiler version 10.6 with QNX 4.25. Will a “modem
handler” of QNX be of any use?

I have already tried a dial-up connectivity between two QNX computers (with
“qtalk” for dialing from one computer and “tinit, modem” utilities at the
other end to answer a call and start a “login” session). That worked, but I
would want my programs to communicate for data transfer over a dialup serial
line.

Can anyone help me?

Thanks in advance,
Krupa

“Situ Electro Instruments Pvt. Ltd.” <seto@vsnl.com> wrote in message
news:95tuvs$5d5$1@inn.qnx.com

Hello,

it depends on what do you mean under “dual-up connected line”. if you
mean
running tcp/ip over serial line with ppp then i guess changes should be
minimal.
look at “Socket Programming Guide” shipped with tcp/ip development kit for
qnx4.

actually, you need the following steps:

  1. start socket dayemon. don’t remember how is it in 4.x tcp/ip but if you
    use tcp/ip 5b
    just run “#> /usr/ucb/Tcpip MyHostName &”.

  2. establishe ppp connection between two computers over direct link or
    probably
    modem connection. if you use dirrect connection just start pppd on both
    ends. if you
    use modem connection then you should first dial from one host to another
    with qtalk
    or any other communication program and start pppd next.

note: afair it wasn’t so easy to configure propertly ppp connection between
qnx4 and
windoze and guess same situation might be with qnx4-qnx4 connectivity. i
don’t remember
right now all tips so feel free to ask if you will find some troubles.

  1. from your receiver host program (let to call it server) you should open
    tcp socket,
    assign needed address info, bring it into listen state and in circle accept
    all [or selected]
    incomming connections and transmit all needed data. kind of :

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#define LISTEN_PORT 1234 /* this is a tcp port you wish to listen on
*/

struct sockaddr_in sa;
int sock,data_sock;

static const char smsg[] = “server reply message”;
static char rmsg[100];

/* create tcp socket */
sock = socket(AF_INET,SOCK_STREAM,0);

/* bind address info to created socket /
memset(&sa,0,sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = INADDR_ANY; /
receive requests from any
ip address /
sa.sin_port = htons(LISTEN_PORT)
bind(sock,(struct sockaddr
)&sa,sizeof(sa));

/* bring your socket into “listen” state */
listen(sock,5);

for (;:wink: {
/*
wait for incomming connection and accept it
accept returns file descriptor (socket) which should be used for
futher operations during this connection
*/
data_sock = accept(sock,NULL,0);

/*
so now you have established connection and
you can send/receive streamming data with calling
read()/write() passing data_sock as target file descriptor.
for example receive a string message :
*/

memset(rmsg,0,sizeof(rmsg));
read(data_sock,rmsg,sizeof(rmsg)-1);
fprintf(stdout,“client send message is: %s\n”,rmsg);

/*
…and write reply
*/
write(data_sock,smsg,sizeof(smsg);

/* close connection */
close(data_sock);
}

/* at exit close listen socket */
close(sock);


  1. from your sender host programm (let call it client) you should open tcp
    socket,
    assign needed address info, connect to server and transmit all needed data.
    kind of :

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#define LISTEN_PORT 1234 /* this is a tcp port you wish to listen on
*/

static const char smsg[] = “client send message”;
static char rmsg[100];

struct sockaddr_in sa;
int sock,data_sock;

/* create tcp socket */
sock = socket(AF_INET,SOCK_STREAM,0);

/*
bind server address info to created socket
let assume that you assigned addres 192.168.1.1 to your server
during ppp connection handshake
/
memset(&sa,0,sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr(“192.168.1.1”); /
receive
requests from any ip address /
sa.sin_port = htons(LISTEN_PORT)
bind(sock,(struct sockaddr
)&sa,sizeof(sa));

/* connect to server /
connect(sock,(struct sockaddr
)&sa,sizeof(sa));

/*
so now you have established connection with server
and can send/receive data with write()/read
passing sock as target file descriptor
*/

/* send test message */
write(sock,smsg,sizeof(smsg));

/* …and read server reply */
memset(rmsg,0,sizeof(rmsg));
read(sock,rmsg,sizeof(rmsg)-1);
fprintf(stdout,“server reply message is: %s”,rmsg);

/* close socket at exit */
close(sock);


well, as you can see, communicating over dial-up line with tcp/ip is
pretty easy and is very simular to raw serial channel communication. look at
examples included in tcp/ip development distribution and hope it becomes
absolutely clear to you.

// wbr

I have developed a serial communication program for data transfer on
RS232 serial connectivity between two computers running QNX 4.25. The
serial
program modules are as follows :

The program at one end is running in MASTER mode. This program’s role is
to
transmit query command packets on the serial line. It then waits for a
response packet from SLAVE. If SLAVE does not respond within 800milliSec,
MASTER indicates a timeout error and prepares next quey packet for
transmission.

At the other end communciation program runs in SLAVE (listening) mode.
This
module normally remains blocked on incoming serial data . If a valid
packet is received on serial port, SLAVE transmits a response packet
with
data to MASTER.

Both the modules are tested and found working on a dedicated serial
connection. Now I wish to use the same program modules over a serial,
dial-up line. Do I need to make major modifications in my source code? I
have used Watcom C compiler version 10.6 with QNX 4.25. Will a “modem
handler” of QNX be of any use?

I have already tried a dial-up connectivity between two QNX computers
(with
“qtalk” for dialing from one computer and “tinit, modem” utilities at the
other end to answer a call and start a “login” session). That worked, but
I
would want my programs to communicate for data transfer over a dialup
serial
line.

Can anyone help me?

Thanks in advance,
Krupa


Ian Zagorskih
Novosoft CyBearNet Department
Custom software development and web design since 1992
E-mail: ianzag@novosoft.ru
Phone: +7 (3832) 39-72-60, 39-72-61
Fax: +7 (3832) 39-63-58
For more visit www.novosoft-us.com

Situ Electro Instruments Pvt. Ltd. <seto@vsnl.com> wrote:

Hello,

I have developed a serial communication program for data transfer on
RS232 serial connectivity between two computers running QNX 4.25. The serial
program modules are as follows :

The program at one end is running in MASTER mode. This program’s role is to
transmit query command packets on the serial line. It then waits for a
response packet from SLAVE. If SLAVE does not respond within 800milliSec,
MASTER indicates a timeout error and prepares next quey packet for
transmission.

At the other end communciation program runs in SLAVE (listening) mode. This
module normally remains blocked on incoming serial data . If a valid
packet is received on serial port, SLAVE transmits a response packet with
data to MASTER.

Both the modules are tested and found working on a dedicated serial
connection. Now I wish to use the same program modules over a serial,
dial-up line. Do I need to make major modifications in my source code? I
have used Watcom C compiler version 10.6 with QNX 4.25. Will a “modem
handler” of QNX be of any use?

I’ll assume you’re just talking about your MASTER directly dialing
your SLAVE computer, not talking to an ISP for internet connectivity
between the machines.

I have already tried a dial-up connectivity between two QNX computers (with
“qtalk” for dialing from one computer and “tinit, modem” utilities at the
other end to answer a call and start a “login” session). That worked, but I
would want my programs to communicate for data transfer over a dialup serial
line.

Can anyone help me?

The big issue/issues is the question of are these machines always going
to be dialed up & connected? Or are you going to do some sort of on-demand
dialing when they need to talk? And, if they are talking, how do you deal
with losing a connection – unexpected hangup at one end or the other, or
loss of connection due to noise on the line, or other such problems.

You also have to realize that throughput may be less (null-modem will often
get 115,200 baud, while dialup may not), and your latencies will be higher.
If you’re sending small packets, this shouldn’t be an issue – but if the
800 ms turn around is at all tight (based on your bandwidth/transmission
time) this could be a problem.

Handling the details of an initial dial-up and answer is, actually, fairly
simple. You can have tinit,modem handle the answering of the phone – but
instead of starting the login, they start your SLAVE program. If the line
drops, your slave should expect a SIGHUP, and deal with this gracefully.

On the dialing side, dial commands are just strings written to the serial
port – you can code the dial-out portion with open(/dev/ser1),
write(“atdt…”), though you may want slightly more resilient handling.
The source to qtalk is available for download, if you wish, and you
could extract the dialing & modem handling code from there, if you
wanted to – but the serial port side is actually less complicated than
the dealing with user-input side of things.

Hope this helps,

-David

QNX Training Services
dagibbs@qnx.com

David Gibbs <dagibbs@qnx.com> wrote in message
news:95uf8e$iro$1@nntp.qnx.com

Situ Electro Instruments Pvt. Ltd. <> seto@vsnl.com> > wrote:
Hello,

I have developed a serial communication program for data transfer on
RS232 serial connectivity between two computers running QNX 4.25. The
serial
program modules are as follows :

The program at one end is running in MASTER mode. This program’s role is
to
transmit query command packets on the serial line. It then waits for a
response packet from SLAVE. If SLAVE does not respond within
800milliSec,
MASTER indicates a timeout error and prepares next quey packet for
transmission.

At the other end communciation program runs in SLAVE (listening) mode.
This
module normally remains blocked on incoming serial data . If a valid
packet is received on serial port, SLAVE transmits a response packet
with
data to MASTER.

Both the modules are tested and found working on a dedicated serial
connection. Now I wish to use the same program modules over a serial,
dial-up line. Do I need to make major modifications in my source code?
I
have used Watcom C compiler version 10.6 with QNX 4.25. Will a “modem
handler” of QNX be of any use?

I’ll assume you’re just talking about your MASTER directly dialing
your SLAVE computer, not talking to an ISP for internet connectivity
between the machines.

Yes, MASTER module on one computer is directly dialing SLAVE module on
another computer… We have developed the serial communication program
based on DNP 3.0 protocol for a dedicated serial connectivity. We now wish
to use a dial-up serial connectivity for data transfer from SLAVE to MASTER

I have already tried a dial-up connectivity between two QNX computers
(with
“qtalk” for dialing from one computer and “tinit, modem” utilities at
the
other end to answer a call and start a “login” session). That worked,
but I
would want my programs to communicate for data transfer over a dialup
serial
line.

Can anyone help me?

The big issue/issues is the question of are these machines always going
to be dialed up & connected? Or are you going to do some sort of
on-demand
dialing when they need to talk? And, if they are talking, how do you deal
with losing a connection – unexpected hangup at one end or the other, or
loss of connection due to noise on the line, or other such problems.

You also have to realize that throughput may be less (null-modem will
often
get 115,200 baud, while dialup may not), and your latencies will be
higher.
If you’re sending small packets, this shouldn’t be an issue – but if the
800 ms turn around is at all tight (based on your bandwidth/transmission
time) this could be a problem

At present we need data transfer from SLAVE to MASTER at 19200 baud and the
packet size is small…

Handling the details of an initial dial-up and answer is, actually, fairly
simple. You can have tinit,modem handle the answering of the phone – but
instead of starting the login, they start your SLAVE program. If the line
drops, your slave should expect a SIGHUP, and deal with this gracefully.

I had also thought that this should be possible. The setting/utility used
and problem encoutered by me is as follows :

On Slave computer,
#tinit -c “modem -b 19200 /home/krupa/comm_slave” -m 10 -t
/dev/ser1 &

On MASTER computer,

qtalk /dev/ser1

From qtalk, I dialed the telephone number of SLAVE computer
When the SLAVE computer answered the telephone, I could see
messages indicating startup of SLAVE communication program on SLAVE
computer. I could obesrve this in qtalk session. After confirming the state
of SLAVE communication program, I selected an option to exit from qtalk
without hangup. I then invoked MASTER communication program on MASTER
computer. I could see that the line is disconnected by MASTER computer when
MASTER communication program transmits the data on serial port.

Is there anyting wrong with the sequence of test?

On the dialing side, dial commands are just strings written to the
serial
port – you can code the dial-out portion with open(/dev/ser1),
write(“atdt…”), though you may want slightly more resilient handling.
The source to qtalk is available for download, if you wish, and you
could extract the dialing & modem handling code from there, if you
wanted to – but the serial port side is actually less complicated than
the dealing with user-input side of things.

For initial experiments on dial-up kink, I would prefer to use a provision
for manual dialing. I have also downloaded source codes for qtalk and qcp
from “contributed softtware” section of QSSL’s web site. I will try to go
through the same once my initial test is through…

Hope this helps,



-David

QNX Training Services
dagibbs@qnx.com

Thanks for the reply,
Krupa

Krupa <krupah@hotmail.com> wrote:

I had also thought that this should be possible. The setting/utility used
and problem encoutered by me is as follows :

On Slave computer,
#tinit -c “modem -b 19200 /home/krupa/comm_slave” -m 10 -t
/dev/ser1 &

On MASTER computer,

qtalk /dev/ser1

From qtalk, I dialed the telephone number of SLAVE computer
When the SLAVE computer answered the telephone, I could see
messages indicating startup of SLAVE communication program on SLAVE
computer. I could obesrve this in qtalk session. After confirming the state
of SLAVE communication program, I selected an option to exit from qtalk
without hangup. I then invoked MASTER communication program on MASTER
computer. I could see that the line is disconnected by MASTER computer when
MASTER communication program transmits the data on serial port.

Is there anyting wrong with the sequence of test?

I would bet you’re missing one little gotcha.

If you do a “stty -a < /dev/ser1” on the MASTER before doing the qtalk,
you will probably see “+hupcl” (start of the 5th line of output). This
means the serial port is set to do a “hang up on close” – when you
exit qtalk, it doesn’t issue a hangup, but it does close all its file
descriptors, Dev sees this fd close, and issues the hangup for you
automatically. Usually you want this – if the program connected to the
serial port goes away, drop the line. (ie, if your talking to a shell,
and hit exit in the shell, or your program crashes, you want
the line to be dropped). If you want to use qtalk for dialing, then have
another program talk over the serial line, issue a “stty -hupcl < /dev/ser1”
before invoking qtalk to setup the connection. (Useful for Net.fd, manually
setting up ppp connections, etc.)

-David

QNX Training Services
dagibbs@qnx.com