Android Question CDC Serial device with multiple ports

Dalyn Becker

New Member
Licensed User
Longtime User
I have a device here that shows up in a "Serial USB Terminal" app that I downloaded from the play store. It shows up as 3 different devices in the USB device list. They all have the same vendor and product IDs. In the list they show up as "Serial device - CDC - Port 1", "Serial device - CDC - Port 2", and "Serial device - CDC - Port 3". Port 2 and Port 3 device selections connect and transmit the data they are supposed to. So I know the Android OS supports it. Port 1 is for connecting to a PC and changing the chip settings. When I use the USB Serial Libraries in B4A, it only connects to port 1, which has no data on it. Does the USB serial libraries support serial devices with multiple ports? Thanks
 

Dalyn Becker

New Member
Licensed User
Longtime User
Finally have time to work on the project again. I've been struggling to get it to work. The btnOpen2 code works with my arduino. The btnOpen code is what I am trying to use to connect to B4aInterfaceNumber:1 on another device that is putting out a text stream on port 2. It seems to connect but there is no data coming through. Just wondering if anyone could point me in the right direction. I have searched and searched for an example using the interface part and can find no examples to look at. I was going to post a screenshot of the device info but the file seems to be to large. Thanks

B4X:
Sub btnOpen_Click

  

        Dim device As UsbDevice

        Dim usbInterface As UsbInterface

        Dim usbconnection As UsbDeviceConnection

      

        device = usbManager.GetDevices(1)

        usbInterface = device.GetInterface(1)

        usbManager.RequestPermission(device)

        If (usbManager.HasPermission(device)) Then

            MsgboxAsync(device.GetInterface(1),"Interface Number")

            usbconnection = usbManager.OpenDevice(device,usbInterface,True)

            usbconnection.StartListening("astreams")

      

    Else

        usbManager.RequestPermission(device)

    End If

End Sub


Sub btnOpen2_Click

  

    If usb.UsbPresent(1) = usb.USB_NONE Then

        Log("Msgbox - no device")

        MsgboxAsync("No USB device or accessory detected!", "Error")

        Log("Msgbox - returned")

        Return

    End If

    Log("Checking permission")

    If (usb.HasPermission(1)) Then


        MsgboxAsync(usb.DeviceInfo(1), "Device Information")

        Dim dev As Int

        dev = usb.Open(9600,1)


        If dev <> usb.USB_NONE Then

            Log("Connected successfully!")

            btnOpen2.Enabled = False

            btnClose2.Enabled = True

            btnSend.Enabled= True

            btnSend2.Enabled = True

          

            astreams.Initialize(Me,"astreams",usb.GetInputStream,usb.GetOutputStream)

        Else

            Log("Error opening USB port")

        End If

    Else

        usb.RequestPermission(1)

    End If

End Sub
 
Upvote 0

Dalyn Becker

New Member
Licensed User
Longtime User
Or am I missing something yet? Like defining an endpoint or something?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…