Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Saving an imaq image to disk using CWIMAQVision

OK, I've given up on trying to get my code to work, so I'm going to try and adapt the 'Low-Level Grab' VB example to my uses. 

 

I want to acquire an save an image every 10 min or so.  I know how to config the timer for this, but when it comes to saving the image...

 

When I use the line of code

errorCode = CWIMAQVision1.WritePNGFile(myImage, "C:\image.png")

 

I get:

'Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown.'

 

Where and how do I need to define and configure the CWIMAQVision Object to correctly save an image and eliminate this error?

0 Kudos
Message 1 of 56
(10,300 Views)

timmkish,

 

How many images are you trying to grab every 10 minutes? Or are you just wanting to SNAP one image every 10 minutes? I might try using the snap if you are only using one image, and then see if your save will work with that.

Chris Van Horn
Applications Engineer
0 Kudos
Message 2 of 56
(10,291 Views)

Just one image every 10 min.  Regardless if I use the snap or grab function, when I write the following line of code:

 

errorCode = CWIMAQVision1.WriteImage(myImage, "C:\1394Image.img")

 

 

 

I declare the CWIMAQVision1 object in the "Friend Class MainForm" using the following statement:

Public CWIMAQVision1 As AxCWIMAQVision

 

I get the error: Object reference not set to an instance of an object. When the code tries to execute the writeJPEG function.

 

 

This is using the NI 'Snap1394' VB code.  The code works just fine to snap an image and display it, now I just want to add the save feature. The 'writeimg' will output a the raw image file correct?  My camera supports 12-bit, so I need to output a 16-bit image and not an 8-bit.  

0 Kudos
Message 3 of 56
(10,287 Views)

Hey timmkish,

 

it took me some time to get this coded properly, but I eventually got it to work with a PNG and clicking the snap button. So, it does not have the timing in it, but it does work. I had to add a CWIMAQVision1 object to the front panel. 

 

Private Sub Form_Load()
CWIMAQViewer1.Attach CWIMAQ1.Images(1)
End Sub

 

Private Sub Snap_Click()
CWIMAQ1.Interface = Text1.Text
CWIMAQ1.LoadInterfaceDefaults
CWIMAQ1.AcquireImage
CWIMAQVision1.WritePNGFile CWIMAQ1.Images(1), "c:\image1.png"
End Sub

Private Sub Quit_Click()
End
End Sub

 

 

I hope this helps!!

 

Message Edited by Chris_VH on 11-11-2008 04:46 PM
Chris Van Horn
Applications Engineer
0 Kudos
Message 4 of 56
(10,280 Views)

What is the code to correctly add a 'CWIMAQVision1 object to the front panel'?

 

I think this is where I'm getting screwed up.  I'm a VBA newbie, so I'm probably making a simple (i.e. dumb) mistake

0 Kudos
Message 5 of 56
(10,274 Views)

timmkish,

 

Its not code to add the CWIMAQVision1 object, but you physically want to drag and drop it from your toolbox of controls. It should be listed in the toolbox along with other IMAQ controls, and once you run the code, it is hidden. You just want to add it so that you can reference it. It acts the same way as the CWIMAQ control that you see on your front panel form.

 

I hope this helps.

Message Edited by Chris_VH on 11-12-2008 08:10 AM
Chris Van Horn
Applications Engineer
0 Kudos
Message 6 of 56
(10,257 Views)

Warning    1    The referenced component 'niimaq1394' could not be found.    
Error    2    'AxCWIMAQViewer' is ambiguous in the namespace 'NationalInstruments.CWIMAQControls'.    F:\Documents and Settings\All Users\Documents\National Instruments\NI-IMAQ for IEEE-1394\Examples\MSVB.NET\Low Level Grab1394.NET\Low Level Grab1394.vb    46    40    Low Level Grab1394
Error    3    'AxCWIMAQViewer' is ambiguous in the namespace 'NationalInstruments.CWIMAQControls'.    F:\Documents and Settings\All Users\Documents\National Instruments\NI-IMAQ for IEEE-1394\Examples\MSVB.NET\Low Level Grab1394.NET\Low Level Grab1394.vb    63    32    Low Level Grab1394
Error    4    'CWIMAQImage' is ambiguous in the namespace 'NationalInstruments.CWIMAQControls'.    F:\Documents and Settings\All Users\Documents\National Instruments\NI-IMAQ for IEEE-1394\Examples\MSVB.NET\Low Level Grab1394.NET\Low Level Grab1394.vb    236    24    Low Level Grab1394
Error    5    'AxCWIMAQVision' is ambiguous in the namespace 'NationalInstruments.CWIMAQControls'.    F:\Documents and Settings\All Users\Documents\National Instruments\NI-IMAQ for IEEE-1394\Examples\MSVB.NET\Low Level Grab1394.NET\Low Level Grab1394.vb    240    34    Low Level Grab1394

 

If I 'Add Reference', browse to my WINDOWS/System32 folder, I don't see the niimaq1394.dll file.  I DO see: niimaqci.dll, niimaqdx.dll, and niimaqmem.dll

Should I add any of those?  I was previously running an earlier version of theNI-IMAQ software and this is when I was successfully able to add the niimaq1394 as a reference.

 

 

0 Kudos
Message 7 of 56
(10,246 Views)

Hmm,

 

I do know that the IEEE for 1394 drivers are the legacy versions which have been replaced by the IMAQdx. I would try adding the dx dll to see if that works. When I made this, I just used the snap example, added the one object to my front panel, and added the one line of code.

Chris Van Horn
Applications Engineer
0 Kudos
Message 8 of 56
(10,244 Views)

Now I get 'Unlicensed copy of NI Vision' error!  Who do I talk to to get this cleared up? Everything should be licensed,

 

Just so we're on the same page, I'm using the.NET CWIMAQ, CWIMAQVision, etc controls (they look like gears in the toolbox), not the COM controls

0 Kudos
Message 9 of 56
(10,216 Views)
Do I need to have a 'Vision Development Module' license to save an image?  Or will just a runtime license and 'Vision Acquisition Software' work?
0 Kudos
Message 10 of 56
(10,212 Views)