Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleRTP 6700 Configuration

The RTP 6700 controller requires a set of configuration parameters for proper operation.  To configure the 6700, connect the console port of the 6700 to a terminal or a PC running a terminal emulator (such as HyperTerminal).  Terminal characteristics are 9600, 8, None, 1.  Switch on the power to the 6700 and enter a “3” to the first prompt  after power up.  The following is an example of reasonable configuration process and parameters for the RTP 6700 controller:

Code Block
A:\>echo off

Datalight is a registered trademark of Datalight, Inc.

CardTrick is a registered trademark of Datalight, Inc.

ROM-DOS is a trademark of Datalight, Inc.

Copyright 1989-1994 Datalight, Inc., All Rights Reserved

Bad command or filename

Loading the Ethernet Packet Driver

smc9192 0x62 0x7 0x300 0x604 ...

Current settings follow :

Twisted pair interface, using select # 2 for interrupt & 6 packets reserved for Tx

My Ethernet address is 00:80:F9:03:04:EC

***********************************************

RTP Corp.                                   *

Pompano Beach, Florida.                     *

Ethernet IO Bus Controller Version F.0.0    *

***********************************************
Code Block

************************
PROTOCOL=TCP
LINK=ETHERNET
MAX_CONNECTIONS=1
CONNECTION_TIMEOUT=3
SERVICE_ACCESS_POINT=0
IP_ADDRESS=89.89.89.121
SUBNET_MASK=255.0.0.0
CMD_BUF_SIZE=1464
RESP_BUF_SIZE=1464
BAUD_RATE=38400 BPS
MESSAGE_TRACE=OFF
MAX_TRACE_BUFF_SIZE=1
CONNECTION_WIRING=TWISTED
************************
1.- Revert Back to Default Configuration
2.- Continue with Saved Configuration
3.- Modify Configuration

No input is necesary, if no change is desired

3

Select Protocol:
[Current - 1] [Default - 0]
0 <Enter> - UDP
1 <Enter> - TCP
2 <Enter> - 802.2
<Enter>   - Keep Current Value
<Esc>     - Exit Configuration without Saving
S<Enter>  - Save Configuration

Selection: 0

Select Link:
[Current - 0] [Default - 0]
0 <Enter> - ETHERNET
1 <Enter> - SERIAL
<Enter>   - Keep Current Value
<Esc>     - Exit Configuration without Saving
S<Enter>  - Save Configuration

Selection: 0

Enter Maximum Number of Connections (1 - 4):
[Current - 1] [Default - 1]
<Enter>   - Keep Current Value
<Esc>     - Exit Configuration without Saving
S<Enter>  - Save Configuration

Selection: 1

Enter the Connection Timeout (0 - 600 seconds):
[Current - 3] [Default - 3]
<Enter>   - Keep Current Value
<Esc>     - Exit Configuration without Saving
S<Enter>  - Save Configuration

Selection: 3

Enter the Service Access Point (SAP) (0 - 254 even only):
[Current - 0]
<Enter>   - Keep Current Value
<Esc>     - Exit Configuration without Saving
S<Enter>  - Save Configuration

Selection: 0

Enter the IP Address (dotted decimal notation e.g. 255.2.3.3):
[Current - 89.89.89.121]
10.0.0.2

Enter the Subnet Mask (dotted decimal notation e.g. 255.0.0.0):
[Current - 255.0.0.0]
255.0.0.0

Enter the Command Buffer Size (1464 - 32727):
[Current - 1464] [Default - 1464]
<Enter>   - Keep Current Value
<Esc>     - Exit Configuration without Saving
S<Enter>  - Save Configuration

Selection: 1464

Enter the Response Buffer Size (1464 - 32727):
[Current - 1464] [Default - 1464]
<Enter>   - Keep Current Value
<Esc>     - Exit Configuration without Saving
S<Enter>  - Save Configuration

Selection: 1464

Select Baud Rate:
[Current - 2] [Default - 2]
0 <Enter> - 9.60  KBPS
1 <Enter> - 19.2  KBPS
2 <Enter> - 38.4  KBPS
3 <Enter> - 57.6  KBPS
4 <Enter> - 115.2 KBPS
<Enter>   - Keep Current Value
<Esc>     - Exit Configuration without Saving
S<Enter>  - Save Configuration

