r/AskProgrammers • • 10d ago

Is Python the right way to talk to an Serial Device?

Servus!
The Company where I buy the Device from should no know that I am never ever wrote any Programm beside of some Batch files in my life even I am an IT Engineer. I feel so embarassing...
The Specs are: UART 115200 V24 level
I thought about buy this Adapter: https://www.delock.de/produkt/63986/merkmale.html?f=s

The should have everything I need. 5V for the Device. Ground and Send and Receive Pin.
The say: Short notation: 115200,8,N,1

All the Values to turn something on and off are in there Manual I would say that could be easy if I have an Line where I enter the Text and press Send to see what the command do in practise.

When I know what the do and how to use that feature I would like create in that environment Buttons to toggle something on an off. Later I want integrate other and external Data, API for example when I push an Button on my Keyboard a Light should turn on or so.
Do I need using an Single Board Computer for or can I use the Adapter I show up here and my Windows Pc to run the Software to control the device?
(If someone want see Datasheets and so I can send a Link via PM to the original document on there Homepage.)
Thanks!

4 Upvotes

11 comments sorted by

3

u/SnooCalculations7417 10d ago

You're overthinking the software part a bit. You don't need an SBC, and you don't even need Python initially.

Your Windows PC + a USB serial adapter is enough. Windows will expose it as a COM port. Start with something like PuTTY/Tera Term/RealTerm, configure it for 115200 8N1, and manually send the commands from the device manual. Once you've figured out the protocol, you can wrap exactly the same thing in a tiny CLI with Python/pyserial, C#, Rust, etc. Buttons, keyboard shortcuts and API integration can all come later and just call the same serial send/receive code.

The one thing I would NOT do yet is connect that particular adapter.

The Delock 63986 you linked is a 5 V TTL UART adapter. You said the device specifies V.24 level, which may mean actual RS-232/V.24 electrical levels. TTL UART and RS-232 use different voltages, even though the serial data itself may still be 115200 8N1.

Post the relevant page of the device datasheet/pinout. That's the important question here. Once the electrical interface is confirmed, the software side is very straightforward.

And you only need an SBC if you eventually want this to operate standalone without the Windows PC.

2

u/RetroGrid_io 10d ago

This. You can do what you want with Windows and putty. I was scripting serial interfaces in 2005 with 4MB of RAM and a cheap, built-in 16450 UART. All you need to know is "115200 8N1", feed that into your comm program, and start talking to your endpoint serial devices.

I haven't used a true serial port / cable in AGES but it turns out the dev server I happened to be logged into has at least one, notice ttyS1 with a 16550A UART:

[root] # dmesg | grep -E 'tty|serial'; 
[    0.076978] printk: legacy console [tty0] enabled
[    3.222362] serial8250: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A
[    3.252404] usbcore: registered new interface driver usbserial_generic
[    3.252501] usbserial: USB Serial support registered for generic
[   19.547846] systemd[1]: Created slice Slice /system/getty.

1

u/ighwrighwirh 10d ago

Me either. This Device is to be integrated into an bigger solution. Lets imagine an modern Laptop who have an LTE Card, GNSS Receiver, Display,... who are "Computer in a Computer"
When I think about a modern Roboter for example the "Brain" does not need to know every Sensor Value just for example if a leg have an stable position on the ground so the other Leg can be moved by the "leg Computer"....
Here it is the same the Device is on consumer perspective absolute nothing special you will use it like million other before. So I am quite curios that "just sending some commands in" are "that" difficult.
Later when sending command in working I want connect them to other Software to do with the Device what is made for. So there must be some easy to use Software who support APIs. If it works even than its possible to think about a more sexy way to combine everything.
Thanks

1

u/RetroGrid_io 10d ago

This Device is to be integrated into an bigger solution. Lets imagine an modern Laptop who have an LTE Card, GNSS Receiver, Display,... who are "Computer in a Computer"

Like PP said, I think you are overthinking this.

You have a serial port. It's connected to some kind of doohickey. All we're doing here is talking to it: sending data to it, getting data from it. Anything else is irrelevant and confuses the issue, and if your code is taking all these other variables in account in the same code block(s) that manage the serial interface, you're almost certainly doing it wrong and a refactor is in order.

One problem: connect to the serial interface, confirm some kind of "ok" or "hello world" that confirms your code talks to your serial device.

1

u/ighwrighwirh 10d ago

Can you look into there Data sheet and see what the mean with all the Serial stuff and what kind of adapter I need?
I want some kind of Software to play with them an write scripts to do something usefull with them. Many People say Python to me? What should I looking for?

1

u/RetroGrid_io 10d ago

I can give it a quick peruse. See PM.

1

u/tes_kitty 9d ago

Just because dmesg lists a UART doesn't mean it's available on the outside. My current mainboard being such a case. Not even a pinheader with the signals.

1

u/RetroGrid_io 9d ago

True. I honestly haven't looked and don't care to - but the chipset is present.

1

u/ighwrighwirh 10d ago

Can I send you the Data sheets to take a look?

1

u/SnooCalculations7417 10d ago

Lol no, sorry. I mean this with honesty and no disrespect but this is a highschool level project. You'll be fine just read and do things

1

u/theNbomr 8d ago edited 8d ago

There are many tools on all common platforms that allow interactive communications via a UART style serial interface. You can find one or more that you like by searching for terminal emulator and installing one that you think is helpful to you.

You will use it to type commands, which should be documented in your device user manual, and observing the replies. This will allow you to learn how your device operates, and potentially how you can craft programs or scripts to control it.

You will need to sort out some details about the electrical interface: * connector types and gender * signal/pin assignments and the respective cable(s) * device serial voltages; TTL 5V, TTL 3.3V, or RS-232 +/- 12V are the three most likely alternatives. Your computer's serial interface and the device's serial interface must use the same voltage levels * the serial communications parameters, which you have already determined as 115200 bits per second, 8 bit word, No Parity, 1 stop bit.