To connect a PLC, a client or an Active Partner must specificate three parameterss : IP, Local TSAP, Remote TSAP.
The communication literature says:
ďA Transport Services Access Point (TSAP) is an end-point for communication between the Transport layer (layer 4) and the Session layer in the OSI (Open Systems Interconnection) reference model. Each TSAP is an address that uniquely identifies a pecific instantiation of a service. TSAPs are created by concatenating the node's Network Service Access Point (NSAP) with a transport identifier, and sometimes a packet and/or protocol type.Ē
We, field-mans, only need to know that the TSAP mechanism is used as a further addressing level in the S7 PLC network and contains informations about the resources involved as well.
In accord to the specifications, the TSAP is a generic indicator and could be also a string, in the S7 connection itís a 16 bit word.
Starting from the 1.1.0 release, Snap7 allows to specificate the TSAPs also in a Client connection, this to allow to connect with LOGO and S7200 that need particular TSAP values, just like a Snap7Partner.
To connect a PLC now there are 4 functions client-side, not to be used all in the same time of course, but grouped.
Letís see how do it dividing by two the PLC families:
Use Cli_ConnectTo() specifying IP_Address, Rack, Slot for the first connection, this functions set the internal parameters and connects to the PLC. if a TCP error occurred and a disconnection was needed, for reconnecting you can simply use Cli_Connect() which doesn't requires any parameters. Look at the reference of CLi_ConnectTo for a detailed explanation of Rack and Slot.
Itís possible but itís not mandatory
(Snap7 1.1.0) to specify the connection type via the function Cli_SetConnectionType()
which must be called before Cli_ConnectTo(). By default the client
connects as a PG (the programming console), with this function is
possible change the connection resource type to OP (the Siemens HMI
panel) or S7 Basic (a generic data transfer connection).
In the hardware configuration (Simatic Manager) of the CPU, under ďCommunicationĒ tab, you can change, PLC-side, the connection's distribution, if you need.
PG, OP and S7 Basic communications are client-server connections, i.e. they donít require that the PLC have a connection designed by NetPro.
Note : This is an optimization function, if the client doesnít connect, the problem is elsewhere.
LOGO! 0BA7 /S7 200 via CP243
To connect to these PLC you need to call Cli_SetConnectionParams() and then Cli_Connect().
of PLC IP Address, Local TSAP and Remote TSAP.
There are two chapter dedicated to these PLC, for now letís say that TSAPs must follow what we wrote in the connection editors.
Remember that the TSAPs are crossed : Local TSAP PC-side is the Remote TSAP PLC-Side and vice-versa.
This function only sets the internal parameters, the real connection is made by Cli_Connect().
Note : when you use these functions donít call Cli_SetConnectionType(), it modifies the HI byte of the Remote TSAP !!!.
Itís possible, but uncomfortable,
to connect to a S7300 PLC using these functions as well.
To do this, use 0x0100 as Local TSAP and follow the next formula for the Remote TSAP.
RemoteTSAP=(ConnectionType<<8)+(Rack*0x20)+Slot; // C/C++/C#
RemoteTSAP:=(ConnectionType SHL 8)+(Rack*$20)+Slot; // Pascal
Snap7Server and Snap7Partner (in passive mode) accept any value for Local and Remote TSAP.
The internal connection mechanism is not really changed : all new functions are only for data-preparation.