Selection: 0

Select Trace:
[Current - 0] [Default - 0]
0 <Enter> - OFF
1 <Enter> - ON
<Enter>   - Keep Current Value
<Esc>     - Exit Configuration without Saving
S<Enter>  - Save Configuration

Selection: 0

Enter the Trace Buffer size (1-63 KBytes):
[Current - 1] [Default - 1]
<Enter>   - Keep Current Value
<Esc>     - Exit Configuration without Saving
S<Enter>  - Save Configuration

Selection: 1

Select the Connection Wiring
[Current - 1] [Default - 0]
0 <Enter> - COAX
1 <Enter> - TWISTED
<Enter>   - Keep Current Value
<Esc>     - Exit Configuration without Saving
S<Enter>  - Save Configuration

Selection: 1

Configuration Complete.

************************
PROTOCOL=UDP
LINK=ETHERNET
MAX_CONNECTIONS=1
CONNECTION_TIMEOUT=3
SERVICE_ACCESS_POINT=0
IP_ADDRESS=10.0.10.11
SUBNET_MASK=255.0.0.0
CMD_BUF_SIZE=1464
RESP_BUF_SIZE=1464
BAUD_RATE=9600 BPS
MESSAGE_TRACE=OFF
MAX_TRACE_BUFF_SIZE=1
CONNECTION_WIRING=TWISTED
************************

Enter Y to Accept Configuration, N to Modify it

Y

EIOBC Ethernet Address: 00-80-F9-03-04-EC

After the configuration is accepted, it will be stored on the controller.  Cycling the power on the card will initialize the card to use these parameters.

...

code

int

tpriRdcTcp::open(int

*devHndl,

char

*devName,

int

portNum,

int

blocking

=

-1,

struct

sockaddr_in

*pServer

=

NULL)

Open

a

connection

to

the

specified

device.

Inputs:

int

*devHndl

Pointer

  Pointer to

device

handle

that

will

be

returned

from

the

open

call.

 

For

non-blocking

requests

this

must

point

to

a

handle

equal

to

-1

on

the

first

attempt

and

passed

unchanged

to

subsequent

open

calls

(made

while

open

remains

in

progress).

char

*devName

Remote

  Remote device

name.

int

portNum Remote device

portNum     Remote device TCP/IP

port

number

int

blocking Flag indicating if the open should block until

blocking    Flag indicating if the open should block until success/failure

(1)

or

return

immediately

(0).

Passing

 Passing -1

indicates

that

the

blocking

state

should

remain

unchanged

from

its

previous

value.

sockaddr_in

*pSvr

Pointer

to

server

structure

that

will

be

filled

in

by

the

open

call.

Once

filled

in,

the

same

structure

can

be

passed

on

subsequent

blocking

calls

to

speed

up

the

connection

process.

Passing

a

NULL

pointer

will

turn

off

this

feature.

Return

value:

Blocking

calls:

This

function

returns

zero

if

successful

or

a

positive

integer

if

the

open

fails.

If

 If successful,

the

device

handle

will

be

stored

in

the

location

pointed

to

by

devHndl.

Non-Blocking

calls:

This

function

will

return

-1

to

indicate

that

the

open

is

still

pending;

call

repeatedly

until

it

returns

a

success

or

failure.

int

tpriRdcTcp::close(int

devHndl)

Close

a

connection

associated

with

a

device

handle.

Inputs:

int

devHndl Device handle as returned from the open call. Return value: Always 0. int

devHndl      Device handle as returned from the open call.

Return value:

Always 0.

int tpriRdcTcp::read(int

devHndl,

char

*rxBuf,

int

rxCnt,

int

blocking

=

-1)

Read

a

set

of

data

from

a

remote

device.

Inputs:

int

