On 08.01.2011 17:32, Thorsten Godau wrote:

> So i tried to use "slcan_attach -o -s6 -c /dev/ttyUSB0"  ...

(..)

> so the correct command should be "slcan_attach -c -s6 -o /dev/ttyUSB0".

(..)

> Nevertheless i can't get the bitrate changed properly with slcan_attach.
> The solution was the echo command (to be honest i tried to change the
> CAN bitrate before determining the working serial parameters):
> 
> echo -e -n "C\rS6\rO\r" > /dev/ttyUSB0

Hi Thorsten,

thanks for your extensive investigation on this topic!

Currently the slcan_attach only uses the commandline options as boolean
switches to send "O\r", "C\r", "S?\r" and "s????\r" in this order:

    S? -> s???? -> O -> (attach tty) -> (wait) -> (detach tty) -> C

And this works fine in the case the slcan adapter is in 'close' state at the
start of slcan_attach.

So the _order_ of the commandline has no effect on the behaviour as you tried
in the two examples in the beginning of this mail.

To fix this behaviour, i would suggest to force a close of the slcan adapter
before setting the bitrate (which is also common for other CAN
adapters/controllers). E.g. by sending

    "C\rS?\r" instead of only "S?\r"

Then we would have this possible init sequence of slcan_attach:

    CS? -> Cs???? -> O -> (attach tty) -> (wait) -> (detach tty) -> C

Can you try this (also attached) patch to check whether a 'close' before
setting the bitrate brings back the wanted functionality?

Index: slcan_attach.c
===================================================================
--- slcan_attach.c      (Revision 1227)
+++ slcan_attach.c      (Arbeitskopie)
@@ -150,12 +150,12 @@
        if (waitkey || !detach) {

                if (speed) {
-                       sprintf(buf, "S%s\r", speed);
+                       sprintf(buf, "C\rS%s\r", speed);
                        write(fd, buf, strlen(buf));
                }

                if (btr) {
-                       sprintf(buf, "s%s\r", btr);
+                       sprintf(buf, "C\rs%s\r", btr);
                        write(fd, buf, strlen(buf));
                }



Finally your approach with the

    echo -e -n "C\rS6\rO\r" > /dev/ttyUSB0

command looks also very good as it uses the standard unix idea to have simple
and clearly arranged tools for each use-case :-)

Btw. when slcan_attach provides some functionality on the commandline, it
should JUST WORK like expected ;-)

73!

Oliver (DK4AM)
Index: slcan_attach.c
===================================================================
--- slcan_attach.c	(Revision 1227)
+++ slcan_attach.c	(Arbeitskopie)
@@ -150,12 +150,12 @@
 	if (waitkey || !detach) {
 
 		if (speed) {
-			sprintf(buf, "S%s\r", speed);
+			sprintf(buf, "C\rS%s\r", speed);
 			write(fd, buf, strlen(buf));
 		}
 
 		if (btr) {
-			sprintf(buf, "s%s\r", btr);
+			sprintf(buf, "C\rs%s\r", btr);
 			write(fd, buf, strlen(buf));
 		}
 
_______________________________________________
Socketcan-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/socketcan-users

Reply via email to