我在Vb.net UWP项目中连接到Telit移动调制解调器设备时遇到问题。
该调制解调器设备(VID:0x1BC7,PID:0x1201)已被Windows 10识别,并在设备管理器中显示为5种不同的设备:
在“ COM和LTP端口”部分中为:
Telit Serial Diagnostics Interface
Telit Serial NMEA Interface
Telit SAP Interface
在“调制解调器”下为:
Telit USB Modem
Telit USB Modem #2
在我的VB.Net应用程序中,我创建了一个DeviceWatcher对象,该对象已经检测到所有5个设备。
在下一步中,我尝试为找到的每个设备创建一个SerialDevice,但这仅适用于其中的前3个。
问题是:我需要连接到至少两个USB调制解调器之一才能发送AT指令。
也许有人可以给我一个提示,如何从两个调制解调器中获取SerialDevice或向我展示一种方法,如何向这些设备发送AT命令。
在以前构建的Win32应用程序中,我通过创建带有查询字符串“ root \ CIMV2”,“ SELECT * FROM Win32_POTSModem”的ManagementObjectSearcher来查找调制解调器,然后创建了具有以下属性的SerialConnect对象:调制解调器的ManagmentObject。
UWP应用程序中也许有类似的方法吗?
我在应用清单中添加了以下信息:
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
<DeviceCapability Name="usb">
<!--SuperMutt Device-->
<Device Id="vidpid:1BC7 1201">
<!--<wb:Function Type="classId:ff * *"/>-->
<Function Type="name:vendorSpecific" />
</Device>
<Device Id="vidpid:1BC7 0036">
<!--<wb:Function Type="classId:ff * *"/>-->
<Function Type="name:vendorSpecific" />
</Device>
</DeviceCapability>
要获取设备,我创建了一个包含Devicewatcher对象的类
Public Async Function InitHardwareWatcher() As Task(Of Boolean)
Dim answer As Boolean = True
Status = "Inititalizing"
Try
Await Dlog("Generating Device Watcher", "Orange")
_DeviceWatcher = Windows.Devices.Enumeration.DeviceInformation.CreateWatcher
AddHandler _DeviceWatcher.Added, AddressOf OnAdded
AddHandler _DeviceWatcher.Removed, AddressOf Onremoved
AddHandler _DeviceWatcher.Updated, AddressOf OnUpdated
AddHandler _DeviceWatcher.EnumerationCompleted, AddressOf OnEnumerationCompleted
AddHandler _DeviceWatcher.Stopped, AddressOf OnStopped
Await StartWatcher()
Initiated = True
Catch ex As Exception
Print_Error(ex)
answer = False
End Try
Return answer
End Function
Public Async Function StartWatcher() As Task(Of Boolean)
Dim answer As Boolean = True
Await Dlog("Starting Device Watcher", "Orange")
Try
_DeviceWatcher.Start()
Status = "Running"
Catch ex As Exception
Print_Error(ex)
answer = False
End Try
Return answer
End Function
Private Async Sub OnAdded(watcher As Windows.Devices.Enumeration.DeviceWatcher, deviceinfo As Windows.Devices.Enumeration.DeviceInformation)
Try
If InitialScanPerformed = True Then
Await Log("Devices", "Added Device: " & vbLf & Print_Hardware(deviceinfo), "Green")
Checknewhardware(deviceinfo)
Else
Checknewhardware(deviceinfo)
End If
Catch ex As Exception
End Try
End Sub
当添加新设备时,我检查它是否为Telit设备,并创建一个新对象以将tele设备及其所有调制解调器端口封装在一起。
Private Async Sub Checknewhardware(device As DeviceInformation)
Dim id As String = ""
Dim iddata() As String = Nothing
Dim devdata As DevID
Dim found As Boolean = False
Try
'Await plog("Checknewhardware called", Colors.Orange)
iddata = device.Id.Split("#")
devdata = Await ParseDevID(iddata(1))
Select Case devdata.VendorID
Case "1BC7" ' Telit
'Await plog("New Hardware is Telit")
Select Case devdata.DeviceID
Case "1201" ' LE 9x0
Await Plog("New Hardware is LE9x0")
If Global_Modem Is Nothing Then Global_Modem = New LE9x0(device)
found = True
Case "0036"
Await Plog("New Hardware is LE910 V2")
If Global_Modem Is Nothing Then Global_Modem = New LE910_V2
found = True
Case Else
Await Plog("Dev ID: " & devdata.DeviceID, "Red")
End Select
Case Else
'Await plog("Vendor ID : " & devdata.VendorID, Colors.Red)
Exit Sub
End Select
If found = True Then Global_Modem.NewDevice(device)
Catch ex As Exception
Print_Error(ex)
End Try
End Sub
在Telit设备的类中,尝试创建SerialDevice
Private Async Sub Set_device(Device As DeviceInformation)
Dim outtext As String = "Setting New GPS Serial Device" & vbLf
Try
If Device IsNot Nothing Then
End If
outtext = outtext & "Getting SerialDevice from Device ID" & vbLf
_device = Await SerialDevice.FromIdAsync(Device.Id)
If _device IsNot Nothing Then
outtext = outtext & " Serial Device Created" & vbLf
outtext = outtext & "Setting Serial Parameters" & vbLf
With _device
.BaudRate = 9600
'.Parity = SerialParity.None 'Parity.None
'.DataBits = 8
'.StopBits = SerialStopBitCount.One
'.Handshake = SerialHandshake.None
'.IsDataTerminalReadyEnabled = True
'.IsRequestToSendEnabled = True
End With
Else
outtext = outtext & " Serial Device NOT Created" & vbLf
End If
outtext = outtext & "Trying to create Stream Reader" & vbLf
_Reader = New StreamReader(_device.InputStream.AsStreamForRead)
outtext = outtext & "Streamreader Created" & vbLf
Catch ex As Exception
Print_Error(ex)
End Try
Tlog(outtext, "Green")
End Sub
这适用于除“ Telit USB调制解调器”和“ Telit USB调制解调器#2”以外的所有端口。在这种情况下,SerialDevice包含“ Nothing”(无)
感谢您的帮助