devHndl Device handle as returned from the open call. char *rxBuf Pointer to the buffer into which the received data should be placed. int rxCnt Maximum number of bytes to read. int blocking Flag indicating if the read should block until rxCnt bytes have been read (1) or return immediately (0) with whatever data is available. Passing -1 indicates that the blocking state should remain unchanged from its previous value. Return value: If successful, the number of characters successfully read is returned. 1 indicates that an error occurred, and information about that error is available through WSAGetLastError(). -99 indicates that the connection has been closed. int tpriRdcTcp::write(int devHndl, char *txBuf, int txCnt) Write a set of data to a remote device. Inputs: int devHndl Device handle as returned from the open call. char *txBuf Pointer to the buffer containing the data to be written. int txCnt Number of bytes to write. Return value: If successful, the number of characters successfully written is returned. 1 indicates an error occurred. int tpriRdcTcp::listen(int *devHndl, int *svrHndl, int portNum, int backLog, int blocking /* = -1 */, char *hostName /* = NULL */) Listen for incoming TCP/IP connections. Inputs: int *devHndl Pointer to device handle that will be returned when a remote device connects to the server. int *svrHndl Pointer to device handle associated with the server socket. This handle can be reused to accept multiple connections. This must point to a handle equal to -1 on the first attempt and passed unchanged to subsequent listen calls. int portNum Remote device TCP/IP port number. int backLog Maximum number of connections to allow. int blocking Flag indicating if the open should block until success/failure (1) or return immediately (0). Passing a -1 indicates that the blocking state should remain unchanged from its previous value. char *hostName Local device name (if desired). Return value: Blocking calls: This function returns zero if successful or a positive integer if the open fails. If successful, the device handle will be stored in the location pointed to by devHndl. Non-Blocking calls: This function will return -1 to indicate that no connections are pending; call repeatedly until it returns a success or failure.

devHndl      Device handle as returned from the open call.

char *rxBuf      Pointer to the buffer into which the received data should be placed.

int rxCnt      Maximum number of bytes to read.

int blocking      Flag indicating if the read should block until rxCnt bytes have been read (1) or return immediately (0) with whatever data is available.  Passing -1 indicates that the blocking state should remain unchanged from its previous value.

Return value:

If successful, the number of characters successfully read is returned.   1 indicates that an error occurred, and information about that error is available through WSAGetLastError().  -99 indicates that the connection has been closed.

int tpriRdcTcp::write(int devHndl, char *txBuf, int txCnt)

Write a set of data to a remote device.

Inputs:

int devHndl      Device handle as returned from the open call.

char *txBuf      Pointer to the buffer containing the data to be written.

int txCnt      Number of bytes to write.

Return value:

If successful, the number of characters successfully written is returned.   1 indicates an error occurred.

int tpriRdcTcp::listen(int *devHndl, int *svrHndl, int portNum, int backLog,

                                 int blocking /* = -1 */, char *hostName /* = NULL */)

Listen for incoming TCP/IP connections.

Inputs:

   int *devHndl      Pointer to device handle that will be returned

                     when a remote device connects to the server.  

   int *svrHndl      Pointer to device handle associated with the

                     server socket.  This handle can be reused to

                     accept multiple connections.

                     This must point to a handle equal to -1 on the

                     first attempt and passed unchanged to

                     subsequent listen calls.

   int portNum       Remote device TCP/IP port number.

   int backLog       Maximum number of connections to allow.

   int blocking      Flag indicating if the open should block until

                     success/failure (1) or return immediately (0).

                     Passing a -1 indicates that the blocking state

                     should remain unchanged from its previous value.

   char *hostName    Local device name (if desired).

Return value:

   Blocking calls:

      This function returns zero if successful or a positive integer

      if the open fails.  If successful, the device handle will be

      stored in the location pointed to by devHndl.  

   Non-Blocking calls:

      This function will return -1 to indicate that no connections

      are pending; call repeatedly until it returns a success or

      failure.

Expand
titleStatic Class Functions
languagenone

Lantronix Terminal Server Driver - tpriRdcLts

Expand
titleOverview

The I/O driver library includes the tpriRdcLts class for communications through a Lantronix terminal server to a remote device.  This class provides functions to open a connection to a specified port on the desired terminal server, to read and write data to and from the device attached to the terminal server, and to close the connection when finished.  Blocking and non-blocking modes are both supported individually for connections and reads.  The library is composed of several static class functions that can be explicitly called without having to manage the underlying class itself.

