this post was submitted on 05 May 2024
14 points (93.8% liked)

Open Source

31372 readers
137 users here now

All about open source! Feel free to ask questions, and share news, and interesting stuff!

Useful Links

Rules

Related Communities

Community icon from opensource.org, but we are not affiliated with them.

founded 5 years ago
MODERATORS
 

Anyone know of any scriptable asynchronous communication tools?

The closest so-far appears to be Kermit. It's been around since CP/M, but apparently there's still no centralised language reference and the syntax predates Perl.

top 15 comments
sorted by: hot top controversial new old
[–] Lodra 3 points 6 months ago (1 children)

Uh email? It’s not exactly exciting but there are loads of tools available for automating emails. Definitely asynchronous. Does it fit your needs?

[–] [email protected] 3 points 6 months ago* (last edited 6 months ago) (2 children)

No, it needs to be serial communication. My use case is talking to a CNC.

Edit: fat fingers: "ea" -> "to a"

[–] Lodra 4 points 6 months ago (1 children)

lol got it. Definitely not email then

[–] [email protected] 1 points 6 months ago

That would be fun tho

[–] [email protected] 1 points 6 months ago* (last edited 6 months ago) (1 children)

I used expect a lifetime ago to reliably talk to a bunch of very strange ISDN modems.

https://www.tcl.tk/man/expect5.31/expect.1.html

I think something like expect also exists for more modern languages, but tcl is still easy enough to learn (just a little unusual, everything is a string)

[–] [email protected] 1 points 6 months ago

That's several recommendations for expect. I'll start digging. Thank you.

[–] [email protected] 1 points 6 months ago (1 children)

Kermit on top of FTP can work really well. Kermit has its own communication and transfer protocol, IIRC, but updates in the 1990's allowed it to be used with TCP/IP and FTP. So you can write a script to log into a remote system, run some commands and then initiate a file transfer. The scripting allows you to wait for responses and act on them.

[–] [email protected] 1 points 6 months ago (1 children)

Yes. As I said, I'm aware of Kermit. It's like sendmail, user friendly, just picky who it makes friends with.

I have not discovered a complete language reference for Kermit, neither have I been able to determine if it works asynchronously, since the examples I've found are just polling loops, which is not what I need.

My use case is talking over serial to a CNC to iteratively calibrate it. This requires dealing with asynchronous events, think move, interrupt by edge switch.

[–] [email protected] 1 points 6 months ago (1 children)

Keep in mind that it has been decades since I last used Kermit, but I'm pretty sure the use case it was originally designed for was...

Connect to a serial port, which had a modem attached. Talk to the modem and get it to dial a number. Presumably, the remote end answered and the port attached to its modem would issue a login prompt. Negotiate the login and then issue a bunch of commands to change directories and then launch Kermit on the remote system. After that Kermit to Kermit communications took over until you terminated the session. Finally, log off the remote system and hang up the modem.

All of this stuff could be done via scripts. I seem to remember that it would actually wait for a response, and then parse the response in the script. I don't remember ever doing polling loops.

If you're on a *nix box of some type, it's totally possible to open up a serial port for manual I/O even in something like a bash script. Even if you have to reverse telnet to a terminal server.

[–] [email protected] 1 points 6 months ago (1 children)

I started down the bash path but came unstuck when I wanted to create a process that uses a single bidirectional serial port to write a move command, whilst reading the current location and checking to see if an end stop switch was closed to write a stop command.

Ideally, all of it is interrupt driven, but I'm at a loss to see how I can do this with either Kermit or expect. Both appear to use a send, then wait for a response model, even if you can check for different responses.

Of note is that the end stop is external to the serial communication, so I can't check the same stream for that information.

[–] [email protected] 1 points 6 months ago (1 children)

the end stop in external to the serial communication

Does this mean that you have some kind of other signals or pin-outs? If so, this is starting to sound like a great project for a Raspberry Pi, because the GPIO pin array can handle that.

[–] [email protected] 1 points 6 months ago (1 children)

Yeah, it's already on a pi, connected to my LAN and the USB port of the CNC. The switch is on a gpio pin.

I need to automate the calibration of the three axis. In other words, tell the CNC to move a specific distance, then figure out how far it actually moved, update the number of steps per mm, rinse and repeat.

To implement this, I have a known calibrated distance, a set of three 1-2-3 blocks, so I actually need to move until the switch closes, then ask the CNC how far it thinks it moved.

I intend to run this several times because right now, doing it manually is giving me weird results and I'm trying to figure out the root cause of the error.

So, I need to move an axis, interrupt the move if the switch is closed, and keep moving until the switch is closed.

[–] [email protected] 1 points 6 months ago (1 children)

Maybe then you need to move one stop up from scripting into something closer to actually programming. I'd be surprised if Python doesn't have the library support on a Pi for dealing with both serial and GPIO I/O.

[–] [email protected] 1 points 6 months ago (1 children)

Yeah, I was hoping to avoid that, but it's been heading that way for a few days now :}

[–] [email protected] 1 points 6 months ago

I looked and Python has the library support for the GPIO and to do background threading to poll pins. My preference would be to go with a JVM language like Kotlin, but then I'm a programmer. Python, from the little that I've mucked about with it is really just one step in complexity from scripting. Maybe even easier, because some things in shell scripts are super difficult to do.