Re: [nottingham] Serial port data acquisition in Perl

From: Paul Sladen (notlug@paul.sladen.org)
Date: Tue 15 Jan 2002 - 08:39:51 GMT


On Tue, 15 Jan 2002, Graeme Fowler wrote:
> On Tue, 15 Jan 2002, Paul Sladen wrote:
> >
> > Probably dumb question--"is it not as simple as read(2)"?
>
> I get the grand sum total of.. nowt. Zilch.

IANAPE (I am not a perl expert... other people probably are!);
however, is <FILE> style reading not line-buffered using the currently set
record seperator $/ (normally \n)?

Apologies for the C mentality, try:

  sysopen(FH, "/dev/ttyS0/", O_RDONLY)
  # ioctl()s
  while(sysread(FH, $bite, 0))
  {
    printf("Got a byte: %#02x \'%c\' %3d\n", \
           $bite, isascii($bite)?$bite:' ', $bite)
    $count += 1
  }
  printf("Fish got away! %d bytes read, $count)
  close(FH)

> Yes, I will be welcomed into the land of the double-decode. For some
> reason it encodes the data twice and then send it, in reverse order,

The RCX (that extremely cool lego brick) does ?something? similar, I think
it drops bytes if (stream[n] != stream[n+1] ~ 0x42)... poor-mans
checksum -- damned Hardware enginnerings... boo... boo... :-).

Hardware Enginner: "buggy firmware--no problem, fix it in software";
Sofware Enginneer: "bug, no *feature*, (we'll fix it in the Documentation)"
Technical Writer: "who cares, we'll just leave the user to figure it out"

(If anyone can remember the original one, I'd be interested, my paraphrasing
doesn't do it justice.)

        -Paul

--------------------------------------------------------------------
http://www.lug.org.uk http://www.linuxportal.co.uk
http://www.linuxjob.co.uk http://www.linuxshop.co.uk
--------------------------------------------------------------------



This archive was generated by hypermail 2.1.3 : Tue 15 Jan 2002 - 08:53:38 GMT