Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

delay in output

hi all,
i am developing an application using Measurement Studio for .NET, and image acqusition is done with a IEEE1394 camera.well,my problem is a certain delay in the execution of the program..for instance,if i want to do color matching and display the color in a message box, it doesnt appear at once.even when i removed the message box and just returned the color to a calling function,its still the same..when i debug it,though(using F11),it runs fine..there is a delay in saving the image in memory,and also in storing any other info from any image processing function(in my case,the LearnColor function).i had to insert a delay between LearnColor and MatchColor to make sure the color information was saved properly.without the delay,the program just throws an unhandled exception at MatchColor.
 
my question is, whether this is caused by the camera,or inherent in Vision,or could the speed of my computer be a factor too?if its any of the 1st two,is there a way around it?
 
thank u..
0 Kudos
Message 1 of 6
(4,706 Views)

Hello rebecs,

Would it be possible for you to post your project to the forum, so we can take a look at it?  I would like to run the code you are using to see if I can duplicate the problem.  Thank you.

Regards,

Jasper S

0 Kudos
Message 2 of 6
(4,697 Views)
hi jasper,
 
here is my code:
Public Class VisionTool

Dim ViewRect As New NationalInstruments.CWIMAQControls.CWIMAQRegions

Dim ColInfo As New NationalInstruments.CWIMAQControls.CWIMAQColorInformation

Dim Scores As Object

Dim sid As System.UInt32

Dim errorCode As Integer

Public IMAQVision As NationalInstruments.CWIMAQControls.AxCWIMAQVision

Dim myImage As NationalInstruments.CWIMAQControls.CWIMAQImage

Dim BufferNumber As Integer

Private WithEvents t1 As System.Timers.Timer

' A creatable COM class must have a Public Sub New()

' with no parameters, otherwise, the class will not be

' registered in the COM registry and cannot be created

' via CreateObject.

Public Sub New()

MyBase.New()

IMAQVision =

New NationalInstruments.CWIMAQControls.AxCWIMAQVision

IMAQVision.CreateControl()

'image initialization

myImage =

New NationalInstruments.CWIMAQControls.CWIMAQImage

myImage.Type = NationalInstruments.CWIMAQControls.CWIMAQImageTypes.cwimaqImageTypeRGB32

'timer initialization

t1 =

New System.Timers.Timer(250)

errorCode = CWIMAQ1394.CameraOpen2("cam0", CWIMAQ1394.CameraMode.IMG1394_CAMERA_MODE_CONTROLLER, sid)

If (errorCode <> CWIMAQ1394.ErrorCodes.IMG1394_ERR_GOOD) Then

Console.WriteLine(" camera error!!")

GoTo ErrorHandler

End If

t1.Enabled =

True

errorCode = CWIMAQ1394.SetupGrabCW(sid)

If (errorCode <> CWIMAQ1394.ErrorCodes.IMG1394_ERR_GOOD) Then

Console.WriteLine(" grab error!!")

GoTo ErrorHandler

End If

ErrorHandler:

If (errorCode <> CWIMAQ1394.ErrorCodes.IMG1394_ERR_GOOD) Then

End If

End Sub

 

Public Function GetLedColor() As Integer

Dim roi As New CWIMAQRegions

Dim roiRect As New CWIMAQRectangle

System.Threading.Thread.Sleep(250)

roiRect.Initialize(111, 54, 7, 15)

ViewRect.AddRectangle(roiRect)

IMAQVision.LearnColor(myImage, ColInfo, ViewRect)

System.Threading.Thread.Sleep(250)

IMAQVision.MatchColor(myImage, ColInfo, Scores, ViewRect)

IMAQVision.Dispose()

Return Scores(0)

End Function

 

Public Sub TimerFired(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles t1.Elapsed

errorCode = CWIMAQ1394.Grab2CW(sid, 1, BufferNumber, myImage)

If (errorCode <> CWIMAQ1394.ErrorCodes.IMG1394_ERR_GOOD) Then

Console.WriteLine("timer error")

t1.Enabled =

False

End If

End Sub

 

End

Class

i am calling this library from a tcl script,using DOS(i mean i run the tcl script from DOS command prompt)..and it is supposed to return the score of the color matching function to the calling program.

for now,it is returning the score..but it is taking some time..as for the first time it is called,it takes forever..Smiley Mad when i posted this question in one of the forums earlier, someone suggested that maybe there is some delay needed for marshaling between .NET and COM...that is from the .NET/COM perspective..wat about the NI perspective?does any of the NI function have an inherent delay?or is this purely dependent on the machine im using?

thanks so much...Smiley Happy

0 Kudos
Message 3 of 6
(4,684 Views)
Hello rebecs,
 
In this case it looks like these delays are expected.  They are inherent to the Vision functions you are calling, and are in no way related to your camera.  The speed of your computer will also be a factor in how long they take to populate their memory spaces.  What is interesting in this case is that they do not block, as you are well aware of.  This means the function returns before the memory operation is complete.  Let me know if you have any other questions regarding this issue.
 
Regards,
Jasper S
0 Kudos
Message 4 of 6
(4,656 Views)

hello jasper,

thank u so much for ur reply..well,since the delay is expected,i guess i have to make do with it...at least my application works.Smiley Very Happy

 

0 Kudos
Message 5 of 6
(4,649 Views)

To speed Up your process, you can change your architecture:

 

- create a Windows Service which connects permanently the camera and IMAQ. Some kind of "out of process" COM executable

- create a small EXE that will exchange small information with the COM server.

 

That architecture will be VERY fast : you won't have to load all the DLLs each time because they will be already loaded and running !

0 Kudos
Message 6 of 6
(3,763 Views)