Expand
titleStatic Class Functions

int tpriRdcLts::open(int *devHndl, char *devName, int portNum, int blocking = -1, struct sockaddr_in *pServer = NULL)

This function is identical to that for the tpriRdcTcp class with the following exception:

Inputs:

int portNum      Desired port number on the terminal server, starting with 1.

int tpriRdcLts::close(int devHndl)

This function is identical to that for the tpriRdcTcp class.

int tpriRdcLts::read(int devHndl, char *rxBuf, int rxCnt, int blocking = -1)

This function is identical to that for the tpriRdcTcp class.

int tpriRdcLts::write(int devHndl, char *txBuf, int txCnt)

This function is identical to that for the tpriRdcTcp class.

int tpriRdcLts:: resetConn(char *devName, int ltsPort, char *password = NULL)

Reset a port on a Lantronix terminal server.  This is useful if a connection to the terminal server died unexpectedly such that the server thinks the connection is still present and will not allow new connections until the original is reset.

Inputs:

char *devName      Remote device name.

int ltsPort      Desired port number on the terminal server, starting with 1.

char *password      The privileged password on the terminal server.  If no password is provided "system" is assumed.

Return value:

If a connection was made to the terminal server then a zero will be returned regardless of whether or not the reset was successful.  A return value of -1 indicates that a connection could not be established.

Expand
titleExample Lantronix Terminal Server

Following is an example class definition and source code for a Lantronix driver using the static function calls above to loop a message through a port on a terminal server back into itself.  It requires that a loopback cable be plugged into the specified port on the Lantronix terminal server.

Code Block
languagec
<DemoLts.cpp>
//------------------------------------------------------------------------
//    File Name        : DemoLts.cpp
//
//    Author           : TelePro, Inc.
//
//    Date (Original)  : 6/15/01
//
//    Hdwr/Sys Config  : Pentium III PC or greater
//                       Windows 2000
//
//    Revision History :
//    Rev     Date       Who/Description
//    1.00    06/15/01   AJ Johnson
//                       Initial Version 
//------------------------------------------------------------------------
//    COPYRIGHT (C) 2001
//    TELEPRO, INC.
//    ALL RIGHTS RESERVED
//
//    THIS SOFTWARE AND ALL INFORMATION AND IDEAS CONTAINED WITHIN
//    ARE THE PROPERTY OF TELEPRO, INC. AND ARE CONFIDENTIAL.
//    NEITHER THIS SOFTWARE NOR ANY PART NOR ANY INFORMATION
//    CONTAINED IN IT MAY BE DISCLOSED OR FURNISHED TO OTHERS
//    WITHOUT THE PRIOR WRITTEN CONSENT OF TELEPRO, INC.
//------------------------------------------------------------------------
//    Function Name: DemoLts
//
//    Function Description and Notes:
//         This program demonstrates communications through a Lantronix
//         terminal server using a loopback test and the static class
//         tpriRdcLts functions to connect, read, write, and close.
//
//    Function type:
//       "C" language void function
//------------------------------------------------------------------------

// Standard header includes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>

// System specific header includes
#include "tpriNtRt.h"
#include "tpriRdcLts.h"

