The following provides a basic methodology for using the
NetworkConnection step:
-
To establish the connection, place the NetworkConnection step
before the first NetworkReader
step or NetworkWriter
step. Note that the NetworkConnection step
should also be placed before the primary programming loop.
-
In the
Configuration pane, specify a Connection name. Subsequent
steps from the Network step category will
use the Connection
name to access the connection.
-
Choose a Protocol type. Note that the
chosen protocol must be the same for both the network client and
your project. Refer to the documentation that came with your
connecting device to determine its protocol.
-
Specify the Operation to be performed
(for example, open a connection). Note that the operations
available are limited based on the chosen protocol.
-
Specify the Port number of your runtime
platform. By default, this value is set to 5555.
-
When listening for a TCP connection, the port number specifies
the local port that accepts incoming connection requests. When
connecting, the port number specifies the port on which your
network client is listening for the connection. Refer to the
documentation that came with your connecting device to determine
your port number.
-
Specify the IP
address or Host name for the connection with your network
client. Note that you can learn the name of your development
computer and its IP address by running the Matrox Network Client
utility. This information is displayed in the utility's title
bar.
-
Modify the Encoding scheme for the
data, to match that of your network client, if the default does not
match.
-
Configure your
network client.
-
To close the connection, place a second NetworkConnection step after
the last NetworkReader
step or NetworkWriter
step.
-
In the
Configuration pane, set the Name of the connection to
close to the name used when creating the connection.
-
Set the Operation to close the
connection.
Once a connection has been established, Matrox Design Assistant
is able to communicate with the network device so long as the
connection remains intact. Connections might be terminated
intentionally, when one side or the other closes the connection, or
unintentionally, for example due to a power cycle or physical cable
disconnection.
Properly closed connections will be reported as Disconnected in
the Status
property of the NetworkConnection step,
NetworkReader
step, and NetworkWriter
step. Unfortunately accidental breaks in the connection are not
signaled to the camera, and a NetworkReader
step on a broken connection will wait until the Timeout property is reached
(which could be infinitely long).
Furthermore, even when the original cause of the disconnection
has been fixed, the project will not reconnect unless the flowchart
is set up to deal with this possibility.
To maintain robust communication that can handle unforeseen
disconnections is a shared responsibility of both sides. It depends
on the project and also on the behavior of the computer, PLC or
robot controller with which you are communicating, and so is beyond
the scope of the User Guide. However the following recommendations
will form the base of a more robust setup:
-
Set the Timeout property in the
NetworkReader
step to a finite time. If an unplanned disconnection occurs, the
NetworkReader
step will wait, stalling the project until the timeout expires.
Note that if there is a timeout, the Status property value will
be TimedOut.
-
Use a
Condition step to check the Status property of a
NetworkReader
step before accessing the ReceivedData property. If
the Status is
not equal to DataRead, trying to access the data will cause a
runtime error and terminate the project.
-
It is not necessary to check the Status property of every
NetworkWriter
step, but verifying periodically that the last NetworkWriter
step has a Status of DataWritten can
help detect a broken connection.
If a read has timed out, or data has not been written, you can
signal the situation through discrete IO or the HMI and let an
operator take corrective action or you can add a NetworkConnection step that
attempts to reconnect and then checks to see if the connection has
succeeded.
Note that the list of possible Status property values in
the Verify option includes Connected, which only applies to TCP
connections, and Opened, which only applies to the less frequently
used UDP protocol.
In some situations a watchdog handshake protocol is used to
check the existence of the connection periodically. Similar to a
ping, one side writes a short message and waits for a response. If
the response is not received it then attempts to close the network
connection and try to re-establish a new one. Typically the
handshaking is done with a dedicated second connection on a
separate port.