Acuity AP820 Laser Scanners
Rev. 3.3
32
As UInteger
)
As UInteger
End Function
<DllImport(
"EthernetScanner.dll"
)> _
Private Function
EthernetScanner_WriteData(
ByVal
pScanner
As
IntPtr,
ByVal
Buffer
As Byte
(),
ByVal
Buffersize
As UInteger
)
As UInteger
End Function
<DllImport(
"EthernetScanner.dll"
)> _
Private Function
E
thernetScanner_GetVersion(<MarshalAs(UnmanagedType.LPStr), Out()>
ByVal
Version
As
StringBuilder,
ByVal
Result
As UInteger
)
As UInteger
End Function
<DllImport(
"EthernetScanner.dll"
)> _
Private Shared Function
EthernetScanner_GetScanRawData(
ByVal
pScanner
As
IntPtr,
ByVal
Buffer
As Byte
(),
ByVal
BufferSize
As UInteger
,
ByVal
ScanProfileMode
As UInteger
,
ByVal
Timeout
As UInteger
)
As Boolean
End Function
We will discuss each function individually as we go. Note that, with the exception of
EthernetScanner_GetVersion, there is a managed type with default marshalling behavior
that matches the unmanaged type in the dll. The exception,EthernetScanner_GetVersion,
requires a null-terminated string in the buffer passed to it by a pointer. To accomplish
this, we will use the buffer of the StringBuilder type and the MarshalAs attribute in
System.Runtime.InteropServices to marshal the StringBuilder as a pointer to a null-
terminated string.
11.2
Calling EthernetScanner_GetVersion
The EthernetScanner_GetVersion function is a fast and easy way to prove that we are
calling the dll correctly, because it is not dependent on the laser in any way. Having
imported the dll using DllImport as in the above example, we can use the following code
to call EthernetScanner_GetVersion:
Public Function
GetVersion()
As String
'Buffer must be at least 256 bytes long
Dim
VersionBuffer
As New
System.Text.StringBuilder(256)
Dim
Result
As UInteger
Result = EthernetScanner_GetVersion(VersionBuffer, 256)
'This function returns the length of the Version String on success
'or -1 on Error
If
Result > -1
Then
Return
VersionBuffer.ToString
Else
Return
"Error"
End If
End Function
Note: The above function should return a string similar to: “1.0.2.1 110629”.
11.3
Establishing Ethernet communication with the AP820
Refer to section 2.1.2