void _cdecl main(int argc, char **argv, char **envp)
   {
   // Variable declarations
   int rstatus = 0;        // this function's return status
   int fstatus = 0;        // function call return status
   int forever = 1;        // Set => 0 when processing loop should exit
   char rxBuf[128];
   char rxCnt = 0;
   char *txBuf = "Test loopback message";
   int txCnt = strlen(txBuf);
   int devHndl = -1;
   char devName[256];
   int portNum;
   int connStat;
   // --------------------------------------------------------------
   // Initialize process management global
   // ------------
   fstatus = tpriProc::Create();
   if (fstatus < 0)
      {
      // unable to initialize process
      LogMsg("DemoLts", DBSS, "Error initializing process commons\n");
      forever = 0;
      }
   else
      {
      LogMsg("DemoLts", DBSS, "DemoLts V1.00\n");
      }
   // --------------------------------------------------------------
   // Set up local process environment using process initialization
   // file parameters
   // --------------------------------------------------------------
   if (forever)
      {
      fstatus = tpriProc::PrIni(argc, argv);
      if (fstatus < 0)
         {
         // unable to initialize process
         LogMsg("DemoLts", DBSS, "Error initializing process\n");
         forever = 0;
         }
      }
   // --------------------------------------------------------------
   // Application Code:
   //     The following code will be run once on initial process execution
   // --------------------------------------------------------------
#ifndef UNDER_RTSS
   WSADATA wsaData;
   int socketInit;
   if (forever)
      {
      // set up windows sockets
      socketInit = WSAStartup(0x0020, &wsaData);
      if (socketInit != 0)
         {
         // error initializing windows sockets
         LogMsg("DemoLts", DBERR, "Error %d starting Windows sockets\n",
            GetLastError());
         forever = 0;
         }
      }
#endif

   if (forever)
      {
      if (argc <= 1)
         {
         LogMsg("DemoLts", DBFERR, 
            "Ini file not specified on command line\n");
         forever = 0;
         }
      else
         {
         // get the LTS IP address
         tpriIniFile::getKeyValue("LtsLoopback", "IPAddress", "localhost", 
            devName, sizeof(devName), argv[1]);

         // get the LTS port number
         tpriIniFile::getKeyValue("LtsLoopback", "LtsPort", "1", 
            rxBuf, sizeof(rxBuf), argv[1]);
         portNum = atol(rxBuf);
         }
      }

   // --------------------------------------------------------------
   // Try to connect
   // -------------------------------------------------------------
   while ((forever) && 
          ((connStat = tpriRdcLts::open(&devHndl, devName, 
                                        portNum, 0)) < 0))
      {
      // -----------------------------------------------------------
      // Call PrWait to stall until the next timer interval
      // -----------------------------------------------------------
      fstatus = tpriProc::PrWait();

      // --------------------------------------------------------
      // Decide whether or not to continue
      // -------------------------------------------------------
      forever &= (tpriProc::getState() > 0);
      }

   if (connStat == 0)
      {
      LogMsg("DemoLts", DBSS, "Connected to terminal server %s port %d\n",
         devName, portNum);

      // write a message out to the terminal server
      if (tpriRdcLts::write(devHndl, txBuf, txCnt) != txCnt)
         {
         LogMsg("DemoLts", DBERR, 
            "Error writing data to terminal server\n");
         }
      else 
         {
         LogMsg("DemoLts", DBERR, 
            "Wrote loopback message <%s> to terminal server\n", txBuf);

         while (forever)
            {
            // read a bit of data
            fstatus = tpriRdcLts::read(devHndl, &rxBuf[rxCnt], 
                         sizeof(rxBuf) - rxCnt, 0);
            if (fstatus > 0)
               {
               // print out what we just received
               DumpHex(DEBUG, (unsigned char *)&rxBuf[rxCnt], 0, fstatus,
                  "Received data");

               // check if this new data completes the message
               rxCnt += fstatus;

               if (memcmp(rxBuf, txBuf, txCnt) == 0)
                  {
                  // bingo! - we got back what we sent
                  rxBuf[txCnt] = 0x00;
                  LogMsg("DemoLts", DBSS, 
                     "Received full loopback message <%s>\n", rxBuf);

                  // fall out of the loops
                  forever = 0;
                  }
               }
               
            // -----------------------------------------------------
            // Call PrWait to stall until the next timer interval
            // -----------------------------------------------------
            fstatus = tpriProc::PrWait();
            
            // ---------------------------------------------------
            // Decide whether or not to continue
            // ---------------------------------------------------
            forever &= (tpriProc::getState() > 0);
            }
         }
         
      // close the connection
      tpriRdcLts::close(devHndl);
      }
   // ----------------------------------------------------------
   // At this point the Application has decided that it no longer wants
   // to be run, so clean up and exit.
   // ------------------------------------------------------------
   LogMsg("DemoLts", DBSS, "Process exiting\n");
   tpriGsmDDCom::Destroy();
   tpriProc::Destroy();

   ExitProcess(rstatus);
   }

