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

Hi I am trying to do the following: 1. Access a serial port say COM1 2. Do some processing (eg download a file) 3. While I am doing step 2 i need to monitor to monitor serial port for any errors. The only way i can think of is starting a process that read the serial port Is there any other way to do this? Is there a option in Win32-SerialPort to tell it to log the serial port output to a file . Any help appreciated
  • Comment on Windows Serial Port Logging using Win32-SerialPort

Replies are listed 'Best First'.
Re: Windows Serial Port Logging using Win32-SerialPort
by Anonymous Monk on Apr 16, 2010 at 17:27 UTC
    You could use a select loop, or an event pacakge with a select loop at its heart (POE or something else compatible with AnyEvent, like a single Win32::GUI or other toolkit thread) without breaking out into processes or threads yourself.
      Hi Thanks. This is all new to me I will go read on that but do you know of any example which tells me how to use this
Re: Windows Serial Port Logging using Win32-SerialPort
by BrowserUk (Patriarch) on Apr 18, 2010 at 00:39 UTC

    A couple of questions:

    1. 2. Do some processing (eg download a file)

      Do you mean download a file via the serial port?

    2. need to monitor serial port for any errors

      What kind of errors? Monitor how?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Here is a pseudo code 1. I have a main script that does the following: - Do a serial port write - Start a FTP download using Net:FTP 2. Now while the main script is doing this FTP , the device that the perl script is talking to is writing something to the serial port 3. After the FTP is done I want to go check if the serial port output was clean. 4. I am using Win32-SerialPort to access serial port.I was hoping it would have a option to write serial port output to a log file but i haven't found one yet. Thanks for your help

        Something like this might do you. Essentially everything inside the async will happen concurrently with everything after it until you join the threads back together.

        use threads; use threads::shared; use Win32::SerialPort; use Net::FTP; my $sp = new Wi3n32::SerialPort( ... ); ... my $count = $sp-write( $out ); my $done :shared = 0; my $t = async{ my $in; until( $done ) { my( $count, $byte ) = $sp->read( 1 ); warn "Read error" and next unless $count = 1; $in .= $byte; } return $in; }; my $ftp = new Net::FTP( ... ); $ftp->get( 'theFile' ); $ftp->done; $done = 1; my $input = $t->join;

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.