VB.NET UWP:如何从调制解调器获取串行设备?
我在Vb.net UWP项目中连接到Telit移动调制解调器设备时遇到问题 此调制解调器设备VID:0x1BC7,PID:0x1201由Windows 10识别,并在设备管理器中显示为5个不同的设备: 在COM和LTP端口部分中,如下所示:VB.NET UWP:如何从调制解调器获取串行设备?,vb.net,uwp,modem,Vb.net,Uwp,Modem,我在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
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命令
也许有人可以给我一个提示,如何从两个调制解调器获取串行设备,或者告诉我一种方法,如何向这些设备发送AT命令
在以前构建的Win32应用程序中,我使用查询字符串root\CIMV2创建ManagementObjectSearcher,从Win32\u POTSModem中选择*以查找调制解调器,然后使用调制解调器的ManagementObject的ConnectedTo属性创建SerialPort对象
也许在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>
添加新设备时,我会检查它是否为Telit设备,并创建一个新对象来封装dhe Telit设备及其所有调制解调器端口
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的代码是什么?您可以使用供应商/产品Id获取SerialDevice吗?您好,我编辑了我的帖子,以包含AppManifest的相关部分和硬件枚举。首先,在您的清单文件中,是“函数类型”正确吗?请检查它是否与设备匹配。其次,这两个产品Id是否分别对应于2个USB模式vidpid:1BC7 1201和vidpid:1BC7 0036?第三,在创建SerialDevice时,变量“device.Id”是否不为空,但变量“u device”在代码中为空_device=wait SerialDevice.FromIdAsyncDevice.Id、 最后,请尝试直接使用USB API连接USB调制解调器设备。请参阅
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