<LtsLoopback.ini>

#
#   Example Lantronix terminal server loopback program config file
#
[LtsLoopback]
IPAddress=192.55.195.222
LtsPort=1

Lantronix Cobox Terminal Server Driver - tpriRdcCbx

Expand
titleOverview

The I/O driver library includes the tpriRdcCbx class for communications through a Lantronix CoBox terminal server to a remote device.  This class provides functions to open a connection to a specified port on the desired CoBox terminal server, to read and write data to and from the device attached to the terminal server, and to close the connection when finished.  Blocking and non-blocking modes are both supported individually for connections and reads.  The library is composed of several static class functions that can be explicitly called without having to manage the underlying class itself.

Expand
titleStatic Class Functions

int tpriRdcCbx::open(int *devHndl, char *devName, int portNum, int blocking = -1, struct sockaddr_in *pServer = NULL)

This function is identical to that for the tpriRdcTcp class.

int tpriRdcCbx::close(int devHndl)

This function is identical to that for the tpriRdcTcp class.

int tpriRdcCbx::read(int devHndl, char *rxBuf, int rxCnt, int blocking = -1)

This function is identical to that for the tpriRdcTcp class.

int tpriRdcCbx::write(int devHndl, char *txBuf, int txCnt)

This function is identical to that for the tpriRdcTcp class.

int tpriRdcCbx:: resetConn(char *devName, char *password = NULL)

Reset a port on a CoBox terminal server.  This is useful if a connection to the terminal server died unexpectedly such that the server thinks the connection is still present and will not allow new connections until the original is reset.

Inputs:

char *devName      Remote device name.

char *password      The privileged password on the terminal server.  If no password is provided "system" is assumed.

Return value:

If a connection was made to the terminal server then a zero will be returned regardless of whether or not the reset was successful.  A return value of -1 indicates that a connection could not be established.

Generalized Remote Device Connection Driver

Expand
titleOverview

In addition to the static library functions described above, the tpriRdc-derived classes can be used to as a framework to manage all of the low-level I/O, timing, and error recovery associated with a connection to a remote device.  In effect, the tpriRdc classes act as a fully customizable state machine to communicate with a remote device through a variety of interfaces without having to worry about the specifics of the intermediate hardware or basic communications protocols.  Currently, the following interfaces are supported:

  • Direct serial RS-232

  • Direct TCP/IP

  • TCP/IP to serial via Lantronix 4-, 8-, and 16-port terminal servers

  • TCP/IP to serial via Lantronix CoBox single-port terminal servers

Info

As suggested above, tpriRdc library is actually composed of a set of C++ classes, each of which is specialized to handle a particular type of interface.  The user creates a custom device driver class derived from the tpriRdc class associated with the desired interface, setting the parent properties and filling in the provided virtual functions as appropriate.  A single entry point is then provided to automatically sequence the state machine through establishing the connection and passing data to and from the remote device.

Expand

The interface-specific tpriRdc classes are:

  • tpriRdcSer           Direct serial RS-232

  • tpriRdcTcp           Direct TCP/IP

  • tpriRdcLts            Lantronix multi-port terminal server

  • tpriRdcCbx           Lantronix CoBox terminal server

The custom device driver should be derived from one of these classes in order to build upon and use the functionality encapsulated within these classes.

Expand
titleState Machine Flow

Following is flow path for the state machine:

switch (current state)

      case UNINIT

  • call virtual function initDrv()

 

case IDLE

  • if first pass → goto state CONNECT

  • else if reopen

    • set/test delay timer for reopen

  • else return non-zero from state driver to indicate we’re finished

 

case CONNECT

  • call virtual function setupComm(0) to open connection

  • if success → goto state WAITMSG

  • else if error →

    • call virtual function setupComm(1) to clean up

 

case WAITMSG

  • call virtual function waitMsg() to check if it’s time to send a message

  • if it’s time → goto state BUILDMSG

  • else if it’s not yet time → continue waiting

 

