in reply to Re^6: Win32::SerialPort ; close / open problem
in thread Win32::SerialPort ; close / open problem
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Win32::SerialPort ; close / open problem
by philipMac (Novice) on Aug 10, 2009 at 19:06 UTC |