Functions | |
MLPIRESULT | mlpiApiConnect (const WCHAR16 *connectionIdentifier, MLPIHANDLE *connection) |
MLPIRESULT | mlpiApiDisconnect (MLPIHANDLE *connection) |
MLPIRESULT | mlpiApiSetDefaultTimeout (const ULONG timeout) |
MLPIRESULT | mlpiApiGetDefaultTimeout (ULONG *timeout) |
MLPIRESULT | mlpiApiIsConnected (const MLPIHANDLE connection, BOOL8 *isConnected) |
MLPIRESULT | mlpiApiTestConnection (const MLPIHANDLE connection, const ULONG payload, const ULONG numMeasurements, MlpiConnectionInfo *info) |
MLPIRESULT | mlpiApiNotifyAlive (const MLPIHANDLE connection) |
The following functions are used for initializing and configuring the API. This has to be done at least once and before the user application wants to use the MLPI-API.
MLPIRESULT mlpiApiConnect | ( | const WCHAR16 * | connectionIdentifier, |
MLPIHANDLE * | connection | ||
) |
This function connects the user application with a specified MLC/MLP/XLC. The first argument of the connect ident string is used to specify the target device to which you want to connect. This can either be the same physical device as your application or a device that is connected via a network. In this case you have to give the IP or host name to the target. As an alternative, this address argument can be set as an option on each place within the connect ident string.
Additionally, the communication to the target can be insecured (MLPI) or secured (MLPIS). MLPI is achieved with the use of the TCP/IP protocol that allows to establish a connection with the target device and the information exchanged within this connection is unencrypted. MLPIS is achieved with the use of the TLS/SSL protocol that allows to encrypt the information exchanged. See MLPI and MLPIS for more information about these two communication protocols.
To establish an MLPIS connection the arguments 'tls' needs to be specified (as seen in the table below), if it is not given, then non secure MLPI connection is used by default. The client is not required to provide credentials (i.e. private key and certificate), however, the server must provide them. These credentials are automatically generated in targets with Firmware versions starting with version 14V18. They can also be replaced by other credentials as specified in MLPIS.
On a successful connect, the function returns a connection handle on the second argument. Use this connection handle for subsequent calls to mlpi functions.
It is also possible to set additional options in the connect string as an argument list.
Option | Description |
---|---|
user=value | Login name of user. See Permission and user management for more information about user and permission system. |
password=value | Password of user. See Permission and user management for more information about user and permission system. |
address=value | IP or URL path of connection. |
timeout_connect=value | Timeout used for connecting in milliseconds (infinite: MLPI_INFINITE). |
timeout_send=value | Timeout of MLPI client used for sending data to server (target) in milliseconds (default: 0, infinite: MLPI_INFINITE). |
timeout_receive=value | Timeout of MLPI client used for receiving data from server (target) in milliseconds (default: 0, infinite: MLPI_INFINITE). |
auto_reconnect=value | If set to 1 or 'true', then the MLPI will try to reconnect with each new call of any MLPI function after connection was lost. For connecting, the same timeout settings are used as given for the first connect (default: false). |
keepalive_mode_server=value | If set to 1 (default, isn't set), then the MLPI server will send a MLPI keepalive telegram after keepalive timeout, if the client does not send any request before. If set to 0, then MLPI server will not send any MLPI keepalive telegrams. |
keepalive_timeout_server=value | Timeout used for sending MLPI keepalive telegram in milliseconds (default: 30000). |
keepalive_probes_server=value | Number of probes for sending MLPI keepalive telegram (default: 10). |
timeout_send_server=value | Timeout of MLPI server used for sending data to client in milliseconds (default: 60000, infinite: MLPI_INFINITE). |
require_hash=value | If true, then only logins to servers which support hashed password logins are allowed. Server version has to be greater than 1.1.1.0 (default: false).
|
protection=value | Select your protection level using values of MlpiApiProtection to protect your connection against closing by an other connection with the assistance of call of mlpiApiCloseConnectionByUid, mlpiApiCloseConnectionsByUser or mlpiApiCloseConnectionsByUri.
|
tls=value | If set to 'active', then MLPI is tunneled through TLS rather than TCP, thus providing data confidentiality and integrity for the connection (default: false). It is highly recommended to change this setting to true if possible. |
A timeout value of 0 means that the timeout value is to be chosen automatically by the operating system. If no timeout is specified here, the global default value as set by the function mlpiApiSetDefaultTimeout is used. This means that any option given here will override the value as set by mlpiApiSetDefaultTimeout. In most cases it is not recommended to override the timeout values. Especially the send and receive timeouts should stay at their default values of 0.
The second argument is handy if you want to establish more than one connection using the MLPI. For example, if you want to connect to two or more devices at the same time. Or if you want to have more than a single connection to the same device. As already noted, you have to pass a pointer to a MLPIHANDLE
variable as second argument to this function. If the function succeeds, it will return a handle which identifies your connection. Use this handle as first argument to all existing MLPI functions. This way, the MLPI function knows on which connection and therefore on which target to execute the MLPI function.
If no request telegram of the MLPI client will be received by the MLPI server, by default, the MLPI server will send on any 'keepalive_timeout_server' milliseconds timeout an empty MLPI keepalive telegram. This is done to check if the client machine is still reachable or if the connection can be closed and freed again. The server will repeat this keepalive telegram for 'keepalive_probes_server' times. After this time ('keepalive_timeout_server' * 'keepalive_probes_server'), the MLPI server waits 'timeout_send_server' milliseconds until the connection is closed finally.
Use case | Return value |
---|---|
Successful connect to a MLPI device. | Positive value. |
The given connection ident string doesn't contain an address. | MLPI_E_INVALIDARG |
No MLPI device found at the given address, e.g. invalid IP address. | MLPI_E_CONNECTFAILED |
A connection could not be established in the given timeout time as provided by mlpiApiSetDefaultTimeout or "-timeout_connect=xxxx". | MLPI_E_TIMEOUT |
MLPI device found, but connection refused because of incompatible version of client library and mlpi device. | MLPI_E_VERSION |
MLPI device found, but connection refused because of missing privileges or invalid user/password settings. | MLPI_E_PERMISSION |
MLPI device found, but connection refused because there are already too much clients or user connected. | MLPI_E_LIMIT_MAX |
A connection could not be established because there was an error with the provided private key. | MLPI_E_INVALID_PRIVATEKEY_FILE |
A connection could not be established because there was an error with the provided certificate. | MLPI_E_INVALID_CERTIFICATE_FILE |
A connection could not be established because the private key and certificate do not match one another. | MLPI_E_KEYPAIR_MISSMATCH |
A connection could not be established because there was an error with the TLS handshake. | MLPI_E_TLS_HANDSHAKE_FAILED |
A call to any other MLPI function prior to calling mlpiApiConnect will return MLPI_E_NOCONNECTION
. If a send or receive timeout is set and a MLPI function call times out due to these settings, then this MLPI function call will return MLPI_E_TIMEOUT
. The connection is then inconsistent and will therefore be closed automatically. Any following MLPI function call will then return with MLPI_E_NOCONNECTION
. This means that after a timeout, a new connection has to be established using mlpiApiConnect unless you made the connect with optional argument auto_reconnect=true
(see above). In this case, the MLPI tries to reconnect in the context of each new MLPI function call.
[in] | connectionIdentifier | The connect ident string identifying the device. Use MLPI_LOCALHOST to connect to the system running on the same host device. Use an IP address to connect over Ethernet to another device. This string may also contain an additional argument list (options). |
[out] | connection | Returns handle of connection, if successful. Has to be canceled by calling mlpiApiDisconnect. Calling mlpiApiConnect without corresponding mlpiApiDisconnect on application termination will result in a memory leak! |
MLPIRESULT mlpiApiDisconnect | ( | MLPIHANDLE * | connection | ) |
This function disconnects the user application from the target.
The connection identified by the handle is closed and destroyed. It is then not allowed to use the handle in any subsequent MLPI call.
[in] | connection | Handle for multiple connections. |
MLPIRESULT mlpiApiSetDefaultTimeout | ( | const ULONG | timeout | ) |
This function sets the default timeout for remote procedure calls done by the API. The timeout is used for connecting, sending and receiving data. During the debugging of your application, you might want to set this value to MLPI_INFINITE
.
[in] | timeout | This is the timeout in milliseconds when doing remote procedure calls via the MLPI-API. |
MLPIRESULT mlpiApiGetDefaultTimeout | ( | ULONG * | timeout | ) |
This function reads the default timeout for remote procedure calls done by the API. This might not be the value that is set for a currently active connection.
[out] | timeout | This is the timeout in milliseconds when doing remote procedure calls via the MLPI-API. |
MLPIRESULT mlpiApiIsConnected | ( | const MLPIHANDLE | connection, |
BOOL8 * | isConnected | ||
) |
This function returns the current state of the MLPI connection. If FALSE
is returned, then the connection is either not yet established or closed because of an error in communication or because mlpiApiDisconnect has been called. In all cases a reconnect using mlpiApiConnect has to be made to make new MLPI function calls. If connection is lost for unknown reason, try increasing the connection timeout using mlpiApiSetDefaultTimeout.
[in] | connection | Handle for multiple connections. |
[out] | isConnected | Returns TRUE if connection is established and FALSE if disconnected. |
MLPIRESULT mlpiApiTestConnection | ( | const MLPIHANDLE | connection, |
const ULONG | payload, | ||
const ULONG | numMeasurements, | ||
MlpiConnectionInfo * | info | ||
) |
This function performs a benchmark on the MLPI communication mechanism. Use it to measure the duration of a MLPI function call with the given payload in bytes. The resulting timing values are the durations which are necessary to marshal the payload, send the payload to the MLPI server, unmarshal it on the MLPI server, perform the remote procedure call, marshal the results, send them back to the MLPI client unmarshal them again and return them to the client thread program. These are the basic costs needed for nearly every MLPI call.
[in] | connection | Handle for multiple connections. |
[in] | payload | Payload in number of bytes that is used for the MLPI communication to be measured. |
[in] | numMeasurements | Number of measurements to do for calculating the average resulting timing values. |
[out] | info | Pointer to structure which receives the calculated timing values. |
MLPIRESULT mlpiApiNotifyAlive | ( | const MLPIHANDLE | connection | ) |
This function notifies the MLPI server that the client is still alive. You may need this function if you use the keepalive mechanism of the MLPI server (mlpiApiConnect).
[in] | connection | Handle for multiple connections. |