Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Talking with a "modem" #4

Open
KenSamson opened this issue Jul 3, 2022 · 2 comments
Open

Talking with a "modem" #4

KenSamson opened this issue Jul 3, 2022 · 2 comments

Comments

@KenSamson
Copy link

I have a device connected to my android tablet... when I run the termux-usb -l command, I do get /dev/bus/usb/002/002 back.

So I'm connected... all seems well.

This device uses 9600 baud, and communicates via AT commands.. like a modem. So I'm trying to write a simply python script in termux using termux_usb_python to send AT commands to the device, and read what it says back out from the device.

In the usbtest_rw1.py example, I do see where CP210xSerial is used with the baudRate option....

But for the life of me I'm having a hard time getting a simple linear python script to send "AT\r\n" to the modem, and have it say "OK" back to me.

While this may seem super trivial to someone who has done it here... is there any way I can get some ideas (without using a .sh file) that I can just send and receive that text over the USB port with this library?

Thank you so much for any time you spend... I know everyone is busy. I've just spent hours trying to do this both interactively and piecing scripts together.. and I'm just not able to see where to go. I basically need to send text lines and get text line back. It's that simple.

Thank you!

Ken

@Querela
Copy link
Owner

Querela commented Jul 3, 2022

So, it is already a long time since I had time to experiment. :-) and I currently do not have anything easy to test at hand.

What you have to keep in mind is that on Termux/Android, USB access only works as callbacks. That means the Termux cli call requires a program that is called with the USB file descriptor. The sh files are mostly some setup/multiplexing stuff, not absolutely required. A plain python script should work, I think. But again, a long time ago. And I used a virtual env, so the wrapper scripts were required. See the usblib.py.sh/usblib.py file. Try to get this to run. It has some interactive shell to test code. But I'm unsure if update in the meantime have broken some things...

You should really try to get the examples working, see the links in the repo readme. If they work, then there might still be something with the device and drivers. For example I never got the esptool to work, and never found out why.
I'm not sure whether your device uses the cp210x driver and some plain command stuff or more.
Did it work with your computer? (Where you don't have to go through loops just to access the USB device? Then you might be able to add the python callback code to the working functionality.)
Then it is sometimes not easy to work with the buffers etc. More or less trial and error sometimes. E.g. if not read completely then some read/write will not work anymore ... In case you want to capture device output... That's why there is a lot of threading, buffering etc. in the code. But you should be able to hard code some simple sending and receiving but might need to fiddle with the code.
I would point you to the usblib, pyusb, Termux USB threads since there are more people active that might be able to help or you might find some code samples that prove useful.
I currently don't really have the time to help you, sorry.

@WheezyE
Copy link

WheezyE commented Jan 29, 2023

I’m interested in writing a similar bridge for some ham radio software modems so that I can connect a ham radio via USB to Termux running software modems (Winelink script: Modems-Termux-Py-OTG-Radio). Did you make any progress with your modem-otg-py-termux script?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants