-
-
Notifications
You must be signed in to change notification settings - Fork 75
Connection
These methods allow controlling the behaviour a Client Object.
Function | Purpose |
---|---|
ConnectTo | Connects a S7Client object to a PLC |
Connect | Connects a S7Client object to a PLC with implicit parameters |
Disconnect | Disconnects a S7Client |
SetConnectionType | Sets the connection type (PG/OP/S7Basic) |
SetConnectionParams | Sets Address, Local and Remote TSAP for the connection |
Connects the client to the hardware at (IP, Rack, Slot) Coordinates.
public int ConnectTo(String Address, int Rack, int Slot)
Name | Type | Note |
---|---|---|
Address | string | PLC IPV4 Address e.g.: "192.168.1.10" |
Rack | int | see table |
Slot | int | see table |
-
0 : The Client is successfully connected (or was already connected).
-
Other values : see the Errors Code List.
In addition to the IP Address, that we all understand, there are two other parameters that index the unit : Rack (0..7) and Slot (1..31) that you find into the hardware configuration of your project, for a physical component, or into the Station Configuration manager for WinAC.
There is however some special cases for which those values are fixed or can work with a default as you can see in the next table.
PLC | Rack | Slot | |
---|---|---|---|
S7 300 CPU | 0 | 2 | almost always, but according to the hw config |
S7 400 CPU | not fixed | not fixed | according to the hw config |
WinAC CPU | not fixed | not fixed | according to the hw config |
S7 1200 CPU | 0 | 0 or 1 | |
S7 1500 CPU | 0 | 0 or 1 | |
WinAC IE | 0 | 0 | according to the hw config |
Connects the client to the PLC with the parameters specified in the previous call of ConnectTo() or SetConnectionParams().
public int Connect()
- 0 : The Client is successfully connected (or was already connected).
- Other values : see the Errors Code List.
This function can be called only after a previous of ConnectTo() or SetConnectionParams() which internally sets Address and TSAPs.
Disconnects “gracefully” the S7Client from the PLC.
public void Disconnect()
This function can be called safely multiple times. After calling this function LastError = 0 and Connected = false.
Sets the connection resource type, i.e. the way in which the Clients connects to a PLC.
public void SetConnectionType(short ConnectionType)
Name | Type | Note |
---|---|---|
ConnectionType | short | See the table |
Connection Type | Value | Helper Const |
---|---|---|
PG | 0x01 | S7.PG |
OP | 0x02 | S7.OP |
S7 Basic | 0x03..0x10 | S7.S7_BASIC |
Sets internally (IP, LocalTSAP, RemoteTSAP) Coordinates.
public void SetConnectionParams(String Address, int LocalTSAP, int RemoteTSAP)
Name | Type | Note |
---|---|---|
Address | string | PLC IPV4 Address e.g.: "192.168.1.10" |
LocalTSAP | int | Local TSAP (PC TSAP) |
RemoteTSAP | int | Remote TSAP (PLC TSAP) |
This function must be called just before Connect().