Re: Virtual COM port on Linux
Scott Edwards wrote: Behold echo -e and quotes. works with single or double quotes. Very nice. I thought I had tried -e, but apparently I failed. Thanks for the info. --Dave /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
Byron Clark wrote: On Tue, Feb 23, 2010 at 09:04:18AM -0700, Dave Smith wrote: Has anyone gotten a USB device that requires Virtual COM Port support to work in Linux? I'm considering employing this relay[1] to perform a nightly reboot of my pile-of-junk Comcast cable modem. It looks like it uses the FTDI chip so it should work fine with any 2.6.x kernel. The part arrived today and after a few minutes of hacking, it works beautifully. I didn't have to install or configure anything for /dev/ttyUSB0 to appear. And now I have a very simple python script that can turn the relay on: f=open(/dev/ttyUSB0,wb) for byte in [0xff, 0x01, 0x00]: f.write(chr(byte)) f.close() (Is there a one-liner to do this?) I wired the relay such that when the USB connection is lost, the power stays on. It works wonderfully. Thanks for the help all. --Dave /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
On Mon, Mar 15, 2010 at 10:40 AM, Dave Smith d...@thesmithfam.org wrote: Byron Clark wrote: On Tue, Feb 23, 2010 at 09:04:18AM -0700, Dave Smith wrote: Has anyone gotten a USB device that requires Virtual COM Port support to work in Linux? I'm considering employing this relay[1] to perform a nightly reboot of my pile-of-junk Comcast cable modem. It looks like it uses the FTDI chip so it should work fine with any 2.6.x kernel. The part arrived today and after a few minutes of hacking, it works beautifully. I didn't have to install or configure anything for /dev/ttyUSB0 to appear. And now I have a very simple python script that can turn the relay on: f=open(/dev/ttyUSB0,wb) for byte in [0xff, 0x01, 0x00]: f.write(chr(byte)) f.close() (Is there a one-liner to do this?) echo -n \xff\x01\x00 /dev/ttyUSB0 /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
Andrew McNabb wrote: Write that to myscript.py and your one-liner is myscript.py. :) Python really isn't about one-liners. Fortunately, modern Linux distributions come with filesystems, so creating files is easy. :) Well, that's what I did, and it looks like this, which is nice: # cat reboot-comcast-cable-modem #!/bin/bash relay-off sleep 10 relay-on Totally cool. By the way, to do the equivalent on Windows, I had to write 20 lines of C++ code and remember what LPVOID and GetLastError() mean. Plus, I had to manually setup the baud rate and other settings. Why does Microsoft hate us? Since this worked so seamlessly, I think I might buy the bigger version and start working on my Linux-based sprinkler control project... Hmmm... --Dave /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
On Mon, 2010-03-15 at 11:40 -0600, Dave Smith wrote: f=open(/dev/ttyUSB0,wb) for byte in [0xff, 0x01, 0x00]: f.write(chr(byte)) f.close() (Is there a one-liner to do this?) $ python -c with open('/tmp/foo', 'w') as f: map(f.write, [chr(x) for x in (0xff, 0x01, 0x00)]) $ od -t x1 /tmp/foo Does this mean I'm going to be kicked out of the Pythonista club? -- XML is like violence: if it doesn't solve your problem, you aren't using enough of it. - Chris Maden /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
echo -n \xff\x01\x00 /dev/ttyUSB0 Sorry, correction: echo $'\xff\x01\x00' /dev/ttyUSB0 /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
On Mon, Mar 15, 2010 at 12:00 PM, Stuart Jansen sjan...@buscaluz.orgwrote: On Mon, 2010-03-15 at 11:40 -0600, Dave Smith wrote: f=open(/dev/ttyUSB0,wb) for byte in [0xff, 0x01, 0x00]: f.write(chr(byte)) f.close() (Is there a one-liner to do this?) I have Comcast's SMC8014 business ip gateway, with my cable. Which device, out of curiosity, would your 'pile'o junk' from Comcast be? The Motorola model or some other? Scott /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
Nicholas Leippe wrote: echo $'\xff\x01\x00' /dev/ttyUSB0 That's what I was looking for. I didn't escape the 'x' when I tried initially. --Dave /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
Dave Smith wrote: That's what I was looking for. I didn't escape the 'x' when I tried initially. Actually, that appears to not work as I expected. The first problem is that echo needs -n to *not* print a newline character, which would not normally be a problem (but for purity's sake I added -n). The second problem is that the last byte (0x00) does not get written to the device, I assume because echo interprets it as a null-termination character. After it failed to turn on the relay, here's what I did to investigate: echo -n $'\xff\x01\x00' /tmp/foo.txt hexdump -C /tmp/foo.txt 000 ff 01 And ls -l confirms that the file is only 2 bytes in size (not 3 as I expected). Is it not possible to write a 0x00 byte as the final byte using echo? Any ideas why this happens? --Dave /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
On Mon, 2010-03-15 at 12:32 -0600, Dave Smith wrote: Dave Smith wrote: That's what I was looking for. I didn't escape the 'x' when I tried initially. Actually, that appears to not work as I expected. The first problem is that echo needs -n to *not* print a newline character, which would not normally be a problem (but for purity's sake I added -n). The second problem is that the last byte (0x00) does not get written to the device, I assume because echo interprets it as a null-termination character. After it failed to turn on the relay, here's what I did to investigate: echo -n $'\xff\x01\x00' /tmp/foo.txt hexdump -C /tmp/foo.txt 000 ff 01 And ls -l confirms that the file is only 2 bytes in size (not 3 as I expected). Is it not possible to write a 0x00 byte as the final byte using echo? Any ideas why this happens? Because echo is merely processing its argv and the '\0' is seen as terminating the arg, not part of the arg. -- XML is like violence: if it doesn't solve your problem, you aren't using enough of it. - Chris Maden /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
Stuart Jansen wrote: Because echo is merely processing its argv and the '\0' is seen as terminating the arg, not part of the arg. So the shell is parsing the $'\x' and turning it into a binary blob for echo? That makes sense. --Dave /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
On Mon, 2010-03-15 at 12:32 -0600, Dave Smith wrote: After it failed to turn on the relay, here's what I did to investigate: echo -n $'\xff\x01\x00' /tmp/foo.txt hexdump -C /tmp/foo.txt 000 ff 01 And ls -l confirms that the file is only 2 bytes in size (not 3 as I expected). Is it not possible to write a 0x00 byte as the final byte using echo? $ printf '\xFF\x01\x00' /tmp/foo $ od -t x1 /tmp/foo 000 ff 01 00 003 -- XML is like violence: if it doesn't solve your problem, you aren't using enough of it. - Chris Maden /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
On Mon, Mar 15, 2010 at 12:32:40PM -0600, Dave Smith wrote: Actually, that appears to not work as I expected. The first problem is that echo needs -n to *not* print a newline character, which would not normally be a problem (but for purity's sake I added -n). The second problem is that the last byte (0x00) does not get written to the device, I assume because echo interprets it as a null-termination character. This is exactly why I only use shell scripts for very simple tasks. :) -- Andrew McNabb http://www.mcnabbs.org/andrew/ PGP Fingerprint: 8A17 B57C 6879 1863 DE55 8012 AB4D 6098 8826 6868 /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
On Mon, Mar 15, 2010 at 11:57:33AM -0600, Dave Smith wrote: Well, that's what I did, and it looks like this, which is nice: # cat reboot-comcast-cable-modem #!/bin/bash relay-off sleep 10 relay-on By the way, I would probably merge these into the Python script. Then you could relay.py on, relay.py off, or relay.py cycle and have all of the logic in one place. And if you wanted to, you could add a command-line option for setting the delay time. -- Andrew McNabb http://www.mcnabbs.org/andrew/ PGP Fingerprint: 8A17 B57C 6879 1863 DE55 8012 AB4D 6098 8826 6868 /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
Andrew McNabb wrote: This is exactly why I only use shell scripts for very simple tasks. :) Well, I got it to work, and I learned something about command line argument parsing in the process. Here's what I ended up with, and I looked over it, and it was good: # cat reboot-cable-modem #!/bin/bash device=/dev/ttyUSB0 printf '\xFF\x01\x01' $device # Power off sleep 10 printf '\xFF\x01\x00' $device # Power on Now I have to blog about it so you can see pretty pictures of the relay. By the way, I think it's time to start my sprinkler control project. I can buy an 8-channel relay for $50 to get started. :) Yum. --Dave /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
/* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
On Mon, 2010-03-15 at 13:58 -0600, Dave Smith wrote: Andrew McNabb wrote: This is exactly why I only use shell scripts for very simple tasks. :) Well, I got it to work, and I learned something about command line argument parsing in the process. Here's what I ended up with, and I looked over it, and it was good: # cat reboot-cable-modem #!/bin/bash device=/dev/ttyUSB0 printf '\xFF\x01\x01' $device # Power off sleep 10 printf '\xFF\x01\x00' $device # Power on commit 6ec863c7e6ff94b59b01a16459f04de41fba4e86 Author: Stuart Jansen sjan...@buscaluz.org Date: Mon Mar 15 14:07:36 2010 -0600 Converted reboot-cable-modem to use more idiomatic Bash * Don't write Perl like C, and don't write Bash like Python. - Uppercase variable names - Plenty of whitespace * Stuarts Rule of Shell Variables: Always quote variable unless you have a very, very good reason not to. #!/bin/bash DELAY=10 DEVICE=/dev/ttyUSB0 printf '\xFF\x01\x01' $DEVICE # Power off sleep $DELAY printf '\xFF\x01\x00' $DEVICE # Power on -- XML is like violence: if it doesn't solve your problem, you aren't using enough of it. - Chris Maden /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
Stuart Jansen wrote: #!/bin/bash DELAY=10 DEVICE=/dev/ttyUSB0 printf '\xFF\x01\x01' $DEVICE # Power off sleep $DELAY printf '\xFF\x01\x00' $DEVICE # Power on Commit rejected. Never name a variable that has anything to do with time without using the units in the name: -DELAY=10 +DELAY_SECONDS=10 :) --Dave /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
Behold echo -e and quotes. works with single or double quotes. supap...@li:~$ echo -en \xFF\x01\x00 junk supap...@li:~$ hd junk ff 01 00 |...| 0003 supap...@li:~$ echo -en '\xFF\x01\x00' junk supap...@li:~$ hd junk ff 01 00 |...| 0003 /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
Dave Smith wrote: Has anyone gotten a USB device that requires Virtual COM Port support to work in Linux? I'm considering employing this relay[1] to perform a nightly reboot of my pile-of-junk Comcast cable modem. Assuming the serial controller on that board is supported by Linux, when you plug in the device to a computer running a recent distribution, you'll get a device called /dev/ttyUSB0, which you can use like an ordinary serial port. OTOH, you might instead try a modem that is not a pile of junk. I bought a Motorola SB6120 a month ago, for use with Comcast, and I've been quite happy. Shane /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
Shane Hathaway wrote: Dave Smith wrote: Has anyone gotten a USB device that requires Virtual COM Port support to work in Linux? I'm considering employing this relay[1] to perform a nightly reboot of my pile-of-junk Comcast cable modem. Assuming the serial controller on that board is supported by Linux, when you plug in the device to a computer running a recent distribution, you'll get a device called /dev/ttyUSB0, which you can use like an ordinary serial port. OTOH, you might instead try a modem that is not a pile of junk. I bought a Motorola SB6120 a month ago, for use with Comcast, and I've been quite happy. That may indeed be a better option, but the hacker in me wants any excuse to setup a relay and a cron job. :) --Dave /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
Dave Smith wrote: That may indeed be a better option, but the hacker in me wants any excuse to setup a relay and a cron job. :) Amen. Shane /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
On Tue, Feb 23, 2010 at 09:04:18AM -0700, Dave Smith wrote: Has anyone gotten a USB device that requires Virtual COM Port support to work in Linux? I'm considering employing this relay[1] to perform a nightly reboot of my pile-of-junk Comcast cable modem. It looks like it uses the FTDI chip so it should work fine with any 2.6.x kernel. -- Byron Clark /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
Shane Hathaway wrote: Assuming the serial controller on that board is supported by Linux, when you plug in the device to a computer running a recent distribution, you'll get a device called /dev/ttyUSB0, which you can use like an ordinary serial port. So I could use minicom to control it? Could I just echo strings into it as well? I would love to write a bash script as simple as this: reboot-cable-modem.sh: #!/bin/bash echo 0 /dev/ttyUSB0 sleep 5 echo 1 /dev/ttyUSB0 Do you think it would be that simple? --Dave /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
Byron Clark wrote: It looks like it uses the FTDI chip so it should work fine with any 2.6.x kernel. Byron, that's why you make the big bucks. Yeah baby! I just ordered one -- can't wait to start playing with it. --Dave /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
Re: Virtual COM port on Linux
On Tue, 2010-02-23 at 09:04 -0700, Dave Smith wrote: Has anyone gotten a USB device that requires Virtual COM Port support to work in Linux? I don't know if this works the same way as what you're looking at, but I've got one of these and it works perfectly right out of the box: http://www.amazon.com/Keyspan-Speed-Serial-Adapter-USA-19HS/dp/BVYJRY /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */