Ok, so I was thinking about this business with the byte number being wrong.
I wondered what would happen if I did not set the Baud, and lo, the same behavior occurred. If I set the baud at some high number, it will just give zeros, as expected.
It should be setting the baud though. I have it set to let me know if there were problems.
FYI, here is the code.
use warnings; use strict; use Win32::FTDI::FTD2XX qw(:DEFAULT FT_BAUD_2400 FT_BITS_8 FT_STOP_BITS_1 FT_PARITY_NONE FT_FLOW_RTS_CTS PFT_MODEM_STATUS_CTS ); my $FTD = Win32::FTDI::FTD2XX->new(); unless( $FTD->PFT_STATUS() == FT_OK ) { printf( STDERR "FTD2XX::new() failed: %s (%s)\n", $FTD->PFT_STATUS_MSG(), $FTD->PFT_ERROR() ); exit( 1 ); } printf( "FTD2XX::new() allocated PFT_HANDLE: %d\n", $FTD->PFT_HANDLE +() ); my $numDevices = $FTD->GetNumDevices(); unless( $FTD->PFT_STATUS() == FT_OK ) { printf( STDERR "FTD2XX::GetNumDevices() failed: %s (%s)\n", $FTD->PFT_STATUS_MSG(), $FTD->PFT_ERROR() ); exit( 1 ); } printf( "Found $numDevices FTDI devices connected!\n" ); $FTD->PFT_DEBUG(1); unless ($FTD->OpenByIndex(0)) { print "Problem opening Port 0\n"; return 0; } unless ($FTD->Purge(FT_PURGE_RX)) { print 'cannot purge'; } unless ($FTD->SetBaudRate(FT_BAUD_2400)) { print "Baud is set\n"; return 0; } peek_buf(); sub split_len { my ($len, $string) = @_; $string =~ m/.{1,$len}/g; } sub peek_buf { my ($amountInRxQueue, $amountInTxQueue, $eventStatus) = $FTD->GetS +tatus(); print "trying to read $amountInRxQueue\n"; while ( $amountInRxQueue< 45) { ($amountInRxQueue, $amountInTxQueue, $eventStatus) = $FTD->Get +Status(); print "$amountInRxQueue in q\n"; sleep(1); } my ($bytesReturned, $readBuffer) = $FTD->Read($amountInRxQueue); my $numHex = $bytesReturned*2; my $upack = unpack("H$numHex", $readBuffer); my @a = split_len(18, $upack); print join "\n", @a,"\n"; }

In reply to Re^7: Win32::SerialPort ; close / open problem by philipMac
in thread Win32::SerialPort ; close / open problem by philipMac

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.