ETHERNET
TO RS-232
Like
all Z-World development kits, the Coyote comes complete
with its own special version of Dynamic C. Using the
services of Dynamic C and the Coyote communications
hardware, you can easily put together a shop-floor
Ethernet-to-RS-232 serial converter.
The
idea is pretty simple: All you need to do is enable
the Ethernet interface and define all of the necessary
IP addressing for the Coyote. Next, enable an RS-232
serial port and specify the data rate, parity, stop
bit (or bits), and the number of data bits between
the start and stop bits. Then, define a buffer tub
for all of the bits and devise a scheme to move the
bits between the tub and the RS-232 and Ethernet interfaces.
I
figured this would take a day or two to code, debug,
and test. Before I started the coding, I decided to
take a look at the TCP/IP samples directory that comes
with Dynamic C for the Coyote. I found a serialexa.c
file. After reading the code description for serialexa.c,
all I had to do was twiddle a few values in an information
structure within the example code and fill in the
Coyote IP blanks in the TCP_CONFIG.LIB file. After
that came the Ethernet-to-RS-232 serial converter.
As it turned out, I only had to fill in my Coyote’s
IP address (192.168.0.150) and network mask (255.255.255.0)
in the TCP_CONFIG.LIB file to make things go (see
Listing 1).
Listing
1—If the Coyote had to use the “Big Router,”
then at least the MY_GATEWAY IP address would
have to be supplied here.
There are many levels to this routine, which are
selected by functions and defined using TCPCONFIG.
As you can see, this is TCPCONFIG 1. |
The
sample code for the Ethernet-to-RS-232 serial interface
is based on a state machine that uses the socket status
(INIT, LISTENING, OPENING, and CLOSING) as states
to determine how to handle the data transfers. The
serial port is always open. The buffer tub of bits
is composed of SRAM buffers for both the serial and
Ethernet ports.
The
Coyote Ethernet-to-RS-232 serial program initializes
a socket, starts the serial port, and listens for
a connection. I used telnet to establish a session
with the Coyote.
For
the serial-side transactions, I ran Tera Term Pro
on a separate PC and tied one of the Tera Term Pro
PC’s serial ports to the Coyote’s serial port E. As
simple as this seems, it didn’t work right out of
the box. After a few hours of scratching my head and
running traces, I found that the J6 RS-232 serial
port designations were incorrect. After lots of pin
swapping, I finally consulted the Coyote’s schematic
and found the GND pin to be J6 pin 9 rather than J6
pin 10. After I straightened this out, I lashed up
a corrected DCE cable, using words that a victorious
Navy fighter pilot would scream after a dogfight,
“Splash one.”