Supposing that TerminateCondition()is a boolean function that //returns true when the thread needs to be terminated. In Unix you have to use nanosleep() instead of sleep() or copy Supposing that TerminateCondition()is a bool function that //returns true when the thread needs to be terminated. Sleep(TimeRate) // exchange time interval In the thread body we could write something like this: Let's suppose that we have a Client that cyclically exchanges data into a thread and we want a fast recovery in case of network problems or PLC power.
Now let's see how to take full advantage of this feature. If all they fail, SmartConnect is disabled and all the clients (or Active partners) created will try to connect directly. We use it as B-plan since we need administrative privileges to create RAW sockets in Vista/Windows 7/Windows 8.įrom 1.3.0 an Async (with timeout) TCP connection is used so root rights are no more needed.ĭuring the initialization, the library checks if the ping can be performed trying the above methods. If its load fails (very rare case), an ICMP socket is created to perform the ping. The system library iphlpapi.dll is used, but it’s is loaded dynamically because it’s not officially supported by Microsoft (even if it is present in all platforms and now it’s fully documented by MSDN). Snap7 uses two different ways to do this, depending on the platform: When we call Cli_ConnectTo(), or when an active Snap7Partner needs to connect, first the PLC is “pinged”, then, if the ping result was ok, the TCP connection is performed. Unlike the TCP connection timeout, The ping time is fixed and we can decide how much it should be. The SmartConnect feature relies on this principle to avoid the TCP connection timeout when a PLC is off or the network cable is unwired. Said that, if we "can ping" a PLC we are almost sure that it can accept our connections.
If the server is PC based, the first condition not always implies the second.īut for specialist hardware firmware-based such as the PLC, the things are different, few seconds after the power on all the services are running.
A Server software listening for our connection must be running.
When we try to connect to a generic server, basically two requirements must be met.Ģ. If this data size exceeds the PDU size, the packet is automatically split across more subsequent transfers. To meet this, Snap7Client exposes three interesting features : PDU Independence, SmartConnect and Asynchronous data transfer.Īs said, every data packet exchanged with a PLC must fit in a PDU, whose size is fixed and varies from 240 up to 960 bytes.Īll Snap7 functions completely hide this concept, the data that you can transfer in a single call depends only on the size of the available data. Snap7 library is designed keeping in mind large industrial time-critical data transfers involving networks with dozen of PLCs. What I think is important to highlight, is its advanced characteristics. You certainly have a clear idea about its use, its functions and their use are explained in detail into the Client API reference of the Snap7 Manual. It fulfills almost completely the S7 protocol, you can read/write the whole PLC memory (In/Out/DB/Merkers/Timers/Counters), perform block operations (upload/download), control the PLC (Run/Stop/Compress.), meet the security level (Set Password/Clear Password) and almost all functions that Simatic Manager or Tia Portal allows. The same OPC Server, despite to its name, is a client against the PLC. Into S7 world, LibNoDave, Prodave, SAPI-S7 (Simatic Net mn library) are clients.
A PLC client is the most well-known object, almost all PLC communication drivers on the market are clients.