• uspp
Réponses:
2
Visites:
0
Up one level
Vous devez être un membre enregistré pour contribuer sur ce forum.
Inscrivez-vous maintenant
• uspp
Posté par
vavincavent
le
25/08/2008 23:16
Bonjour,
Je souhaite utiliser uspp pour lire les données provenant d'un ordinateur de plongée, via la liaison série rs232. Je débute en python et j'ai pour l'instant réussit à faire ça : vincent@vincent-laptop:~$ python Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from uspp import * >>> tty=SerialPort("/dev/ttyUSB0",None,19200) >>> tty.read() '\x00' >>> tty.read() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/var/lib/python-support/python2.5/SerialPort_linux.py", line 222, in read s=s+SerialPort.__read1(self) File "/var/lib/python-support/python2.5/SerialPort_linux.py", line 207, in __read1 byte = os.read(self.__handle, 1) KeyboardInterrupt >>> Je connais le protocol de l'aladin, il me faut lire 2050 bytes à partir de UUU\0. Comment puis-je écrire celà? Cordialement, |
• Re: uspp
Posté par
yorukaze
le
26/08/2008 14:32
Es-ce que tu pourrais développer un peu ta problématique?
Qu'est ce que tu veux lire? Au vu de la doc (http://ibarona.googlepages.com/uspp) je ne sais pas si c'est encore maintenu. Tu t'es renseigé sur pyserial? http://pyserial.wiki.sourceforge.net/pySerial |
• Re: uspp
Posté par
vavincavent
le
26/08/2008 18:39
uspp ou pyserial, peu importe du moment que celà fonctionne!!
Le programme python sera en attente de réception. Une manipulation sur l'ordinateur de plongée permet d'envoyer les données (2050 bytes commençant par la chaine UUU\0). 19200 baud, 8bit, No parity and 1 stopbit. voici la séquence qui réalise celà en perl : code: sub receive { sub readaladin { my($i); ### CONFIGURE: Please select either of following -- ### (1) # require 'ioctl-types.ph'; ### Note: In order to include ioctl-types.ph, some Linux system requires to do ### (cd /usr/include && h2ph *.h sys/*.h asm/*.h) ### (2) require 'sys/ioctl.ph'; ### End CONFIGURE. use POSIX; $tio = POSIX::Termios->new; $tio->setiflag(0); $tio->setoflag(0); $tio->setlflag(0); $tio->setcflag(CS8|CLOCAL|CREAD); $tio->setispeed(B19200); $tio->setcc(VMIN, 1); $tio->setcc(VTIME, 0); $tio->setattr(fileno(ALADIN), TCSANOW); ioctl(ALADIN, &TIOCMBIC, pack('i', &TIOCM_RTS)); for ($i = 0; $i < 3 ; $i++) { sysread(ALADIN, $buf, 1); if (unpack('C', $buf) != ord('U')) { $i = -1; } } sysread(ALADIN, $buf, 1); if (unpack('C', $buf) != 0) { return -1; } for ($i = 0; $i < 2046; $i++) { sysread(ALADIN, $buf, 1, $i); } @buf = unpack('C2046', $buf); # The following is for compatibility with data # received by the older version of this script. $buf[2047] = 0; $buf[2046] = 255; # end for ($i = 0; $i < 2046; $i++) { $d = 0; $e = $buf[$i]; for ($j = 0; $j < 8; $j++) { $d <<= 1; $d |= $e & 1; $e >>= 1; } $buf[$i] = $d; } $buf = pack('C2048', @buf); $checksum = unpack('%16C2044', $buf); $checksum += 0x01fe; $checksum %= 65536; $CHECKSUM = unpack('v', substr($buf, 2044, 2)); if ($CHECKSUM != $checksum) { print STDERR "Checksum error\n"; return -1; } return 0; } open(ALADIN, "<$Device"); while (readaladin()) { print STDERR "Read error. Please retry.\n"; } close(ALADIN); unless (! -f $Info or substr($MACHINEID, 49, 3) eq substr($buf, 0x7ed, 3)) { print STDERR "panic: data from a different Aladin!\n"; return; } open(LS, "ls -1 |"); @ls = <LS>; close(LS); ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(); $file = sprintf "%02d%02d%02d", $year % 100, $mon+1, $mday; @ls = grep(/^$file[0-9][0-9][0-9]\n$/, @ls); if (@ls) { @ls = sort numerically @ls; $ls[$#ls] =~ /^$file([0-9][0-9][0-9])\n$/; $file .= sprintf "%03d", $1 + 1; } else { $file .= '000'; } open(WRITE, ">$file"); print WRITE $buf; close(WRITE); $u = substr($buf, 1980, 1); $u = unpack('C', $u); if ($u == 0xa4) { $Nitrox = 3; } if ($u == 0xf4 || $u == 0xff) { $Nitrox = 2; } if ($u == 0x1c) { $NormalAir = 1; } open(INFO, ">$Info"); print INFO substr($buf, 1980, 52); $t = substr($buf, 2040, 4); print INFO $t; print INFO pack('N', time()); $TIMECORR = time() - (unpack('N', $t) >> 1); close(INFO); $MACHINEID = substr($buf, 1980, 52); } |






