Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

EnumerateVideoModes in vb.NET

I have IMAQdx 3.0.1 installed on my computer and I am trying this code:
 

Dim cameraInformationArray() As CWIMAQdx.CameraInformation

status = CWIMAQdx.EnumerateCameras(cameraInformationArray, True)

status = CWIMAQdx.OpenCamera(cameraInformationArray(0).InterfaceName, CWIMAQdx.CameraControlMode.Controller, session)

Dim vma() As CWIMAQdx.VideoMode

Dim vmaCurrent As Long

status = CWIMAQdx.EnumerateVideoModes(session, vma, vmaCurrent)

 

Unfortionally EnumerateVideoModes does not fill in the vma table... How can I make this work?

 

Dim vm As New CWIMAQdx.VideoMode

status = CWIMAQdx.GetAttribute(session, "AcquisitionAttributes::VideoMode", CWIMAQdx.ValueType.EnumItem, vm)

 

Also, the GetAttribute does not return the VideoMode as requested.

0 Kudos
Message 1 of 7
(4,130 Views)

I found some other issues on the web where they say you should first uninstall before installing the new NI-versions.

So I uninstalled all the Acquisition-software and drivers and reïnstalled it.

Now the code works!

Dim

cameraInformationArray() As CWIMAQdx.CameraInformation = Nothing
Dim videoModeArray() As CWIMAQdx.VideoMode = Nothing
Dim currentMode As Integer
status = CWIMAQdx.EnumerateCameras(cameraInformationArray, True)
status = CWIMAQdx.OpenCamera(cameraInformationArray(0).InterfaceName, CWIMAQdx.CameraControlMode.Controller, session)
status = CWIMAQdx.EnumerateVideoModes(session, videoModeArray, currentMode)
For Each vm As CWIMAQdx.VideoMode In videoModeArray
    Me.combobox.Items.Add(vm.Name)
Next

0 Kudos
Message 2 of 7
(4,128 Views)

GetAttribute and SetAttribute still don't seem to work...

Does anybody have code that works and could post it here?

0 Kudos
Message 3 of 7
(4,127 Views)
Update:
 
This works:
status = CWIMAQdx.SetAttribute(session, "CameraAttributes::Brightness::Value", CWIMAQdx.ValueType.F64, 255)
 
This does not work:

status = CWIMAQdx.SetAttribute(session,

"AcquisitionAttributes::VideoMode", CWIMAQdx.ValueType.EnumItem, vm)

The error I am getting is:
{"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."}
0 Kudos
Message 4 of 7
(4,121 Views)
Hi Snipe,
 
There should no reason to use the EnumItem ValueType to set an enumerated attribute. It is mainly meant for reading the name/value simultaneously (which actually isn't supported under .NET anyways), but on the set side it is clumsy as you have to provide both a name and a value, when in reality you just need one or the other.
 
 You can use the U32 ValueType and set any of the possible enumeration values, or alternatively use the String ValueType and set it to one of the possible values by name. A simple change to your existing code would be to make the line:
status = CWIMAQdx.SetAttribute(session, "AcquisitionAttributes::VideoMode", CWIMAQdx.ValueType.String, vm.Name)
 
We are investigating a possible issue with how the the EnumItem ValueType is handled in the .NET interop layer (which is causing the exception you noted above), but as I mentioned above it should not be necessary to set the attribute that way.
 
-Eric G
0 Kudos
Message 5 of 7
(4,115 Views)
Thanx.
 
Unfortunatly I get an "NationalInstruments.CWIMAQControls.CWIMAQdx.Error.AttributeOutOfRange"-error when using your line of code. But when I use
 

s = CWIMAQdx.SetAttribute(session,

"AcquisitionAttributes::VideoMode", CWIMAQdx.ValueType.U32, vm.Value)

 
it works great. Of course I always need to put the follawing calls around it (as I also need to do to change the width)

CWIMAQdx.StopAcquisition(session)
CWIMAQdx.StartAcquisition(session)

0 Kudos
Message 6 of 7
(4,095 Views)

It seems that sometimes when I change the videomode, the image gets scrambled (and stays scrambled until I restart the camera). I guess this is because of buffers being written or read on a wrong moment. How can I make sure this does not happen? (I first thought dat using IgnoreFirstFrame would do the trick, but that did not help.)

Message Edited by Snipe on 04-12-2007 04:38 AM

0 Kudos
Message 7 of 7
(4,093 Views)