THIS IS EXPERIMENTAL CODE !!!!
DON'T CONNECT TO REAL MACHINERY !!!!

IF YOU CONNECT TO PLCs, EXPECT RANDOM PLC DATA, PROGRAM INCLUDED, TO BE
**** OVERWRITTEN ****

EXPECT OUPUTS TO !!! CHANGE RANDOMLY !!!

EXPECT PLCs TO !!! STOP !!!

EXPECT PLCs TO REQIRE !!! COMPLETE ERASE PROCEDURES !!!

DO NOT run the test programs on PLCs where something is connected to their outputs.
DO NOT run the test programs on PLCs where current state must be preserved.
THE TEST PROGRAMS DO INTENTIONALLY MODIFY PLC MEMORY CONTENTS !!!

To use the test programs, you will have to adapt the name of the serial interface to
your needs.

If you test this code with devices others than those listed in the source code,
please let me know whether the code works with them.

News for release 0.6.2:
Seemless integration of (MPI) protocol for IBH-NetLink. PPI over NetLink is still to do.
Pascal unit should be completely compatible with Borland Delphi now.
Users who miss the readoutXXX, runXXX, stopXXX programs: It's in the main tests now. See the options.

News for release 0.6:
Can load program blocks into CPU over MPI, ISO/TCP and PPI. See testMPIload, testPPILoad.
Can write multiple variables in a single request.
Can use single bit variables in multiple read/multiple write requests.

News for release 0.5:
Unified library for MPI, PPI and ISO over TCP.
Can read timers and counters.
Can read and write single bits.

News for release 0.4:

General:
The following applies to all versions of transport but IBH-Link, as I currently 
have none to do tests :-(
Test programs now take options and the name of the serial port.
They do no longer write to your PLC unless you specify it with the -w option.
daveNewConnection has got 2 new parameters, rack and slot, to specify rack and slot for Ethernet
connections.
More of the common stuff went into daveCommon. This way, all transport variants should benefit
immediately from additional possibilities.
A few functions now return correct error codes.


New Features:
Libnodave can now use Ethernet connections to CPs 243,343,443 and both, IT and non-IT versions
of these.
Libnodave can now readout program and data blocks from a PLC. Try the readoutXXX programs.
Libnodave readout SZL Information. I don't know how this is called in English. It's diagnostic
information. SZL stands for "System Zustands-Liste", literally "System State Lists". You
will get only a sequence of bytes. See Siemens Manuals about their meanings. To try it, use
the -z option on the testXXX programs.


ISO over TCP:
Usage:
type ./testISO_TCP to get some hints.
The program assumes you use a CP 343 or 443 with a CPU on rack 0,slot 2.
If somebody has CPUs/other communicating devices on other positions, she can
specify that in daveNewConnection(). Let me know whether it works.
If you use a CP 243, you must specify the -2 option.
This makes a connection of the same kind as MicroWin does. Your CFG-LED will light.
This does not mean that libnodave changes anything in any configuration.
I saw 3rd party OPC servers using the same kind of connection and I gues they will
light your CFG led as well.
The CPs, at least the 243, begin to send a sort of keepalive packets when the connection
is idle. I don't whether LINUX answers these packets correctly. I doubt the way Siemens
implemented that is fully correct.
Anyway, the CP closes the (ISO or logical, NOT tcp) connection after 30 seconds idle. You 
need to connect again with connectPLC() if this happens, or you will get no more answers.
If your application intentionally polls the PLC less often, you should consider to close
the TCP connection willingly and reconnect completely. This may save money on network
connections you pay by time or volume.

MPI:
I integrated the protocol version found by Andrew Rostovtsew, which had been in the /rostic
subdirectory. You can choose it specifying the option -2 to testMPI. See testMPI source about
how to specify the protocol version. I found that an adapter with order code
6ES7 972-0C821-0XAC (or was it 6ES7 972-0CA21-0XAC ?) worked only with that version.

News for release 0.4.1:

MPI:
Fixed a bug in initialization of TS adapter 6ES7 972-0CA33-0XAC.
Seems it didn?t work since 0.3 :-(
New Features:
Libnodave can now make your PLC stop and run.

THE READING OF MULTIPLE VARIABLES, EVEN IF ALREADY BENCHMARKED, IS NOT YET
USEABLE. YOU CANNOT YET RETRIEVE THE RESULTS !!


News for release 0.4.2:

Applied patch for variable Profibus speed from Andrew Rostovtsew. 
The Profibus speed is a new parameter to daveNewInterface, so you will need to change 
existing programs :-(
The parameter is only meaningful for the MPI protocol. It is meaningful for but 
not yet supported by nodaveIBH. For all other protocols, any integer will do.

Cleaned up most warnings.

Bryan D. Payne compiled libnodave under Cygwin successfully, but tested only
ISO over TCP. I did not quite apply his changes, but cleaned up include directives,
provided support in the Makefile and replaced the byteswap.h he used by
conversion functions that can do without it. This will hopefully also easy porting
to other systems.

THE NEW MULTIPLE READ FEATURE:

The protocol allows to read from multiple addresses in the PLC with a single request,
minmizing overhead and time consumtion. The problem with that is that the result cannot 
be returned as a continous byte array. The reason for this is that one of the addresses 
might not exist, e.g. a data block that is not present in the PLC. So there is an error 
information for each single address and the position the user data in the answer varies.

To use multiple read function, do:

PDU p;
daveResultSet rs;	// a special structure to hold result data


davePrepareReadRequest(dc, &p);			// This prepares a read request
daveAddVarToReadRequest(&p,daveInputs,0,0,1);   // Adds a request to read 1 byte from IB0
daveAddVarToReadRequest(&p,daveFlags,0,0,4);	// Adds a request to read 4 bytes from FB0
daveAddVarToReadRequest(&p,daveDB,6,20,2);	// Adds a request to read 2 bytes from DB6:DBB20
daveAddVarToReadRequest(&p,daveFlags,0,12,2);	// Adds a request to read 2 bytes from FB12
res=daveExecReadRequest(dc, &p, &rs);		// Execute all these requests	
/*
    Now, res has the information whether the entire request succeeded.
    If so, the result set contains the four results and their error states. For the exact 
    structure refer to nodaveCommon.h. To read the data using the conversion functions 
    like daveGetByte, daveGetWORD etc., you have to call daveUseResult(dc, rs, <result number>)
    first. daveUseResult() also returns the error status for this particular result.
*/
res=daveUseResult(dc, rs, 0); // first result

/*
    Last, you should call daveFreeResults() with the daveResultSet, to free the memory
    occupied by it.
*/



News for release 0.5:
    Made a unique library for MPI, PPI and ISO over TCP.
    Protocol specific functions are called via pointers to these functions. The pointers
    are initialized in daveNewInterface depending on the choosen protocol.
    As some users reported problems using shared libraries, this is how to do it:
	type make		This will build statically linked test programs and the 
				shared libraries libnodave.so and libnodaveIBH.so.
	type make install	This will copy the shared libraries to /usr/local/lib and
				invoke ldconfig. Now the libraries are available to both, linker
				and program loading mechanism. You may need root rights to execute
				this step successfully.
	type make dynamic	This will build dynamically linked versions of the test programs
				testMPI, testPPI and testISO_TCP named testMPId, testPPId and 
				testISO_TCPd.
				
Have Fun !	