У меня проблема с подключением к мобильному модемному устройству Telit в моем проекте Vb.net UWP.
Это модемное устройство (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 я сделал это, создав ManagementObjectSearcher со строкой запроса «root \ CIMV2», «SELECT * FROM Win32_POTSModem», чтобы найти модемы, а затем создал объект SerialPort со свойством «ConnectedTo» объекта Управляющий объект модема.
Может быть, есть аналогичный способ в UWP-Apps?
Я добавил следующую информацию в манифест приложения:
<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, и создаю новый Объект для инкапсуляции устройства 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 Modem» и «Telit USB Modem # 2». В этом случае SerialDevice содержит «Nothing»
Спасибо за вашу помощь