PDA

View Full Version : Selecting USB Camera at start application



roman
April 13, 2012, 14:15:48
I'm developing a VB.net application, using 2 usb cameras. I created one form with its own IcImagingControl for each camera.
I'm able to select a camera for each IcImagingControl and display it, but when I save the select device it uses the CurrentProcessName, which is always the same for the application. Next time I startup the application it would try to use the last camera selected instead assigning one camera to each IcImagingcontrol.
Thank you

Stefan Geissler
April 13, 2012, 15:24:10
Hi,

how do you save the devices? And how do you load them at program start?

roman
April 13, 2012, 16:59:40
Please see my response to your 2 questions below. Thanks

Here is the code I use to save the device:

Sub SaveSelectedDevice(ByVal IC15Control As TIS.Imaging.ICImagingControl)
On Error GoTo err_SaveSelectedDevice
With IC15Control
If .DeviceValid Then
SaveSetting(CurrentProcessName(), REG_SECTION, REG_KEY_VIDEO_SOURCE, .Device)
If .InputChannelAvailable Then
SaveSetting(CurrentProcessName(), REG_SECTION, REG_KEY_INPUT_CHANNEL, .InputChannel)
End If
If .VideoNormAvailable Then
SaveSetting(CurrentProcessName(), REG_SECTION, REG_KEY_VIDEO_NORM, .VideoNorm)
End If

SaveSetting(CurrentProcessName(), REG_SECTION, REG_KEY_VIDEO_FORMAT, .VideoFormat)

If .DeviceFrameRateAvailable Then
SaveSetting(CurrentProcessName(), REG_SECTION, REG_KEY_FRAME_RATE, CStr(.DeviceFrameRate))
End If

End If
End With
err_SaveSelectedDevice:
End Sub


Here is my code to load a device when I load a form call video:

Private Sub frmVideo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Width = 665
Me.Height = 552
Me.Top = 53

VideoDeviceSettings1.OpenSelectedDevice(IcImagingC ontrol1)
IcImagingControl1.LiveStart()
CrossHairVisible = True

End Sub

Here is my code to load a device when I load a form call Witness:

Private Sub frmWitness_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.Width = 665
Me.Height = 552
Me.Top = 53

VideoDeviceSettings2.OpenSelectedDevice(IcImagingC ontrol2)
IcImagingControl2.LiveStart()
CrossHairVisible = True


End Sub

Stefan Geissler
April 16, 2012, 08:22:02
Hi

I have a little trouble understanding your problem. If you use CurrentProcessName and have two cameras using this, then the second saving of cameras will always overwrite the first, because CurrentProcessName returns every time the same. It seems CurrentProcessName returns the name of the process, but not of the form. It seems you want to use the name of of the form for this. This can be done either by reflection stuff, or much more simple, you pass a name string to SaveSelectedDevice() and use this instead of CurrentProcessName



Sub SaveSelectedDevice(ByVal IC15Control As TIS.Imaging.ICImagingControl, Name as String)
...
SaveSetting(Name), REG_SECTION, REG_KEY_VIDEO_SOURCE, .Device)
....

End Sub

Private Sub frmVideo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Width = 665
Me.Height = 552
Me.Top = 53

VideoDeviceSettings1.SaveSelectedDevice(IcImagingC ontrol1,"Video") ' for saving


VideoDeviceSettings1.OpenSelectedDevice(IcImagingC ontrol1,"Video")
IcImagingControl1.LiveStart()
CrossHairVisible = True

End Sub


Private Sub frmWitness_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.Width = 665
Me.Height = 552
Me.Top = 53

VideoDeviceSettings1.SaveSelectedDevice(IcImagingC ontrol1,"Witness") ' for saving

VideoDeviceSettings2.OpenSelectedDevice(IcImagingC ontrol2, "Witness")
IcImagingControl2.LiveStart()
CrossHairVisible = True

End Sub


I hope, this sample code shows the idea.

roman
April 18, 2012, 14:06:00
It works. Thank you very much