title: Newbie perl serial programming
body: <p>I have a RFXCOM transceiver for 433 mhz signals. I managed to put together a program that can transmit signals without a problem (and for example turn on a lamp). However I also want to be able to receive signals from my remote control. A bit of googling gave me this working code;</p>
  
  <pre><code>use Device::SerialPort;
   my $PortObj=Device::SerialPort-&gt;new("/dev/ttyUSB1");
  
    $PortObj-&gt;user_msg(ON);
    $PortObj-&gt;databits(8);
    $PortObj-&gt;baudrate(38400);
    $PortObj-&gt;parity("none");
    $PortObj-&gt;stopbits(1);
    $PortObj-&gt;handshake("rts");
  
  
   my $STALL_DEFAULT=10; # how many seconds to wait for new input
  
   my $timeout=$STALL_DEFAULT;
  
   $PortObj-&gt;read_char_time(0);     # don't wait for each character
   $PortObj-&gt;read_const_time(1000); # 1 second per unfulfilled "read" call
  
   my $chars=0;
   my $buffer="";
   while ($timeout&gt;0) {
          my ($count,$saw)=$PortObj-&gt;read(1); # will read _up to_ 255 chars
          if ($count &gt; 0) {
                  $chars+=$count;
                  $buffer.=$saw;
  print $saw; 
                  # Check here to see if what we want is in the $buffer
                  # say "last" if we find it
          }
          else {
                  $timeout--;
          }
   }
  
   if ($timeout==0) {
          die "Waited $STALL_DEFAULT seconds and never saw what I wanted\n";
   }
  </code></pre>
  
  <p>One thing I can't figure out - this script gives me the output after about 10 seconds, but I want to see the received data instantly. Any idea what I need to change? I don't think it has to do with the timeout part since that just seems to measure the time since the last received signal. Any ideas?</p>