Accessing ad2*/ser2sock from Terminal

If you want to interact with the ad2* over ser2sock using Terminal on Mac OS X, you can use "nc" or "telnet", but things don't look quite right if you use the default settings. I wrote the following script to avoid the issues I was seeing:
Save this to "ad2pi.sh", then mark it executable ("chmod a+x ad2pi.sh"), and run it ("./ad2pi.sh").
This script assumes your ser2sock is listening on port 10000 on a host named "ad2pi.local"; update the values as needed.
Explanation:
This sequence of commands first saves the current TTY state so that it can restore it later, and then overrides the TTY handling of echoing and newlines. Next, the "nc" command is used to connect to the remote socket. Finally, after "nc" has exited (use Control-C to exit), the TTY state is restored.
- Code: Select all
#!/bin/sh
HOSTNAME=ad2pi.local
PORTNUMBER=10000
SAVED_STTY=`stty -g`
stty -icanon -icrnl inlcr -echoctl -echo echonl
nc $HOSTNAME $PORTNUMBER
stty $SAVED_STTY
Save this to "ad2pi.sh", then mark it executable ("chmod a+x ad2pi.sh"), and run it ("./ad2pi.sh").
This script assumes your ser2sock is listening on port 10000 on a host named "ad2pi.local"; update the values as needed.
Explanation:
This sequence of commands first saves the current TTY state so that it can restore it later, and then overrides the TTY handling of echoing and newlines. Next, the "nc" command is used to connect to the remote socket. Finally, after "nc" has exited (use Control-C to exit), the TTY state is restored.