none
GetCommState 讀回來的BaudRate=0 ?? RRS feed

  • 問題

  • 下面是我的程式碼

    請問ㄧ下

    我用GetCommState 把手機的狀態透過DCB讀回來

    我看了此函數的回傳值是True

    可是..為何BaudRate=0 ??

    請大家給點建議

    ------------------------------------------------------------

    Imports System.Runtime.InteropServices
    Public Class Form1
        Dim infileHandler As Long
        Dim home_DCB As New DCB()
        Dim home_comm As Boolean
        Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
            connect()
        End Sub

        Public Sub connect()
            Dim inPort As Short = 6
            infileHandler = CreateFile("COM" & inPort & ":", _
                                        &HC0000000, 0, 0, 3, 0, 0)
            Application.DoEvents()

            home_comm = GetCommState(infileHandler, home_DCB)
            'MsgBox(home_comm)
            MsgBox("baud=" & home_DCB.BaudRate)
        End Sub

        <DllImport("coredll.dll")> _
    Private Shared Function CreateFile(ByVal lpFileName As String, _
                                       ByVal dwDesiredAccess As Integer, _
                                       ByVal dwShareMode As Integer, _
                                       ByVal lpSecurityAttributes As Integer, _
                                       ByVal dwCreationDisposition As Integer, _
                                       ByVal dwFlagsAndAttributes As Integer, _
                                       ByVal hTemplateFile As Integer) As Integer
        End Function

        'Declare structures.
        Public Structure DCB
            Public DCBlength As Int32
            Public BaudRate As Int32
            Public fBitFields As Int32 'See Comments in Win32API.Txt
            Public wReserved As Int16
            Public XonLim As Int16
            Public XoffLim As Int16
            Public ByteSize As Byte
            Public Parity As Byte
            Public StopBits As Byte
            Public XonChar As Byte
            Public XoffChar As Byte
            Public ErrorChar As Byte
            Public EofChar As Byte
            Public EvtChar As Byte
            Public wReserved1 As Int16 'Reserved; Do Not Use
        End Structure

        <DllImport("coredll.dll", EntryPoint:="GetCommState")> _
        Public Shared Function GetCommState(ByVal hFile As Integer, ByRef dcb As DCB) As Boolean
        End Function
    End Class

     

     

     

    2010年5月4日 下午 01:03