我制作了一个程序来接收来自2D扫描仪的数据,但是当我使用GetData
方法时,它会返回一个我不知道标题的哪个部分的数据。因此,我根据扫描仪手册中报告的标题创建了用户定义类型,但我无法根据每种类型获取包。以下是我在VBA
中使用Winsock
控件生成的代码。还有扫描仪手册中报告的标题打印输出。
Private WithEvents tcpClient As Winsock
Public Event DataArrival(ByVal bytesTotal As Long)
Private Type packet_Header
magic As Integer
packet_type As Integer
packet_size As Integer
header_size As Integer
scan_number As Integer
packet_number As Integer
timestamp_raw As Date
timestamp_sync As Date
status_flags As Integer
scan_frequency As Integer
num_points_scan As Integer
num_points_packet As Integer
first_index As Integer
first_angle As Integer
iq_input As Integer
angular_increment As Integer
iq_overload As Integer
header_padding As Integer
End Type
Private Type scan_point_data
distance As Integer
End Type
Public Sub CommandButton1_Click()
Set tcpClient = New MSWinsockLib.Winsock
tcpClient.Protocol = sckTCPProtocol
tcpClient.Connect "169.254.218.229", "59164"
MsgBox tcpClient.State
'MsgBox tcpClient.SocketHandle
MsgBox tcpClient.BytesReceived
End Sub
Public Sub tcpClient_DataArrival(ByVal bytesTotal As Long)
Dim teste As packet_Header
tcpClient.GetData teste.magic
MsgBox teste.magic
End Sub
扫描仪: