Initialization
Use PnSServiceConnectRealtime to establish a connection; after obtaining the handle, call it once PnSServiceStart; within the loop, write to Q and read from I.
First, install the Darra Profinet Slave. Set the station name and network card in the configuration tool; there’s no need to specify them here. Do not perform “Connect” or “Close” operations every cycle.
C No constructor. Only one live session is allowed at a time; the second one returns PNS_ERR_BUSY.
Create a Session
PnSServiceConnectRealtime()
pns_result_t PnSServiceConnectRealtime(pns_service_handle_t * p_session);
Creates a new session and returns a handle. This will fail if the service is not running. This merely retrieves the handle; the service has not yet been activated IO,IO and the controller has not yet been connected. You must call it again PnSServiceStart.
When it fails, it is *p_session NULL.
Parameters:
p_session(pns_service_handle_t *) — Return value: session handle (if successful)
Return value:
PNS_OKSuccessPNS_ERR_BUSYThere are other active sessionsPNS_ERR_NO_CONNECTIONService UnavailablePNS_ERR_INVALID_PARAMInvalid parameterPNS_ERR_MEMORY/ Failed toPNS_ERR_NATIVEallocate or establish a session
Example:
pns_service_handle_t session = NULL;
if (PnSServiceConnectRealtime(&session) != PNS_OK)
return 1;
if (PnSServiceStart(session) != PNS_OK)
return 1;
while (running)
{
/* Write "Q", read "I" — write it here */
}
PnSServiceStop(session);
PnSServiceClose(session);
Handles span the entire program lifecycle; loops are written in Close Previously. Start Once is enough. Q Close is cleared at the end of each cycle, so anything written to it in the next cycle will be discarded.
Start-Stop
PnSServiceStart()
pns_result_t PnSServiceStart(pns_service_handle_t session);
Enable IO, then return pns_result_t. Success does not necessarily mean the IO controller is already switching data; that depends on PnSServiceIsConnected. If it has already been started but not yet stopped, calling it again will return immediately PNS_OK.
Failure PnSServiceLastError: Return code; PNS_ERR_INVALID_PARAM Invalid handle: Return code; Service did not start PNS_ERR_NO_CONNECTION: Return code; Startup failure PNS_ERR_NATIVE: Return code.
Example:
pns_result_t rc = PnSServiceStart(session);
if (rc != PNS_OK)
{
printf("%s\n", PnSServiceLastError(session));
return 1;
}
PnSServiceStop()
pns_result_t PnSServiceStop(pns_service_handle_t session);
Disabled IO. The handle still exists, so it can be reused Start. If it has never been started or has already been stopped, calling it again is fine. If it fails, log it PnSServiceLastError.
Completely liberalize the use of PnSServiceClose(), No Stop().
Example:
PnSServiceStop(session);
Resource Release
PnSServiceClose()
pns_result_t PnSServiceClose(pns_service_handle_t session);
If it's still running Stop, release the handle first. Q will be cleared (only the data area); I will be retained for the next program. NULL The handle is safely returned PNS_OK. Once released, this handle can no longer be used and must be reallocated PnSServiceConnectRealtime.
Disable IO PnSServiceStop(). Stop The handle is still there, so you can Start.
Example:
PnSServiceClose(session);