Reputation: 6268
I installed Octo4A on my android phone. It installed Alpine linux and python3. When I run a python script to view the serial ports. It says no ports are found, but it does find the ports on my windows computer using the same script:
import serial.tools.list_ports as ports
def getAvailablePorts():
availablePorts = list(ports.comports())
return availablePorts
availablePorts = getAvailablePorts()
for port in availablePorts:
print("Available port: " + port.device)
The output on windows:
Available port: COM3
Here are the serials listed in Octo4a:
How can I get a list of the available ports and connect to it on android using python3?
Upvotes: 1
Views: 1616
Reputation: 3496
If you look at the code, the way pyserial looks for ports in Linux is by trying to find the following strings:
/dev/ttyS* # built-in serial ports
/dev/ttyUSB* # usb-serial with own driver
/dev/ttyXRUSB* # xr-usb-serial port exar (DELL Edge 3001)
/dev/ttyACM* # usb-serial with CDC-ACM profile
/dev/ttyAMA* # ARM internal port (raspi)
/dev/rfcomm* # BT serial devices
/dev/ttyAP* # Advantech multi-port serial controllers
/dev/ttyGS* # https://www.kernel.org/doc/Documentation/usb/gadget_serial.txt
In Octo4A, serial ports are apparently called /dev/ttyOcto4a
so they will not be found by list_ports()
.
Of course, that does not mean pyserial won't work, you can try to instantiate and open your serial port directly with:
import serial
ser = serial.Serial(port='/dev/ttyOcto4a')
ser.isOpen()
I have not tried this myself, so I can not guarantee it will work.
Upvotes: 2