Aug-14-2023, 06:36 AM
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:
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