我有一项任务是与摩托罗拉SNAPI扫描引擎设备建立通信,作为vb.net项目。我一直在参考摩托罗拉C#中的示例源代码以及Snapi文档。设备正确响应SNAPI_Init调用,但随后无法处理以下SNAPI_Connect调用。请协助。感谢。
`
`**My vb.net code:**
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.IO
Imports System.Threading
Imports System.Runtime.InteropServices
Imports System.Collections.ObjectModel
Imports System.Collections.Specialized
Imports System.Windows.Forms
Imports System
Imports Scan_2d_7mar.SnapiDLL
Public Class Form1
'Declaration
Dim status As Integer
Dim xstatus As Integer
Dim num_device As Integer
Dim m_hWnd As Integer = Me.Handle.ToInt32
Dim devicehandle(8) As Integer
Dim sernum() As String
'obtain and populate the s/n for this scanner
Public sb As New System.Text.StringBuilder(100)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
status = SnapiDLL.SNAPI_Init(m_hWnd, devicehandle, num_device)
TextBox1.Text = devicehandle(0)
TextBox2.Text = num_device
TextBox3.Text = m_hWnd
If ((status = 0) And num_device) Then 'Assuming one scanner found during call to SNAPI_Init
Dim y() As Byte
xstatus = SNAPI_GetSerialNumber(devicehandle(0), y)
xstatus = SnapiDLL.SNAPI_Connect(devicehandle(0))
TextBox2.Text = sb.ToString(4, sb.Length - 4)
TextBox1.Text = xstatus
Else
TextBox1.Text = 9
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End Sub
End Class