none
UBIQ-230 和 IrDA 的問題 [vb.net 2005] RRS feed

  • 問題

  • 我有一台研華的 UBIQ-230, 而這一台上面有一個紅外線發射/接收, 我想用 vb.net 來寫一個 irda 發射及接收程式, 我用 Visual Studio 的 "插入程式碼片段" 的功能中的 "探索 IrDA 裝置" 於執行時都會發生錯誤, 因為沒有錯誤說明, 只知道發生誤, 請問要如何使用 IrDA 呢??

    2008年1月3日 上午 08:12

所有回覆

  • 插入程式碼片段 - 傳送IrDA傳輸的程式如下:

     

    Private Sub sendIrDAData(ByVal irServiceName As String, ByVal dataFile As String)

            Dim irClient As New IrDAClient()
            Dim irDevices() As IrDADeviceInfo
            Dim buffersize As Integer = 256

            ' Create a collection of devices to discover.
            irDevices = irClient.DiscoverDevices(2)

            ' Connect to the device
            Dim irEndP As New IrDAEndPoint(irDevices(0).DeviceID, irServiceName)
            Dim irListen As New IrDAListener(irEndP)
            irListen.Start()
            irClient = irListen.AcceptIrDAClient()

            ' Open a Pocket Word file to send and get its stream.
            Dim fs As Stream
            fs = New FileStream(dataFile, FileMode.Open)

            ' Get the underlying stream of the client.
            Dim baseStream As Stream = irClient.GetStream()

            Dim length As Byte() = BitConverter.GetBytes(fs.Length)
            baseStream.Write(length, 0, length.Length)

            ' Create buffer for reading the file.
            Dim buffer(buffersize) As Byte
            Dim fileLength As Integer = CInt(fs.Length)

            ' Read the file stream into the base stream.
            While fileLength > 0
                Dim numRead As Int64 = fs.Read(buffer, 0, buffer.Length)
                baseStream.Write(buffer, 0, numRead)
                fileLength -= numRead
            End While
            fs.Close()
            baseStream.Close()
            irClient.Close()

        End Sub

     

    插入程式碼片段 - 探索IrDA裝置的程式如下:

     

    Private Sub FindIrDADevices()
            Dim irDevices() As IrDADeviceInfo
            Dim irClient As New IrDAClient()

            ' Create a collection of a maximum of three devices.
            irDevices = irClient.DiscoverDevices(2)

            If irDevices.Length > 0 Then

                For Each device As IrDADeviceInfo In irDevices

                Next
            End If
        End Sub

     

    插入程式碼片段 - 接收IrDA傳輸的程式如下:

     

    Private Sub writeIrDADataToFile(ByVal irServiceName As String, ByVal fileName As String)

            Dim irClient As New IrDAClient()
            Dim irDevices() As IrDADeviceInfo
            Dim buffersize As Integer = 256

            ' Create a collection of for discovering up to
            ' three devices, although only one is needed.
            irDevices = irClient.DiscoverDevices(2)

            ' Cancel if no devices are found.
            If irDevices.Length = 0 Then
                Exit Sub
            End If

            ' Connect to the first IrDA device
            Dim irEndP As New IrDAEndPoint(irDevices(0).DeviceID, irServiceName)
            irClient.Connect(irEndP)

            ' Create a stream for writing a Pocket Word file.
            Dim writeStream As Stream
            writeStream = New FileStream(fileName, FileMode.OpenOrCreate)

            ' Get the underlying stream of the client.
            Dim baseStream As Stream = irClient.GetStream()

            ' Create buffer for reading the file.
            Dim buffer(buffersize) As Byte

            Dim numToRead, numRead As Int64

            numToRead = 8

            While numToRead > 0
                numRead = baseStream.Read(buffer, 0, numToRead)
                numToRead -= numRead
            End While

            ' Get the size of the buffer to show
            ' the number of bytes to write to the file.
            numToRead = BitConverter.ToInt64(buffer, 0)

            Try
                While numToRead > 0
                    numRead = baseStream.Read(buffer, 0, buffer.Length)
                    numToRead -= numRead
                    writeStream.Write(buffer, 0, numRead)
                End While
            Finally
                writeStream.Close()
            End Try

            baseStream.Close()
            irClient.Close()

        End Sub

     

    您可以參考看看

     

    tihs

    2008年1月8日 上午 03:24
  • 你好..

     

    我試過了~  我是用插入程式碼片段 內的 IrDA 來測試的, 結果錯誤, 後來詢問研華, 他們跟我說, 要用他們的 DLL 來讀取...

    所以, 這一台的 IrDA 可能不是標準的...

    2008年1月11日 上午 08:27