Python Forum
Name of USB device on Anodrid
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Name of USB device on Anodrid
#1
I have my Python app using in Windows but I am interesting if is possible to run it on Android phone. My app is about 1600 lines of code, I collect data, make some calculations and make some plots. I installed Pydroid and tried to start my code and it works well on Android. I can open saved data in csv and make all calculations and plots. But if I want connect my usb serial device to mobile and read data, I am not able to find it. So I installed USB Serial Terminal and I can connect my device and read data. It showes me name Serial device - CDC, Name: Teensyduino. I can communicate with my device.
Question is: is any way how to update my python code to connect my device on android mobile?
Thanks.

Now I use this code to detect usb serial:
def serial_read():
    # Define raw_data as a global variable
    global raw_data
    global SPS
    SPS = 3000
    raw_data = np.zeros(SPS)
    current_os = platform.system()
    print(current_os)
    devices = []
    if current_os == "Windows":
        # Scan all available COM ports to find connected devices
        for i in range(10):
            try:
                port = 'COM{}'.format(i + 1)
                s = serial.Serial(port)
                devices.append(port)
                print(devices)
                s.close()
            except (OSError, serial.SerialException):
                pass
    elif current_os == "Linux":
        # Search for serial devices on Linux
        devices = glob.glob("/dev/ttyACM*")
    else:
        print("Unsupported operating system")
        QMessageBox.about(w, "VG", "Unknown OS")
        sys.exit()
    
    if len(devices) > 0:
        # Connect to the first detected device
        ser = serial.Serial(devices[0])
        print(devices[0])
        ser.write(b't')
        response = ser.read()
        if response == b'@':
            print("Response is correct")
            print("Connect to device: ", devices[0])
            ser.close()
            ser = serial.Serial(port=devices[0], baudrate=2000000)
            s = struct.Struct('<' + str(SPS) + 'f')
            ser.reset_input_buffer()
            ser.write("r".encode())
            serial_data = ser.read(SPS * 4)
            unpacked_data = s.unpack(serial_data)
            raw_data = np.array(unpacked_data)
            ser.close()
            connected = True
        else:
            print("Unexpected response")
            ser.close()
            connected = False
            QMessageBox.about(w, "app", "Not connected device")
    else:
        print("No connected serial USB devices found")
        connected = False
        QMessageBox.about(w, "app", "No device connected or used by other app")
    return connected, raw_data
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading UDP from external device without device software ikdemartijn 2 3,424 Dec-03-2019, 04:29 PM
Last Post: Larz60+
  Display device details i.e connected with more than one device shintonp 6 5,337 May-10-2017, 06:00 AM
Last Post: shintonp

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020