case BUILDMSG

  • call virtual function buildMsg() to assemble the outbound message

  • if return = 0 → goto state XMITMSG

  • else if error → return to state WAITMSG

 

case XMITMSG

  • call virtual function xmitMsg() to send message

  • if return = 0 → goto state WAITRSP

  • else if error →

    • call virtual function setupComm(1) to clean up

    • return to state IDLE

 

case WAITRSP

  • call waitRsp() to read data from interface

  • call virtual function testRsp() to test if a full msg has been recv’d.

  • if full msg recv’d → goto state PROCRSP to process valid message

  • else if timeout → goto state PROCRSP to process empty message

  • else if error →

    • call virtual function setupComm(1) to clean up

    • return to state IDLE

 

case PROCRSP

  • call virtual function procRsp()

  • if return is 0 → goto state WAITMSG

  • else if error → goto state IDLE

 

The state machine for the remote device connection can be executed by calling the following function defined in the tpriRdc base class:

int tpriRdc:: stateDrv(int oneshot = 0)

Close a connection associated with a device handle.

Inputs:

int oneshot      If non-zero, the state machine will execute only once and return.  If zero, the state machine will repeatedly execute until the current state does not change from pass to pass. 

Return value:

Zero if no error and state machine can be called again to continue processing or non-zero if an error has occurred or the state machine has finished.

The state machine for the remote device connection can be executed by calling the following function defined in the tpriRdc base class:

Expand
titleClass Data Members

The following variables are internal data members of the tpriRdc class and the custom driver class should set their values as desired:

char *initStr 

Optional initialization string to be used by the custom class.

int reOpen

Flag indicating if connections should be automatically reopened (1) or not (0).

long reOpenDelay

Time to wait (ms) after communications failure before trying to reconnect to remote device.

int connBlocking 

Flag indicating if the connection is to be blocking (1) or non-blocking (0).

int ioBlocking  

Flag indicating if the device reads are to be blocking (1) or non-blocking (0).

char devName[]  

String specifying the name of the remote device.

long connTimeout  

Amount of time to wait for a non-blocking connection to timeout (ms) or <= 0 for no timeout.

long txTimeout

Amount of time to wait for a non-blocking write to timeout (ms) or <= 0 for no timeout (not currently supported).

long rxTimeout

Amount of time to wait for a non-blocking read to timeout (ms) or <= 0 for no timeout.

int txAttemptMax 

Maximum number of transmission attempts before message fails.

The following variables are internal data members of the tpriRdcTcp class the custom driver class should set their values as desired:

int portNum 

TCP/IP port number to use in the connection

The following variables are internal data members of the tpriRdc class that the custom device class will require for normal processing:

char txBuf[] 

Buffer containing the current message to be transmitted.  This buffer should be filled by the buildMsg() virtual function and will be transmitted by the xmitMsg() function.

int txCnt 

Number of characters in the current message to be transmitted.  This value should be set according to the txBuf[] above.

char rxBuf[]  

Buffer containing all data received by the driver since the last outbound message was sent.  This data should be checked by the testRsp() virtual function and either thrown away with a call to tossRsp(int nToss) or moved to the response buffer as a complete response with a call to ripRsp(int nRsp).

int rxCnt

Number of characters received by the driver since the last outbound message was sent, and consequently the number of bytes currently stored in the rxBuf[] receive buffer.

char *rspBuf

Dynamically allocated received response buffer.  This buffer is automatically allocated when a full response is found in the receive buffer and grabbed with a call to the ripRsp(int nRsp) function.  This buffer should then be processed by the procRsp() virtual function.

int rspCnt

Size of the dynamically allocated received response buffer *rspBuf.  This is automatically set when the buffer is allocated in the ripRsp(int nRsp) function.

Expand
titleClass Virtual Functions

