If connection issues arise when using the ‘connect’ interface, it is necessary to verify if it aligns with the demonstrated methods in the example.
-
Taking the C++ version in Mech-Eye SDK as an example.
-
The image below shows the ‘connect’ interface. You can connect by selecting the camera index from the list or by manually entering the IP address, port, and connection timeout. In either case, you can use ‘disconnect’ to terminate the connection.
-
The ConnectToCamera sample demonstrates the usage of the ‘connect’ interface.
-
status = device.connect(deviceInfoList[inputIndex]);
This line of code attempts to connect to a Mech-Eye device.deviceInfoList
is the list of device information, andinputIndex
is the index indicating the device to connect to. The program tries to establish a connection with the device at the specified index in the device information list, and the result of the connection is stored in a variable namedstatus
. -
if (!status.isOK()) {
Here begins a conditional statement that checks ifstatus
indicates a successful connection (status is OK). If the connection is not successful, the code block within the conditional statement is executed. -
showError(status);
If the connection fails, the program calls a function namedshowError
and passes the connection statusstatus
as a parameter. This function is used to display connection error messages. -
return -1;
If the connection fails, the program returns a non-zero value (-1), indicating an error in the program execution. -
std::cout << "Connected to the Mech-Eye device successfully." << std::endl;
If the connection is successful (i.e., the status in the conditional statement is OK), this line of code outputs a message to the console, indicating a successful connection to the Mech-Eye device. -
device.disconnect();
This line of code performs disconnection from the Mech-Eye device. -
std::cout << "Disconnected from the Mech-Eye device successfully." << std::endl;
This line of code, after disconnecting, outputs a message to the console indicating a successful disconnection from the Mech-Eye device. -
return 0;
Finally, the program returns 0, indicating successful completion of the program.