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 Industrial 3D Camera

Mech-Eye API: C++ 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.

For Mech-Eye SDK 2.2.0 and later:

#include "area_scan_3d_camera/Camera.h"
#include "area_scan_3d_camera/api_util.h"

int main()
{
    mmind::eye::Camera camera;
    showError(camera.connect("192.168.1.1",10000));
    std::cout << "Connected to the camera successfully." << std::endl;
    camera.disconnect();
    std::cout << "Disconnected from the camera successfully." << std::endl;
    return 0;
}

For Mech-Eye SDK 2.1.0 and earlier:

#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 camera successfully." << std::endl;
    device.disconnect();
    std::cout << "Disconnected from the camera 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.

For Mech-Eye SDK 2.2.0 and later:

from mecheye.shared import *
from mecheye.area_scan_3d_camera import *
from mecheye.area_scan_3d_camera_utils import *

def connect_camera_ip_capture():
    camera = Camera()
    status = camera .connect("192.168.1.1", 10000)

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


if __name__ == "__main__":
    connect_camera_ip_capture()

For Mech-Eye SDK 2.1.0 and earlier:

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()

Mech-Eye API: C# 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.

For Mech-Eye SDK 2.2.0 and later:

using System;
using MMind.Eye;

class ConnectIP
{
    static int Main()
    {
        var camera = new Camera();

        Utils.ShowError(camera.Connect("192.168.1.1",10000));

        camera.Disconnect();
        Console.WriteLine("Disconnected from the camera successfully.");
        Console.WriteLine("Press any key to exit ...");
        Console.ReadKey();
        return 0;
    }
}

Mech-Eye 3D Laser Profiler

Mech-Eye API: C++ 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.

For Mech-Eye SDK 2.2.0 and later:

#include <iostream>
#include <thread>
#include <chrono>
#include "profiler/Profiler.h"
#include "profiler/api_util.h"

int main()
{
    mmind::eye::Profiler profiler;
    showError(profiler.connect("192.168.1.1"));
    std::cout << "Connected to the camera successfully." << std::endl;
    profiler.disconnect();
    std::cout << "Disconnected from the camera successfully." << std::endl;
    return 0;
}

Mech-Eye API: C# 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.

For Mech-Eye SDK 2.2.0 and later:

using System;
using MMind.Eye;

class PrintProfilerStatus
{
    static int Main()
    {
        var profiler = new Profiler();
        Utils.ShowError(profiler.Connect("192.168.1.1",10000));
        Console.WriteLine("Connected to the camera successfully.");
        profiler.Disconnect();
        Console.WriteLine("Disconnected from the profiler successfully.");
        Console.WriteLine("Press any key to exit ...");
        Console.ReadKey();
        return 0;
    }
}