Hi All.
I’ve scoured the Internet for a solution to this but can’t find anything.
I have one of these, https://www.kmtronic.com/usb-relays.html/usb-relay-controller-one-channel-pcb.html, and am trying to get it to report its status, open or closed.
The funny thing is that it works with CuteCom but not when I try to operate it via the command line. It will switch on and off, in response to echo -e "\xff\x01\x01" > /dev/ttyUSB0 and echo -e "\xff\x01\x00" > /dev/ttyUSB0, respectively. But, when I send it echo -e "\xff\x01\x03" > /dev/ttyUSB0 which is supposed to cause it to return its status, i.e. different byte sequences for off or on, it doesn’t. Or, more accurately, the second terminal that I have running in the background with cat -v /dev/ttyUSB0 doesn’t show anything.
As I say, it does work with CuteCom but I need a non graphical solution as I am running it on a Raspberry Pi via SSH. Also, it seems to be transmitting in response to the status request, echo -e "\xff\x01\x03" > /dev/ttyUSB0, because the “RX” LED on the board flickers, which it only does in response to this command, but my terminal just isn’t seeing it (the byte sequence returned doesn’t map to ASCII but I should be getting some garbage at least).
Also, the manufacturer has a shell script on their website, “usbrelaystatus.sh” at https://info.kmtronic.com/kmtronic-usb-one-relay-linux-test-script.html, which is basically doing the same thing except, rather than a second terminal, it has a background process running cat, sending the output to a temporary file which it then reads but that isn’t working either, the file is coming back empty.
I have noticed that, when CuteCom is running, if I try to send a command to the device via the terminal then it throws an error “bash: /dev/ttyUSB0: Device or resource busy”. In contrast, it won’t throw that error while I’m running the C program that I wrote to try to grab the response.
The device is a couple of years old (ironically, I bought it because I thought that RS232 would be easier to work with than HID) so presumably it worked then. It is doing it, or rather not doing it, on both my Ubuntu laptop and my Raspbian RPi so I’m wondering whether it’s been caused by a kernel update.
Any ideas?
--
You received this message because you are subscribed to the Google Groups "London Hackspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to london-hack-sp...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/london-hack-space/97c637eb-7070-4c45-9d59-c8507ae6b541%40googlegroups.com.
--
Super thanks to Adrian!
His PM prompted me to check that the port was set to ‘raw’.
Being a bit shaky on the foundations of Unix/Linux (I am currently working my way through The Design of the Unix Operating System by Bach) I Googled it and found https://acassis.wordpress.com/2016/01/22/configuring-linuxs-serial-port-to-raw-mode/
I followed the steps given there to set up my second, monitor, terminal as follows:
$ sudo stty -F /dev/ttyUSB0 raw
$ sudo stty -F /dev/ttyUSB0 -echo -echoe -echok
$ sudo stty -F /dev/ttyUSB0 9600
$ cat /dev/ttyUSB0 | hexdump -v -e '/1 "%02X "' -e '/1 "%c\n"'
...and it works!
I only really want to be able to check the status for debugging so I’ll work up a shell script based on this.
To unsubscribe from this group and stop receiving emails from it, send an email to london-h...@googlegroups.com.