Hi leute, hi Alex,
So viel ge-googled hab ich noch nie - ich hab’s mit PHP hinbekommen.
Der Fehler war, dass ich nicht ALLE Einstellmöglichkeiten konsequent ein- bzw ausgeschalten habe.
Dh.
root@raspberry:~# stty -F /dev/ttyACM0 -hupcl
root@raspberry:~# stty -F /dev/ttyACM0 ignpar
root@raspberry:~# stty -F /dev/ttyACM0 -opost
root@raspberry:~# stty -F /dev/ttyACM0 -onlcr
root@raspberry:~# stty -F /dev/ttyACM0 -isig
root@raspberry:~# stty -F /dev/ttyACM0 -icanon
root@raspberry:~# stty -F /dev/ttyACM0 -iexten
root@raspberry:~# stty -F /dev/ttyACM0 -echo
root@raspberry:~# stty -F /dev/ttyACM0 -echoe
root@raspberry:~# stty -F /dev/ttyACM0 -echok
root@raspberry:~# stty -F /dev/ttyACM0 –echoctl
Alleine 9600 .. 115200 8N1 als Einstellung reicht nicht aus. (zumindest beim HB628), sonst hat man keine pure IO (Bytes hin, Bytes zurück).
Eine Aufstellung aller Einstellungen unter: Einstellungen
Jetzt hab ich:
root@raspberry:~# stty -a < /dev/ttyACM0
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>;
swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V;
flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl cstopb cread clocal -crtscts
-ignbrk -brkint ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -ixon -ixoff -iuclc -ixany
-imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt -echoctl echoke
Als praktisches Modul hab ich die
php_serial.class.php gefunden. Ohne dem, dass extra so was geschrieben wurde, hätte ich auch nicht mehr geglaubt, das es unter php geht.
Mein funktionierendes Prog:
<?php
require "php_serial.class.php";
echo "start\n";
// function zum umwandeln des strings in werte
function strToHex($string)
{
$hex='';
for ($i=0; $i < strlen($string); $i++)
{
$hex .= dechex(ord($string[$i])) . "\n"; // n zum bessern zählen der bytes
}
return $hex;
}
// Let's start the class
$serial = new phpSerial;
// First we must specify the device. This works on both linux and windows (if
// your linux serial device is /dev/ttyS0 for COM1, etc)
$serial->deviceSet("/dev/ttyACM0");
// We can change the baud rate, parity, length, stop bits, flow control
// ?? ob es nach der Einstellung mit stty noch nötig ist, weiß ich nicht ??
$serial->confBaudRate(9600); //Baud rate: 9600
$serial->confParity("none"); //Parity (this is the "N" in "8-N-1")
$serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1")
$serial->confStopBits(1); //Stop bits (this is the "1" in "8-N-1")
// Then we need to open it
$serial->deviceOpen();
// To write into
$serial->sendMessage("c09"); // c09 – alle 8 analogen Eingänge abfragen
// Or to read from
$read = $serial->readPort();
echo $read . "\n";
$data = strToHex($read) ;
echo $data . "\n";
// If you want to change the configuration, the device must be closed
$serial->deviceClose();
?>
root@raspberry:~# php /myprogs/class_ser.php
start
Á{@{[]Ñ
2
c1
2
7b
2
40
2
7b
1
8f
2
5b
1
86
1
5d
d1
17 Bytes sind korrekt ;-)
Alex – ich konnte mich mal wieder davor drücken, was neues zu lernen ;-). Ich Danke Dir für das Aufzeigen der Alternativen – hätte es doch nicht mit php geklappt.
PS die dio Befehle funktionieren nur unter Windows – Lustig, dass es mal andersrum ist.
Viele Grüße aus LA
ralphi