3 Replies - 6931 Views - Last Post: 08 April 2011 - 08:09 AM Rate Topic: -----

#1 perdono-2007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 07-April 11

USB camera interfacing through VB.net

Posted 07 April 2011 - 05:39 AM

HI

I am working on a project
I need to connect a USB camera but there is no com port No. on Device Manager

the problem i know how to use camera on a serial port but USB ....i don't??


can anyone help me soon please ?
Is This A Good Question/Topic? 0
  • +

Replies To: USB camera interfacing through VB.net

#2 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: USB camera interfacing through VB.net

Posted 07 April 2011 - 06:00 AM

View Postperdono-2007, on 07 April 2011 - 07:39 AM, said:

HI

I am working on a project
I need to connect a USB camera but there is no com port No. on Device Manager

the problem i know how to use camera on a serial port but USB ....i don't??


can anyone help me soon please ?

A good idea is to use WIA (Windows Image Acquisition) to grab the image from the camera.

A quick google search returned this: Look at me! Windows Image Acquisition

Another way is to use the serial port if possible since you already know how to do that.
Was This Post Helpful? 0
  • +
  • -

#3 perdono-2007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 07-April 11

Re: USB camera interfacing through VB.net

Posted 08 April 2011 - 08:01 AM

thank u

this is my code to let you see what is my problem

[
Imports System.IO.Ports
Imports System.Threading
Imports System
Imports System.Text
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Runtime.InteropServices


Public Class Form1
    Shared serialPort As SerialPort
    Const WM_CAP_START = &H400S
    Const WS_CHILD = &H40000000
    Const WS_VISIBLE = &H10000000
    Const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
    Const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
    Const WM_CAP_EDIT_COPY = WM_CAP_START + 30
    Const WM_CAP_SEQUENCE = WM_CAP_START + 62
    Const WM_CAP_FILE_SAVEAS = WM_CAP_START + 23
    Const WM_CAP_SET_SCALE = WM_CAP_START + 53
    Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
    Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50
    Const SWP_NOMOVE = &H2S
    Const SWP_NOSIZE = 1
    Const SWP_NOZORDER = &H4S
    Const HWND_BOTTOM = 1




    '---The capGetDriverDescription function retrieves the version
    ' description of the capture driver---
    Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriverIndex As Short, ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, ByVal cbVer As Integer) As Boolean
    '---The capCreateCaptureWindow function creates a capture
    ' window---
    Declare Function capCreateCaptureWindowA Lib "avicap32.dll" (ByVal lpszWindowName As String, ByVal dwStyle As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Short, ByVal hWnd As Integer, ByVal nID As Integer) As Integer
    '---This function sends the specified message to a window or
    ' windows---
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, <MarshalAs(UnmanagedType.AsAny)> ByVal lParam As Object) As Integer
    '---Sets the position of the window relative to the screen
    ' buffer---
    Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
    '---This function destroys the specified window---
    Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As Boolean


    '---used as a window handle---
    Private hWnd As Integer


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        '---close the serial port if it is open---


        If serialPort.IsOpen Then
            serialPort.Close()
        End If
        Try
            '---configure the serial port with the various
            ' parameters---
            With SerialPort1
                .PortName = "COM3"
                .BaudRate = 9600
                .Parity = IO.Ports.Parity.None
                .DataBits = 8
                .StopBits = IO.Ports.StopBits.One
                .Handshake = IO.Ports.Handshake.None
            End With
            '---open the serial port---
            serialPort.Open()
            serialPort.DiscardInBuffer()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        '---preview the selected video source---
        PreviewVideo(PictureBox1)
    End Sub




    '---preview the selected video source---
    Private Sub PreviewVideo(ByVal pbCtrl As PictureBox)
        hWnd = capCreateCaptureWindowA(0, WS_VISIBLE Or WS_CHILD, 0, 0, 0, 0, pbCtrl.Handle.ToInt32, 0)
        If SendMessage(hWnd, WM_CAP_DRIVER_CONNECT, 0, 0) Then
            '---set the preview scale---
            SendMessage(hWnd, WM_CAP_SET_SCALE, True, 0)
            '---set the preview rate (ms)---
            SendMessage(hWnd, WM_CAP_SET_PREVIEWRATE, 30, 0)
            '---start previewing the image---
            SendMessage(hWnd, WM_CAP_SET_PREVIEW, True, 0)
            '---resize window to fit in PictureBox control---
            SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, pbCtrl.Width, pbCtrl.Height, SWP_NOMOVE Or SWP_NOZORDER)
        Else
            '---error connecting to video source---
            DestroyWindow(hWnd)
        End If
    End Sub



    Private Sub btnStartRecording_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartRecording.Click
        btnStartRecording.Enabled = False
        btnStopRecording.Enabled = True
        Application.DoEvents()
        '---start recording---
        SendMessage(hWnd, WM_CAP_SEQUENCE, 0, 0)

    End Sub

    Private Sub btnStopRecording_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStopRecording.Click
        btnStartRecording.Enabled = True
        btnStopRecording.Enabled = False
        Application.DoEvents()
        '---save the recording to file---
        SendMessage(hWnd, WM_CAP_FILE_SAVEAS, 0, "C:\" & Now.ToFileTime & ".avi")
    End Sub

    Private Sub btnTakeSnapshot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTakeSnapshot.Click
        Dim data As IDataObject
        Dim bmap As Image
        '---copy the image to the Clipboard---
        SendMessage(hWnd, WM_CAP_EDIT_COPY, 0, 0)
        '---retrieve the image from Clipboard and convert it
        ' to the bitmap format---
        data = Clipboard.GetDataObject()
        If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
            bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Image)
            bmap.Save("C:\Newfolder" & Now.ToFileTime & ".bmp")
        End If
    End Sub


End Class
]

This post has been edited by modi123_1: 08 April 2011 - 08:03 AM
Reason for edit:: please use code tags

Was This Post Helpful? 0
  • +
  • -

#4 perdono-2007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 07-April 11

Re: USB camera interfacing through VB.net

Posted 08 April 2011 - 08:09 AM

the problem is i have USB camera

and i did not find USB port instructions in VB.net

and i could not have comm port no when i connect the camera

i found a usb address but i cant use it in VB.net is there any way to ?

thank you
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1