GigeVision

repository·master·Indexed 41 days ago

https://github.com/touseefelahi/gigevision

A C# implementation of the GigE Vision standard supporting the GigE Vision Streaming Protocol (GVSP) and GigE Vision Control Protocol (GVCP). It provides functionality to discover cameras on a network, read and write registers, read memory, manage camera control via heartbeats, and stream raw video data.

Tokens
1K
Snippets
6
Records
6
Agent score
1%

What's inside GigeVision

  1. Write to a register using GVCP

    master

    Writing to a register requires taking control of the camera. You can use the TakeControl() method, which handles writing to the CCP register. If successful, you must periodically send true to the heartbeat mechanism to maintain control. Once control is acquired, use WriteRegisterAsync to write the value to the target register.

    var gvcp = new Gvcp
    {
        CameraIp = "192.168.10.99"
    };
    if (await gvcp.TakeControl())
    {
        var reply = await gvcp.WriteRegisterAsync("0x0D04", 1000);
    }
    else
    {
        throw new Exception("Camera is already in control");
    }
  2. Discover all GigE cameras in the network

    master

    Use the Camera class and its Gvcp property to scan the network for available GigE devices. The GetAllGigeDevicesInNetworkAsnyc method returns a list of detected devices.

    var camera = new Camera();
    var listOfDevices = await camera.Gvcp.GetAllGigeDevicesInNetworkAsnyc().ConfigureAwait();
  3. Stream raw video data from a camera

    master

    To receive a raw byte stream from a camera:

    1. Initialize the Camera object with the camera's IP address.
    2. Subscribe to the FrameReady event to handle incoming raw bytes.
    3. Call StartStreamAsync with the IP address of the local network interface (the PC's IP) to begin streaming.

    Note: If you have multiple network interfaces, you must explicitly define the receiver IP in StartStreamAsync.

    // 1. Initialize
    var camera = new Camera("192.168.10.224");
    
    // 2. Subscribe to event
    camera.FrameReady += FrameReady;
    
    // 3. Start stream (using PC IP, e.g., 192.168.10.221)
    bool isStarted = await camera.StartStreamAsync("192.168.10.221").ConfigureAwait(false);
    
    // Event handler implementation
    private void FrameReady(object sender, byte[] e)
    {
      // e contains the raw data in bytes
    }
  4. Set a fixed IP for a camera using ForceIPAsync

    master

    You can assign a specific IP address to a camera by using its MAC address via the ForceIPAsync method. This is useful for ensuring a detected camera always uses a specific IP.

    var camera = new Camera();
    var listOfDevices = await camera.Gvcp.GetAllGigeDevicesInNetworkAsnyc().ConfigureAwait(true);
    if (listOfDevices.Count > 0)
    {
        camera.Gvcp.ForceIPAsync(listOfDevices[0].MacAddress, "192.168.10.243");
    }
  5. Read memory using GVCP

    master

    Use ReadMemoryAsync to read a specific number of bytes from a memory address. The method takes the memory address (e.g., "0x0D04") and the number of bytes to read (e.g., 500).

    var gvcp = new Gvcp();
    gvcp.CameraIP = "192.168.10.99";
    var reply = await gvcp.ReadMemoryAsync("0x0D04", 500); // To read 500 bytes from memory address 0x0D04
  6. Read a register using GVCP

    master

    To read a specific register, instantiate a Gvcp object, set the CameraIP property, and call ReadRegisterAsync with the register address (e.g., in hex format like "0x0D04").

    var gvcp = new Gvcp();
    gvcp.CameraIP = "192.168.10.99";
    var reply = await gvcp.ReadRegisterAsync("0x0D04");