crazysarik has asked for the wisdom of the Perl Monks concerning the following question:

Good Evening Monks, I have a X-bee module connected to one of the usb port and is receiving Hex data continuously.

I want to write these data into a file continuously?

How can I do this?

Replies are listed 'Best First'.
Re: Reading serial port data into a file
by roboticus (Chancellor) on Jun 04, 2013 at 10:28 UTC

    crazysarik:

    I'd try something like this:

    open my $FH, '>', 'results' or die $!; while (my $bytes = xbee_get_bytes()) { print $FH $bytes; }

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Reading serial port data into a file
by jmlynesjr (Deacon) on Jun 04, 2013 at 20:57 UTC

    Look at Device::SerialPort, Device::SerialPort::Arduino, or Win32::SerialPort if on windows.

    James

    There's never enough time to do it right, but always enough time to do it over...

      Look at Device::SerialPort, Device::SerialPort::Arduino, or Win32::SerialPort if on windows.

      :) serialport isn't usb , are you sure about that?

        Yes. Have used Device::SerialPort::Arduino to read data coming from the USB interface on the chipKIT UNO PIC based Arduino clone. The chipKIT UNO uses the FTDI FT232R USB serial converter chip and FTDI FT232R drivers are available on my Unbuntu 10.10 laptop. This is a pretty commonly used USB support chip.

        # Perl Polling Test # Title: Perl to chipKIT Serial Poll Test # Author: James M. Lynes, Jr. # Version: 1.0 # Creation Date: June 10, 2012 # Modification Date: June 10, 2012 use strict; use warnings; # Initialize the serial port - creates the serial port object $Arduino use Device::SerialPort::Arduino; my $Arduino = Device::SerialPort::Arduino->new( port => '/dev/ttyUSB0', baudrate => 9600, databits => 8, parity => 'none', ); while(1) { $Arduino->communicate('P'); # Send a poll print ($Arduino->receive(), "\n"); # Print poll respons +e sleep(1); # Delay until next p +oll }

        James

        There's never enough time to do it right, but always enough time to do it over...