Upgrading to CVB.NET

Hello Chris and Frank,
I have finally decided to stop using the old AX controls!
I have read the “Getting Started with CVB.NET
I already have one display showing images.
What would be the code to work with 5 cameras, 5 displays and 5 images? Sorry, but I just started CVB!
Thank you very much again

Hi @George,

if you are able to view 1 Display with 1 Camera behind, you can do this accordingly for n cameras.
So just add another n displays (dynamically from code behind or with n Display controls on the MainView).

Hello Chris,
Now I have this:

private void openButton_Click(object sender, EventArgs e)
{
  try
  {
    Device device = FileDialogs.LoadByDialog(path => DeviceFactory.Open(path), "CVB Devices|*.vin;*.emu;*.avi");
    if (device == null)
      return; // canceled

    Device = device;
  }
  catch (IOException ex)
  {
    MessageBox.Show(ex.Message, "Error loading device", MessageBoxButtons.OK, MessageBoxIcon.Error);
  }
}

So I suppose I must create device1, device2, device3… ??
But what happen with this?:

private Device Device
{
  get { return _device; }
  set
  {
    if (!ReferenceEquals(value, _device))
    {
      display.Image = value?.DeviceImage;
      streamHandler.Stream = value?.Stream;

      _device?.Dispose(); // old one is not needed anymore
      _device = value;
    }
  }
}
private Device _device;

How can I link the other displays with their own images?
Do you have any example code for multiple devices?
I am a little bit lost Chris
Thank you very much

The part that (in your non MVVM approach) links the Display to the camera image is

display.Image = value?.Device.Image.

So you need n more Display on your UI (display2, display3 aso.) and n more DeviceProperties in your code behind (Device2, Device3 aso.)

Now in the open method just open the Driver on the next port:

Device device1 = FileDialogs.LoadByDialog(path => DeviceFactory.Open(path, 0, 1), “CVB Devices|.vin;.emu;*.avi”);

Device device1 = FileDialogs.LoadByDialog(path => DeviceFactory.Open(path, 0, 2), “CVB Devices|.vin;.emu;*.avi”);

If you dont have that many cameras, you should be able to simply load the CVMock.vin for testing.

Now set your device properties

Device1 = device1
Device2 = device2

And in there, as mentioned above:

display1.Image = value?.Device.Image for Device1
and
display2.Image = value?.Device.Image for Device2.

Hope this helps, if not, I can create you a simple Example in WPF tomorrow.

1 Like

Thank you Chris!
I will try this.
By the way we are not using Wpf, just Windows Forms.
I will let you know tomorrow.
You are the best, thank you for your help.
George

Hi Geroge,

I saw that from the code and its no problem but if we have the chance to start over from scratch I would like to give you an example on how easy CVB can be :wink:
I will try to get a little example up and running for you tomorrow.

1 Like

That will be amazing!
Thank you again Chris

Hello Chris!
This is the code I wrote yesterday, and it’s working!

