Versions Compared

Key

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

...

Expand
titleSoftware Driver

The core of the driver is provided as a C++ class that implements the initialization and communications functions.  A sample process is provided which calls the appropriate class members.

The IP address, configuration information, and data areas to be read and written are passed as calling parameters to the class functions.

The following is a list of the provided driver files.  After review of the example driver, the user is required to modify the files as indicated:

File Name

Description

Modification

ModPlc.cpp

Driver mainline function

Modify configuration class calls for specific PLC configuration.  Modify locations to read and write data.  Modify input and output datagram structure definition

ModPlcIn.cpp

ModPlc driver initialization

Insert required global common areas. 

PlcUsr.cpp

Process received values from PLC datagram and place in user data variables.

Get application variables and store in datagra for transmission to PLC

Change as required

TpriModPlc Class Descriptions

Expand

Expand
titleClass Inferface

The following public member functions are provided as part of the tpriModPlc class:

  • tpriModPlc *pModPlc = new tpriModPlc;

Allocate a new tpriModPlc object

 

  • destroy (tpriModPlc *)pModPlc();

Destroy the tpriModPlc class object.

 

 

  • int SetTraceLevel (int TraceLevel);

where:

int TraceLevel = debug trace level for class operations

                           default value = 30

                           valid values range between 0 and 100, inclusive

                           lower values produce less debug information

                           higher values produce more debug information

                           debug information written using LogMsg function

This function stores a new value for the TraceLevel parameter

 

  • int SetTimeOut (int sTimeOut, int rTimeOut, unsigned char ticktime,

                              unsigned char timeoutticks, unsigned char timeoutmultiplier,

                              unsigned long otrpi, unsigned long torpi );

where:

int sTimeOut = Send message timeout value in milliseconds

                                    Default value = 2000

int rTimeOut = receive message timeout value in milliseconds

                                    Default value = 2000

This function stores timeout parameter values for use by the member functions of the class

 

  • int int SetDestinationInfo(unsigned char destID);

where:

unsigned short vendorid = Destination ID

default value = 1

This function stores new values for the Destination ID

 

  • int SetPduMaxIoDataBytes (int noBytes);

where:

int noBytes = the maximum number of data bytes that will be placed in a single PDU

                           default value = 125

                           a PDU is a protocol Data Unit and is equivalent to a single Ethernet frame   

                           valid values range between 2 and 125, inclusive

                           lower values may produce more frames to transfer the same user data

                           higher values may produce fewer frames to transfer the same user data

This function sets a new value for the maximum number of user data bytes to be included in a single Ethernet frame (PDU) that is transmitted to the PLC.  A value too low will increase the number of Ethernet frames that will be required to send a given number of user data bytes and reduce throughput. A number too high will not be understood or acknowledged by the PLC.  

 

  • int Connect (char *hostname, short int port);

where:

char *hostname = host name, or

IP addresses expressed as a character string

short int port = TCP/IP port number

This function establishes a connection between the computer system and the Modicon PLC

 

  • int Disconnect ();

This function breaks a connection between the computer system and the Modicon PLC

 

  • int read4x (int offset, int noElements, void *buf);

where:

int offset = PLC memory offset in 16 bit words from which to read data

int noElements = number of 16 bit integer data elements to read

void *buf = address of user supplied data buffer

This function reads a single data block of 16 bit integers values from the PLC user register memory starting at ‘offset’ words from 40000 and stores the results in a user defined buffer

 

  • int writ4x (int offset, int noElements, void *buf);

where:

int offset = PLC memory offset in 16 bit words from which to write data

int noElements = number of 16 bit integer data elements to write

void *buf = address of user supplied data buffer

This function writes a single block of user supplied 16 bit data words to the PLC user register memory starting at ‘offset’ words after 40000