Setting DTR high, RTS low using Linux bash? - stty

I have a serial device that has no flow control, but is powered from the RS232 port by holding the RTS high and DTR low
I was hoping to read from this device using a simple bash script, but can't find any way to set the handshaking lines, using stty or otherwise, to allow for the above configuration.
Any ideas if this is possible?

I don't have an answer about setting RTS without touching DTR, because I don't have any DTR pin on my dongle; but, trying to set RTS was already very tricky un pure shell.
You may need to play with stty crtscts and clocal flags.
I have published a detailed answer here:
https://forums.gentoo.org/viewtopic-p-8132756.html#8132756
Here is the short version:
#!/bin/bash
MySerialPort="/dev/ttyUSB0"
MyLatency="2"
echo "#include <fcntl.h>
#include <sys/ioctl.h>
main()
{ int fd; fd = open(\"${MySerialPort}\",O_RDWR | O_NOCTTY );
int RTS_flag; RTS_flag = TIOCM_RTS;
ioctl(fd,TIOCMBIS,&RTS_flag);
sleep (${MyLatency});
ioctl(fd,TIOCMBIC,&RTS_flag);
close(fd); } " | tcc -run -
Note that sending data on TX will probably mess RTS; see the Gentoo forum for details.

I've been trying something similar here.
I used the ioctls. Then measured with a multimeter.
this is what I found:
dsrv=TIOCM_DTR;//this sets RTS to -11.7?
dsrv=TIOCM_RTS;//sets DTR -11.7
ioctl(fd, TIOCMBIS, &dsrv);
dsrv=TIOCM_DTR;//this sets RTS to 11.7?
dsrv=TIOCM_RTS;//sets DTR 11.7
ioctl(fd, TIOCMBIC, &dsrv);
It is somewhat weird...

socat controls DTR when hucpcl=1
(Atmel EDBG USB Serial needs DTR high)
sleep 1; while true; do echo -en "\x01\x02"; sleep 0.1; done | socat -T1 -t1 - /dev/ttyUSB0,hupcl=1,raw,b1000000,cs8,echo=0
man socat - may be find more solutions for your serial problem.

Related

Multiple channels in a single SSH session

I am debugging OpenSSH code where it seems multiple channels have been allocated on single SSH session (single connected child server).
My queries could be naive here:
Under what conditions can multiple channels be opened?
What are the SSH message flows which lead to multiple channels? A message flow chart will be very helpful.
Is it correct to free channels[0] in the case below?
(gdb) p channels[0]
$1 = (Channel *) 0xb0f33e20
(gdb) p channels[0]->rfd
$2 = 0xd
(gdb) p channels[0]->efd
$3 = 0xffffffff
(gdb) p channels[0]->wfd
$4 = 0xffffffff
(gdb) p channels[1]->wfd
$5 = 0x9
(gdb) p channels[1]->efd
$6 = 0xffffffff
(gdb) p channels[1]->rfd
$7 = 0x9
Under what conditions can multiple channels be opened?
Every channel is either X11 forwarding, TCP port forwarding (there might be more types), UNIX domain socket forwarding (or ssh-agent socket) or MUX proxy. Consulting source code describing the types is a good start. They are opened, if the client requests them using command-line options (-X, -L, -R, -D, -A, ...) which are described in the manual page for ssh.
What are the SSH message flows which lead to multiple channels? A message flow chart will be very helpful.
If you will run the OpenSSH client and/or server in debug mode (LogLevel DEBUG3), you will get a lot of useful information what messages are being exchanged for various use cases.
Is it correct to free channels[0] in the case below?
Most probably not, but it is not clear what you ask here and what is the context. That is obviously valid channel with read file descriptor pointing to FD 0x0D so you might expect there will be something to read at some point.

Reading value from TAR register in MSP430

How should i go about reading value from TAR register in msp430. I wnat to see the values, like we have serial monitor to do so in Arduino. I know we do not have anything like that in msp(except energia of course).I am coding in CCS 5.5.0.
The registers for the MSP430 processors are defined in standard headers and can then just be accessed as variables, they are just memory locations after all. There is a gotcha with the TAR and TBR registers in that they can sometimes return an intermediate value if they are in the process of being updated as a clock count increments the register contents so I have always used the following code to guard against this problem.
uint16_t Timer_Value ;
Timer_Value = TAR ;
while ( Timer_Value != TAR )
{
Timer_Value = TAR ;
}

In Bluez A2DP: how can I modify the default audio sample rate

I am using Bluez4 to sink Audio from an iphone 5 to a Raspberry pi audio output.
The default settings for BLuez 4 A2DP appear to be S16_LE, 44,1kHz Stereo.
Similar to other posts about Bluez, I can't catch Select_Configuration DBus messages in order to change the sample rate dynamically. Instead I decided to try to find the default A2DP sample rate in the BLuez Stack.
Does anyone know where the default sample rate is set? My first thought was that it was in the BLuez/audio/ folder but nothing appears to change the default 44.1kHz sample rate.
Now I'm very curious to know where it is set.
Currently using this: sudo ./a2dp-alsa --sink | aplay -c 2 -r 44100 -f S16
would like to use this sudo ./a2dp-alsa --sink | aplay -c 2 -r 16000 -f S16
I came across these lines in a2dp-alsa.c
/* Initialise connection to ALSA */
g_handle = audio_init("hw:0,0", 48000);
maybe its hard coded in a2dp-alsa - not parameterizable

Turning off a single usb device... again

I know that this topic has been discussed many times, but none of the answers helped me. For the record, i'm running Debian.
The deal is: I bought an usb powered led lamp, which is very simple and doesn't even have an on/off switch (it works and is always on). I want to be able to turn it on/off via command line. Here's what i tried:
echo on > /sys/bus/usb/devices/usb1/power/level # turn on
echo suspend > /sys/bus/usb/devices/usb1/power/level # turn off
which is what i've found on many forums. Turning "on" works, but "suspending" yields
-su: echo: write error: Invalid argument
for every usbN. I also tried
echo "0" > "/sys/bus/usb/devices/usbX/power/autosuspend_delay_ms"
which doesn't give an error, but also doesn't do anything (again, for every usbN)
trying
echo "usb1" > /sys/bus/usb/drivers/usb/unbind
works only for more "inteligent" devices, like the keyboard, the mouse, or the usb wifi card. What i mean is that only tyhose devices are turned off, other usbN don't give an error, but the lamp never goes off.
the contents of /sys/bus/usb/devices/ are
1-0:1.0 1-1:1.0 1-2:1.0 1-2:1.2 2-0:1.0 4-0:1.0 4-1:1.0 6-0:1.0 8-0:1.0 8-2:1.0 usb2 usb4 usb6 usb8
1-1 1-2 1-2:1.1 1-2:1.3 3-0:1.0 4-1 5-0:1.0 7-0:1.0 8-2 usb1 usb3 usb5 usb7
i tried to do
echo device_name > /sys/bus/usb/drivers/usb/unbind
with every single one of them, but only the devices usbN and N-M react, the ones of the form n-m:x.y yield
tee: /sys/bus/usb/drivers/usb/bind: No such device
(i tried putting in, for instance, "1-0:1.0", "1-0\:1.0" and "1-0\:1.0", all gave the same result).
One last thing, what is shown after executing
lsusb -t
does not change when i plug or unplug the lamp.
Any ideas?
Turn off device ID 2-1:
echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/unbind
Turn device ID 2-1 back on:
echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/bind
In my case, using device ID 2-1 controls power to my usb stick, and as a consequence controls the light.
TIP: If they work for you in Debian, create an alias for them to make life easier for you later.
Hope this helps,
Su
If all you want to do is reset a USB device to fix it once it gets into a broken state, then using the bind/unbind usbfs special files can be a bit of a pain (since device IDs can change, and they're a bit tricky to identify precisely if you don't want to rebind other devices). In this case I've found it much easier to use the vendor and product IDs given by lsusb with usb_modeswitch. For example, if I identify my wireless adapter using:
$ lsusb
Bus 001 Device 042: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]
Bus 001 Device 035: ID 0409:005a NEC Corp. HighSpeed Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
I can then reset the wireless adapter using:
$ sudo usb_modeswitch -v 0x7392 -p 0x7811 --reset-usb
If you have more than one device attached with the same vendor and product IDs then usb_modeswitch provides bus and device number flags. For the wireless adapter example above I'd add -b 1 -g 42 to the flags.
Try this code it works for me (Only for rooted)
String[] cmdline = { "su", "-c", "echo '1-1' >/sys/bus/usb/drivers/usb/unbind" };
try {
Runtime.getRuntime().exec(cmdline);
} catch (IOException e) {
Log.e("MainActivity","Failed"+e);
}
and for bind again do this
String[] cmdline = { "su", "-c", "echo '1-1' >/sys/bus/usb/drivers/usb/bind" };
try {
Runtime.getRuntime().exec(cmdline);
} catch (IOException e) {
Log.e("MainActivity","Failed"+e);
}

remove usb node

My aim is to disable usb port usage except a specific kind of usb. Every time a usb device is inserted a udev rule is called and it runs a program to handle the work.
I can't unload usb_storage module since it is needed for usage, so how can i remove usb dev link if it doesn't meet my case?
unbind the device. Pass vendor id and product id to below script.
VENDOR=$1
PRODUCT=$2
if [ n$VENDOR = n ] || [ n$PRODUCT = n ]; then
echo "Unbinding the first non-hub device..."
ID=`grep -l "^0$" /sys/bus/usb/drivers/usb/*/maxchild | sed -e "s|/sys/bus/usb/drivers/usb/\(.*\)/maxchild|\1|" | head -n 1`
VENDOR=`cat /sys/bus/usb/drivers/usb/$ID/idVendor`
PRODUCT=`cat /sys/bus/usb/drivers/usb/$ID/idProduct`
echo $ID > /sys/bus/usb/drivers/usb/unbind
echo "Device found ($VENDOR:$PRODUCT), and unbound!"
exit 0
fi
Regards,
Barun Parichha