The custom device driver class then overrides a set of virtual functions that will be called by the base classes at the appropriate times.  These virtual functions are:

 

  • Virtual int initDrv()
    The framework calls this function to process one-time initialization of internal parameters including device name, timeout values, max retry counts, etc.  Return zero to indicate success and nonzero to indicate that an error has occurred.

  •  Virtual int setupComm(int oper)
    The framework calls this function to connect (oper <> 0) or disconnect (oper = 0) from the remote device.  Return zero to indicate success and nonzero to indicate that an error has occurred.  This function does not need to be overridden under normal circumstances.

  •  Virtual int waitMsg()
    The framework calls this function to allow the derived class to decide when it is time to send a message to the remote device.  Return zero to indicate a message should now be sent and nonzero to continue waiting.

  •  Virtual int buildMsg()
    The framework calls this function to assemble the next outbound message immediately after the user has returned zero from a call to waitMsg().  The custom driver should copy the outbound message into the class data member txBuf[] character buffer and store the number of characters in the class data member txCnt.

  •  Virtual int xmitMsg()|
    The framework calls this function to transmit data to the remote device.  Return 0 to indicate success or nonzero indicate an error.  This function does not need to be overridden under normal circumstances.

  •  Virtual int waitRsp()
    The framework calls this function to read data from the remote device.  It must also call testRsp() to check if a full message has been received.  Return 0 to indicate reception of a complete message or timeout or -1 to continue reading data.  This function does not need to be overridden under normal circumstances.

  •  Virtual int testRsp()
    The framework calls this function to decide whether or not a response has been received from the remote device.  Upon entry into this function all data received from the remote device since transmission of the most recent message is stored in the class data member rxBuf[] character buffer and the number of received bytes stored in rxCnt.  Any bytes at the beginning of the rxBuf[] buffer that are not part of a valid response may be removed using the class member function tossRsp(int nToss).  If a valid message is found, copy it from the beginning of the rxBuf[] buffer to the response buffer using the class member function ripRsp(nRsp).  Return zero to indicate that the response is complete, less than zero to indicate that the response is incomplete, and greater than zero to indicate that an error has occurred.

  •  Virtual int procRsp()
    The framework calls this function to process a complete response from the remote device.  Return zero to reset and wait until the next message should be sent, and nonzero to reset the connection.

Expand
titleClass Helper Functions

The following functions are internal data methods of the tpriRdc class for use within the custom user driver:

int getState()

Return the current state.

Return value:

The current state is returned as specified in the following table:

UNINIT            0

IDLE            1

CONNECT           2

WAITMSG           3

BUILDMSG          4

XMITMSG           5

WAITRSP           6

PROCRSP           7

void setRxBufSize(int size)

Resize of the internal receive buffer.  Any data existing in the existing buffer will be transferred to the new buffer provided that it does not exceed the new size.  The default size of the receive buffer is 1024 bytes.

Inputs:

int size      New size of receive buffer.

void setTxBufSize(int size)

Resize of the internal transmit buffer.  Any data existing in the existing buffer will be transferred to the new buffer provided that it does not exceed the new size.  The default size of the transmit buffer is 1024 bytes.

Inputs:

int size      New size of transmit buffer.

void ripRsp(int nRsp)

Pops the first nRsp bytes from the receive buffer rxBuf[], dynamically allocates the response buffer *rspBuf, and stores the response there for later processing.  This function should be called from within the testRsp() virtual function once a full response starting at the beginning of the rxBuf buffer has been detected.  Each call to ripRsp(..) destroys the response buffer created by the previous call and shifts the receive buffer so that the remaining data is stored at the beginning of the buffer.

Inputs:

int nRsp      Number of bytes in the detected response that should be copied out of the receive buffer rxBuf[].

      void tossRsp(int nRsp)

Pops the first nRsp bytes from the receive buffer rxBuf[] and throws them away.  The receive buffer is then shifted so that the remaining data is stored at the beginning of the buffer.  This function should be called from within the testRsp() virtual function to throw away bytes at the beginning of the receive buffer that are not part of a valid response.

Inputs:

int nRsp   Number of bytes in the detected response that should be copied out of the receive buffer rxBuf[].

Expand
titleExample Lantronix Terminal Server RDC Driver

The Tsentry source distribution area contains an example class definition and source code for a tpriRdc-derived class used to loop a message through a port on a Lantronix multi-port terminal server back into itself.  It requires that a loopback cable be plugged into the specified port on the Lantronix terminal server.

Allen Bradley Control Logix PLC Driver