How to connect to a camera via its IP address using Mech-Eye API

In the provided Mech-Eye API sample ConnectToCamera, how to search for and connect to a Mech-Eye camera is demonstrated. If you want to connect directly to a camera using its IP address, the following methods can be used.

Mech-Eye API: C++ version

The following code not only enables you to connect to the camera’s interface by inputting its IP address but also allows you to set the port number and specify the timeout value.

/**
 * @brief Connects to the device by the ip address and port identifying a device.
 * @param [in] ipAddress the device ip address used to connect the device
 * @param [in] port the device port used to connect the device
 * @param [in] timeout the timeout value (ms)
 * @return See @ref ErrorStatus for details.
 */
ErrorStatus connect(const std::string& ipAddress, int port = 5577, int timeout = 10000);

Change the IP address 192.168.1.1 in the C++ program below to the camera’s IP address to connect to the camera. The timeout value, which is 10,000 ms in the program below, should be set according to specific needs.

#include "MechEyeApi.h"
#include "SampleUtil.h"
#include <iostream>

int main()
{
    mmind::api::ErrorStatus status;
    mmind::api::MechEyeDevice device;
    status = device.connect("192.168.1.1", 5577, 10000);

    if (!status.isOK()) {
        showError(status);
        return -1;
    }

    std::cout << "Connected to the Mech-Eye device successfully." << std::endl;

    device.disconnect();
    std::cout << "Disconnected from the Mech-Eye device successfully." << std::endl;
    return 0;
}

Mech-Eye API: Python version

Change the IP address 192.168.1.1 in the C++ program below to the camera’s IP address to connect to the camera. The timeout value, which is 10,000 ms in the program below, should be set according to specific needs.

import re
from MechEye import Device

def connect_camera_ip_capture():
    device = Device()
    status = device.connect_by_ip("192.168.1.1", 5577, 10000)

    if not status.ok():
        print("\n Failed to connect to the camera. ")
        input()
        return False
    else:
        print("Connect Mech-Eye Successfully. ")
        device.disconnect()
        print("Disconnected from the Mech-Eye device successfully. ")


if __name__ == "__main__":
    connect_camera_ip_capture()