private void FrmNewDisplayTest_Load(object sender, EventArgs e)
        {
            this.Size = new Size(1280, 1024);
            this.Location = new Point(0, 0);

            string path = ConfigurationManager.AppSettings["Camera Drivers"];

            Device device1 = DeviceFactory.Open(path, 0, 0);
            Device device2 = DeviceFactory.Open(path, 0, 1);
            Device device3 = DeviceFactory.Open(path, 0, 2);
            Device device4 = DeviceFactory.Open(path, 0, 3);
            Device device5 = DeviceFactory.Open(path, 0, 4);

            Device1 = device1;
            Device2 = device2;
            Device3 = device3;
            Device4 = device4;
            Device5 = device5;

        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                components?.Dispose();
                Device1?.Dispose();
                Device2?.Dispose();
                Device3?.Dispose();
                Device4?.Dispose();
                Device5?.Dispose();

            }
            base.Dispose(disposing);
        }

        private Device Device1
        {
            get { return _device1; }
            set
            {
                if (!ReferenceEquals(value, _device1))
                {
                    GenICamApiGrid.NodeMap = null; // unset any previous node maps
                    Display1.Image = value?.DeviceImage;
                    streamHandler1.Stream = value?.Stream;

                    _device1?.Dispose(); // old one is not needed anymore
                    _device1 = value;

                    //SetupNodeMapComboBox();
                }
            }
        }

        private Device Device2
        {
            get { return _device2; }
            set
            {
                if (!ReferenceEquals(value, _device2))
                {
                    GenICamApiGrid.NodeMap = null; // unset any previous node maps
                    Display2.Image = value?.DeviceImage;
                    streamHandler2.Stream = value?.Stream;

                    _device2?.Dispose(); // old one is not needed anymore
                    _device2 = value;

                    //SetupNodeMapComboBox();
                }
            }
        }

        private Device Device3
        {
            get { return _device3; }
            set
            {
                if (!ReferenceEquals(value, _device3))
                {
                    GenICamApiGrid.NodeMap = null; // unset any previous node maps
                    Display3.Image = value?.DeviceImage;
                    streamHandler3.Stream = value?.Stream;

                    _device3?.Dispose(); // old one is not needed anymore
                    _device3 = value;

                    //SetupNodeMapComboBox();
                }
            }
        }

        private Device Device4
        {
            get { return _device4; }
            set
            {
                if (!ReferenceEquals(value, _device4))
                {
                    GenICamApiGrid.NodeMap = null; // unset any previous node maps
                    Display4.Image = value?.DeviceImage;
                    streamHandler4.Stream = value?.Stream;

                    _device4?.Dispose(); // old one is not needed anymore
                    _device4 = value;

                    //SetupNodeMapComboBox();
                }
            }
        }

        private Device Device5
        {
            get { return _device5; }
            set
            {
                if (!ReferenceEquals(value, _device5))
                {
                    GenICamApiGrid.NodeMap = null; // unset any previous node maps
                    Display5.Image = value?.DeviceImage;
                    streamHandler5.Stream = value?.Stream;

                    _device5?.Dispose(); // old one is not needed anymore
                    _device5 = value;

                    //SetupNodeMapComboBox();
                }
            }
        }

        private Device _device1;
        private Device _device2;
        private Device _device3;
        private Device _device4;
        private Device _device5;


        private void BtnStartGrab_Click(object sender, EventArgs e)
        {
            streamHandler1.Start();
            streamHandler2.Start();
            streamHandler3.Start();
            streamHandler4.Start();
            streamHandler5.Start();
        }

        private void BtnStopGrab_Click(object sender, EventArgs e)
        {
            streamHandler1.Stop();
            streamHandler2.Stop();
            streamHandler3.Stop();
            streamHandler4.Stop();
            streamHandler5.Stop();
        }

        private void BtnCloseThis_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void BtnMainFormClose_Click(object sender, EventArgs e)
        {
            //Program.DisplayForm.SaveEdgePositions();
            //Program.SetupForm.SaveLimits();
            Program.SetupForm.chkBit1.Checked = false;
            Program.SetupForm.SetBitVal(1);
            Program.MonitorForm.Close();
            Program.DisplayForm.Close();
            Program.SetupForm.Close();
            Program.DisplayTestForm.Close();

            this.Close();
            Application.Exit();
        }

        //------------------------------------------------------------------------------------
        //       CAMERA SETUP
        //------------------------------------------------------------------------------------
        private void ComboBxSelectCamera_SelectedIndexChanged(object sender, EventArgs e)
        {
            PicVanpA2.Visible = true;
            PicGenICam.Visible = true;
            LblConnecting.Visible = true;

            if (ComboBxSelectCamera.Text == "Left Camera")
            {
                var nodeMap = Device1.NodeMaps["Device"];
                GenICamApiGrid.NodeMap = nodeMap;
            }

            if (ComboBxSelectCamera.Text == "Right Camera")
            {
                var nodeMap = Device2.NodeMaps["Device"];
                GenICamApiGrid.NodeMap = nodeMap;
            }

            if (ComboBxSelectCamera.Text == "Bore Camera")
            {
                var nodeMap = Device3.NodeMaps["Device"];
                GenICamApiGrid.NodeMap = nodeMap;
            }

            if (ComboBxSelectCamera.Text == "Bottom Camera")
            {
                var nodeMap = Device4.NodeMaps["Device"];
                GenICamApiGrid.NodeMap = nodeMap;
            }

            if (ComboBxSelectCamera.Text == "Handle Camera")
            {
                var nodeMap = Device5.NodeMaps["Device"];
                GenICamApiGrid.NodeMap = nodeMap;
            }
        }

        private void BtnReleaseNode_Click(object sender, EventArgs e)
        {
            ComboBxSelectCamera.Text = "Select Camera";
            GenICamApiGrid.NodeMap = null;
            PicVanpA2.Visible = false;
            PicGenICam.Visible = false;
            LblConnecting.Visible = false;
        }

As you can see I am using the ApiGrid too, and it’s working beautifully!
Now I have to learn how to change the display property to AREA MODE and how to show the X and Y positition, like the old AXDisplay did.

1 Like

Hi @George ,

as promised here my tutorial:

https://forum.commonvisionblox.com/t/getting-started-displaying-multiple-cameras/1508

You will see, UI and Logic are much cleaner separated from each other up to the point where you can change the whole UI without changing anything in your logic and vice versa.
Also you dont need the whole Streamhandler and UI stuff.

Regarding your questions:

mainDisplay.ShowCursorPosition = true;

To show where on the display the mousecursor currently is

mainDisplay.SelectedArea2D = new Area2D(new Rect(10, 10, 100, 100));

To change the selected area.

Cheers
Chris

Thank you Chris, you are a prince!
I am trying now to load the drivers from another Form (the one which initialise all the forms) and I have no images!

Device device = DeviceFactory.Open(path, 0, 0);
Program.DisplayTestForm.Device = device;

I am loading the driver to the device and passing the “device” to my display test Form

Any clue?

This seems to be a Winforms question rather than a CVB problem.

Maybe try to call an Update() on the DisplayTestForm.

I did it…it doesn’t work Chris

 private void FrmNewDisplayTest_Load(object sender, EventArgs e)
        {
            this.Size = new Size(1280, 1024);
            this.Location = new Point(0, 0);
            this.Update();

Try Updating right under this line.
Still… this is not a question for this forum as this to me sounds like a general programming problem rather than a CVB specific one.
I also dont fully understand what you want to do… if you want a simple form to let you pick the driver that is to be loaded, just go with a FileDialog…

I am trying to load all the drivers from the Initialise Form
Loading the drivers automatically from a given path
It is working on my Display Test Form but it’s not when I try to load the drivers from a different form.
Update() is not working on Initialise Form either

I cant help you on this problem without knowing the code.
Still, I think this is a question that is about basic Forms handling which you might get answered pretty quick at Stackoverflow.

1 Like

OK Chris, thank you very much!

If you dont find any answers at Stackoverflow either, just contact our Support… they can have a quick look at your code and help you out.

Maybe also somebody here in this forum who is more into Winforms understands what the actual problem is and might post an answer soon.

With WPF I could help you out :stuck_out_tongue: