Solved

CameraDeiviceType - No WIA device of the selected type is available

Posted on 2013-06-10
30
2,762 Views
Last Modified: 2013-12-04
Hello Experts,

I am trying to get an image from the integrated webcam of a tablet running Windows 8 using the WIA dll from VBA. The built-in cameras and related devices are:
    Intel(R) Imaging Signal Processor 2300
    Camera Sensor OV2720
    Camera Sensor OV8830
    Flash LM3554

I get runtime error -2145320939 "No WIA device of the selected type is available" using the following code:

Private Sub btnTakePicture_Click()

' Take a picture from a webcam and store it in a temp file.

    On Error GoTo Err_btnTakePicture_click

    Dim strPath As String
    Dim strTempFile As String
    Dim mydevice As WIA.Device
    Dim item As WIA.item
    Dim imfile As WIA.ImageFile
    Dim Commondialog1 As WIA.CommonDialog

    'put the path and name for the location of your temp file here.
    strPath = "C:\Temp\"
    strTempFile = strPath & Format(Now, "dd-mm-yyyy-hhnnss") & ".jpg"

    'the next two lines set up the configuration
    Set Commondialog1 = New CommonDialog
    [i][b][u]Set mydevice = Commondialog1.ShowSelectDevice(CameraDeviceType, False, False)[/u][/b][/i]

    Set item = mydevice.ExecuteCommand(wiaCommandTakePicture)    'instructs the camera to take the picture
    Set imfile = item.Transfer    'transfers the picture from the camera

    'this line saves the picture to a specified file
    If imfile Is Nothing Then
        MsgBox "Action cancelled."
    Else
        imfile.SaveFile (strTempFile)
        MsgBox "Picture saved."
    End If

    On Error GoTo Err_AddImage

Exit_btnTakePicture_click:
    Set mydevice = Nothing
    Set item = Nothing
    Set Commondialog1 = Nothing
    Exit Sub

Err_btnTakePicture_click:
    Select Case Err.Number
        Case Is = -2145320939
            MsgBox "No camera identified." & vbCrLf & "Please call tech support.", vbCritical, "Error"
        Case Else
            MsgBox Err.Description, vbOKOnly + vbCritical, "Error Taking Picture"
    End Select
    Resume Exit_btnTakePicture_click

End Sub

Open in new window


What I tried:
Changed the problematic line to:
1. Set mydevice = Commondialog1.ShowSelectDevice(CameraDeviceType, True, False)
2. Set mydevice = Commondialog1.ShowSelectDevice(UnspecifiedDeviceType, True, False)
3. Set mydevice = Commondialog1.ShowSelectDevice(VideoDeviceType, True, False)

Still no joy.

I ran the following and received the same error.
Public  Sub TestWIADevice()
       
        On Error GoTo Err_handling
       
        Dim MyDevice As WIA.Device
        Dim MyDialog As WIA.CommonDialog
        Dim MyProp As WIA.Property
       
        Set MyDialog = New WIA.CommonDialog
            
           Set MyDevice = MyDialog.ShowSelectDevice(
WIA.WiaDeviceType.CameraDeviceType, False, True)
           
            If Not MyDevice Is Nothing Then

                For Each MyProp In MyDevice.Properties
                    Select Case MyProp.Name
                        Case "Name"
                            MsgBox MyProp.value
                         End Select
                Next
            Else
                MsgBox "No WIA Devices found!"
            End If
           
Err_Exit:
           'release objects & clear Err
           Err.Clear
           
           Set MyDevice = Nothing
           Set MyDialog = Nothing
           
           Exit Sub
           
Err_handling:
          MsgBox Err.Number & " " & Err.Description
          Resume Err_Exit
             
           'release objects
           
           Set MyDevice = Nothing
           Set MyDialog = Nothing
           
End Sub 

Open in new window


I have a hard time believing that none of these webcams are WIA compatible, especially since skype and other webcam devices work fine. Please help!!!
0
Comment
Question by:MacroShadow
  • 14
  • 12
30 Comments
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39251348
I suggest downloading/installing the latest W8 driver. I don't know if it's the Lenovo tablet you have, but the camera specs you posted match this exactly:
http://support.lenovo.com/en_US/downloads/detail.page?DocID=DS033202

If this isn't the tablet you have, find the W8 driver at the manufacturer's website. Regards, Joe
0
 
LVL 26

Author Comment

by:MacroShadow
ID: 39258082
Tried that, no dice.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39258115
This is a total hip-shot: on the problematic line, try

WIA.WiaDeviceType.ScannerDeviceType

I realize that

WIA.WiaDeviceType.CameraDeviceType

makes more sense for a webcam, but it's possible that the system sees it as a scanner. Probably won't work, but will take just a few seconds to try it...can't hurt. Btw, which tablet is it? Regards, Joe
0
 
LVL 26

Author Comment

by:MacroShadow
ID: 39258470
As expected it didn't work. The tablet is: Asus VivoTab Smart ME400C
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39260360
There's been a very recent update to the driver package for that particular tablet...dated 2013.04.23:
http://support.asus.com/Download.aspx?SLanguage=en&m=ASUS+VivoTab+Smart&p=28&s=5

I'm guessing you're on top of this, but if by chance you're not on this updated version, perhaps it fixes a problem in the camera's WIA support (if there's a problem). Once again, low probability, but it's worth a shot.
0
 
LVL 26

Author Comment

by:MacroShadow
ID: 39261435
No joy.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39261505
Does the code you posted work on a standard W8 (or W7) laptop? Would be helpful in determining if your code is the issue or if it's something funky in the tablet's hardware or software.
0
 
LVL 26

Author Comment

by:MacroShadow
ID: 39261558
I don't know. I'll try to get to hold of a W7/W8 machine to test it.

btw I tried running Ammara's DBPix (http://www.ammara.com/dbpix/access.html) on the tablet and it didn't work either.

I appreciate if you could check it also on your machine.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39262544
I ran the first chunk of code on a plain old W7 Pro 64-bit laptop with a built-in Sonix 2MP webcam (which other software accesses fine). I get this:
no-cameraBtw, the label [Err_AddImage] doesn't exist so I changed the line of code containing it to [On Error GoTo Err_btnTakePicture_click]. I didn't try the second chunk of code. Regards, Joe
0
 
LVL 26

Author Comment

by:MacroShadow
ID: 39263139
Yep, that's the problem. For some reason the web cams aren't recognized by WIA. It's runtime error -2145320939.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39263310
Very interesting!

I use a (free) imaging product called IrfanView:
http://www.irfanview.com/

When I go to its [Select Scan/TWAIN Source...] menu, I get this:
IrfanView Select SourceIt's clear that some of the devices in the list are WIA and some are TWAIN (TW), but for the webcam, it's not obvious. In any case, when I go to IrfanView's [Acquire/Batch Scanning...] menu, the webcam comes up fine in video mode and the app has a Snapshot button that works perfectly to create a still image in IrfanView (which I can then save to a large variety of image formats, including, of course, JPG). But, the thing is, I don't know if IrfanView is using the WIA DLL or something else. Regards, Joe
0
 
LVL 26

Author Comment

by:MacroShadow
ID: 39263484
Now this is weird. When I go to IrfanView's [Select Scan/TWAIN Source...] menu, I get... an empty listbox.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39263609
Well, well...isn't this an interesting can of worms! The screenshot above was done on an HP laptop running W7/64-bit. I just tried IrfanView on an Asus laptop running W8/64-bit. It has a built-in webcam that shows up fine in Device Manager but, like your Asus W8 tablet, does NOT appear in IrfanView's Select Source. Maybe Asus is doing something non-standard with its webcams, i.e., they're neither WIA nor TWAIN. To figure out whether the issue is with the Asus webcam or W8, I just tried IrfanView on an identical Asus laptop with the same built-in webcam, but running W7/64-bit. Same result... does NOT appear in IrfanView's Select Source. So the issue is not W7 vs. W8...it's that Asus is doing something non-standard (non-WIA/TWAIN) with its webcams. I think the conclusion of this effort is that your WIA code is not going to work with the webcam of your Asus tablet. Regards, Joe
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39263619
But wait, he says, the WIA code also doesn't work on his non-Asus HP! Back to the drawing board. :(
0
 
LVL 26

Author Comment

by:MacroShadow
ID: 39263857
So are there any alternatives? My objective is to take a picture from a camera and save it in a table.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39265665
Sorry I didn't get back to you yesterday...real life intervened in my EE world. Yes, there are alternatives. I was playing with some webcam code a while ago. I'm busy right now but I'll dig it up and get back to you later today. Regards, Joe
0
 
LVL 26

Author Comment

by:MacroShadow
ID: 39265901
Thanks.
0
 
LVL 51

Accepted Solution

by:
Joe Winograd, EE MVE earned 500 total points
ID: 39266397
I haven't done much with VB. Most of my coding in recent years has been with AutoHotkey (AHK):
http://www.autohotkey.com/

It's similar to other scripting languages and I'm sure you can pick it up quickly since you're already familiar with VB. If you're willing to give AHK a spin, I have a solution for you. Btw, when you install AHK, select the ANSI 32-bit version rather than Unicode 64-bit (that's because the script below is old...it may or may not work on the Unicode 64-bit version, but I know for a fact that it works on the ANSI 32-bit version).

There was a terrific thread in the AHK forum a couple of years ago:
http://www.autohotkey.com/board/topic/27892-webcam-capture-wdm-with-motion-detection-in-ahk/

There are several scripts in that thread. The one I played with is on page 3 by @fures, posted 25-Feb-2011 at 7:07PM:
http://www.autohotkey.com/board/topic/27892-webcam-capture-wdm-with-motion-detection-in-ahk/page-3

The original program takes a snapshot with the webcam when a specified hotkey is pressed (the original hotkey was Shift-Ctrl-k, but it can be whatever you want). It stores the photo in a JPG file in the same folder that the script is in with a filename of [WebCamShot_sn_YYYY-MM-DD_HH.MM.SS.jpg]. The original program stays active (until you manually exit it) waiting for the hotkey to be pressed.

I changed the original program to remove the hotkey, take a single snapshot, and then exit (I also removed the "_sn" from the JPG file name). The revised code is attached as [webcam-snapshot-to-file.ahk].

I had run it before on my W7/64-bit HP laptop where it worked fine. I just tested it on my W8/64-bit Asus laptop...also worked perfectly there! So I have high hopes for your Asus W8 tablet, but as is always the case, ymmv.

You mentioned that your objective is to save the webcam photo in a table. This program saves it in a JPG file, but I'm sure you can modify the code to save it in a table. But before you modify it in any way, run it as-is to see if it works on your Asus tablet. Btw, the photo is captured as a BMP and then the program calls an image conversion routine to convert it to JPG. The conversion routine (embedded in the attached source code) supports JPG, BMP, PNG, TIFF, and GIF as both the input and output file type, so if you prefer a different image format, that will be easy to achieve.

Regards, Joe
webcam-snapshot-to-file.ahk
0
 
LVL 26

Author Comment

by:MacroShadow
ID: 39266414
Thank you. I'll check it out and post back.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39266467
OK. I'm very curious to find out if it works on the Asus W8 tablet (my only tablets are Android).
0
 
LVL 26

Author Comment

by:MacroShadow
ID: 39269763
I added #Warn and I get the following errors.
123
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39269807
Hmmm, compiles and runs perfectly here. Did you try it as-is, that is, without the #Warn? I realize the value of #Warn, but I'm curious if it works for you without it. In any case, I believe that the snapshot code evolved from code that was also able to capture the webcam video...maybe as part of the modification from video to still photo some errors were introduced, but which aren't an issue when taking a photo. I haven't studied the code thoroughly. All I did was change a very small number of lines to remove the hotkey/#Persistent approach and simply have it take the photo when run and exit immediately...which works every time here. Regards, Joe
0
 
LVL 26

Author Comment

by:MacroShadow
ID: 39269835
I forgot to mention that I got those errors on my development machine, Win XP SP3 with no web cam.

Yes I tried it as is, and it doesn't do a thing. That in itself isn't surprising since there is no web cam on the system, the question is, is there a way to notify the user that no cam was detected.

Sorry for taking advantage of you, but I'd imagine that I'd be able to get an answer quicker by asking you than by trying ti figure it out myself, after all this is the first I ever saw ahk.

Thanks in advance.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39269868
> I forgot to mention that I got those errors on my development machine, Win XP SP3 with no web cam.

Ah, well, that could certainly be an issue. :)

> Yes I tried it as is, and it doesn't do a thing. That in itself isn't surprising since there is no web cam on the system

Yes, not surprising that it wouldn't do a thing under those circumstances.

> the question is, is there a way to notify the user that no cam was detected.

Probably, but I don't know off the top of my head. I suggest taking a look at the first page of the thread I mentioned above on the AHK forum:

http://www.autohotkey.com/board/topic/27892-webcam-capture-wdm-with-motion-detection-in-ahk/

The last script on the first page has code that checks for the existence of a driver. Do a search for "SelectedDriver" and "foundDriver" in that script and there should be code there that you can leverage...haven't done this myself, though.

I'm still very curious if the code as-is that works on my W8 laptop (with webcam) will work on your W8 tablet (with webcam). Please try it and let me know. Thanks, Joe
0
 
LVL 26

Author Comment

by:MacroShadow
ID: 39273926
Haven't gotten around to testing on the tablet yet, but I tried your ahk file on a Samsung Windows 7 64 bit laptop, it didn't work. A device selection dialog was shown, once a device was selected an empty bmp was created and immediately deleted.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39274614
Works perfectly here on an HP W7 64-bit laptop. Creates a file called [WebCamShot_YYYY-MM-DD_hh.mm.ss.jpg] every time...has never failed. Attached is a sample from a few minutes ago. Don't know why it isn't working on your end.
WebCamShot-2013-06-25-07.54.48.jpg
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Read about why website design really matters in today's demanding market.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now