Hi I am new to b4a and this forum so please accept my apologies if I don't ask the question correctly or I am doing something very stupid.
I am trying to read and write serial data to a Sportident USB device which uses a Silicon labs driver in Windows. Having read the documentation and many threads I discovered the USB Serial library 2.4 and the example code which I believe should work with Silabs devices and the Sportident box appears in the list of devices using the silabs chip. I have also looked at http://www.silabs.com/Support Documents/TechnicalDocs/AN571.pdf but I don't know whether it is relevant.
I changed the baud rate in the example code to 38400 and I subsequently added some Toast messages. I added an xml filter file to the app's /res/xml folder and set that to read only as recommended and changed the manifest. When I run the app and connect the device it asks which app I want to use. I select the app and the screen shows the Open button. When I click that I get a Could not open port Toast message. The device VID and PIDs are shown correctly. Another app can read the box without problems so the hardware works. Any suggestions?
Modified example code for the Open button. The rest of the code is unchanged.
The xml filter file set as read only.
I am trying to read and write serial data to a Sportident USB device which uses a Silicon labs driver in Windows. Having read the documentation and many threads I discovered the USB Serial library 2.4 and the example code which I believe should work with Silabs devices and the Sportident box appears in the list of devices using the silabs chip. I have also looked at http://www.silabs.com/Support Documents/TechnicalDocs/AN571.pdf but I don't know whether it is relevant.
I changed the baud rate in the example code to 38400 and I subsequently added some Toast messages. I added an xml filter file to the app's /res/xml folder and set that to read only as recommended and changed the manifest. When I run the app and connect the device it asks which app I want to use. I select the app and the screen shows the Open button. When I click that I get a Could not open port Toast message. The device VID and PIDs are shown correctly. Another app can read the box without problems so the hardware works. Any suggestions?
Modified example code for the Open button. The rest of the code is unchanged.
B4X:
Sub btnOpen_Click
If usb1.UsbPresent(1) = usb1.USB_NONE Then ' Ver_2.4
Log("Msgbox - no device")
Msgbox("No USB device or accessory detected!", "Error")
Log("Msgbox - returned")
Return
End If
Log("Checking permission 1")
If (usb1.HasPermission(1)) Then ' Ver_2.4
ToastMessageShow("Has permission",False)
Msgbox(usb1.DeviceInfo(1), "Device Information 1") ' Ver_2.4
Dim dev As Int
'dev = usb.Open(115200, 1) ' Ver_2.4
dev = usb1.Open(38400, 1) ' Ver_2.4
If dev <> usb1.USB_NONE Then
ToastMessageShow("Connected",False)
Log("Connected successfully! 1")
btnOpen.Enabled = False
btnClose.Enabled = True
btnSend.Enabled = True
astreams1.Initialize(usb1.GetInputStream, usb1.GetOutputStream, "astreams1")
Else
ToastMessageShow("Could not open port",False)
Log("Error opening USB port 1")
End If
Else
usb1.RequestPermission(1) ' Ver_2.4
End If
End Sub
The xml filter file set as read only.
B4X:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- 0x10c4 / 0x800a Sportident -->
<usb-device vendor-id="4292" product-id="32778"/>
</resources>