Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^3: Problem Writing to FTDI COM Port using Win32::FTDI::FTD2XX

by kschwab (Priest)
on Jan 16, 2014 at 04:26 UTC ( #1070757=note: print w/replies, xml ) Need Help??

in reply to Re^2: Problem Writing to FTDI COM Port using Win32::FTDI::FTD2XX
in thread Problem Writing to FTDI COM Port using Win32::FTDI::FTD2XX

Here's the source:
sub SetBitMode { my $self = shift; my $mask = shift; my $mode = shift; unless( defined( $self->{_PFT_SetBitMode} ) ) { return( undef ) unless( _importDll( $self, "PFT_SetBitMode" ) ); } $self->{_PFT_STATUS} = $self->{_PFT_SetBitMode}->Call( $self->{_PFT_ +HANDLE}, $mask, $mode ); return( 0 ) if( $self->{_PFT_STATUS} ); return( 1 ); } # SetBitMode()
It wants a mode and a mask, and if you're passing in the ID, it's interpreting that as the mask. Unless you've got an older version or something, passing in the ID may supress some error, but it's not likely doing the right thing.

Replies are listed 'Best First'.
Re^4: Problem Writing to FTDI COM Port using Win32::FTDI::FTD2XX
by PrfrrdUsrNm (Initiate) on Jan 16, 2014 at 06:06 UTC

    My thinking, after not having success with the CPAN definition, was to follow D2XX Programmer's Guide Version 1.3 definition and see if that worked (obviously it didn't and remained in the code, sorry about that).

    The definition in CPAN:

    SetBitMode Parameters: {$mode} Return Success: TRUE Return Failure: FALSE Purpose: API Method - See FT_SetBitMode(). Note: The following EXPORTS for BitModes are available for convenien +ce: PFT_BITMODE_RESET PFT_BITMODE_ASYNCBB PFT_BITMODE_MPSSE PFT_BITMODE_SYNCBB PFT_BITMODE_MHBEM PFT_BITMODE_FOISM PFT_BITMODE_CBUSBB

    Only asks for the $mode parameter, although I have tried this as:

    my $mode = FTDIdev->SetBitMode(0x03, 0x01); #also tried in dec with 3, + 1 print "My mode is: $mode\n";

    This changes the printed $mode to 244 (0xF4) (as opposed to 245 (0xF5), which may indicate we have eliminated one error...). But again the program gets stuck at the write stage.

    Thinking about it, how are the two outputs (two DB9 com ports) represented on the one chip? is this done with the mask? which would make require more than two bytes for masking the full 18 pins...

    This would imply that 0x03 is trying to mask/write from the port belonging to ComPort6...

      <quote>Thinking about it, how are the two outputs (two DB9 com ports) represented on the one chip?</quote> It's an object, so it can keep the "previously selected output" in the internal state of the object. So, you do a OpenBySerial or OpenByIndex, and the calls to methods like SetBitMode operate on the port that was last opened. The docs for the perl module seem wrong with respect to SetBitMode. It wants a mask and mode. Within the source code are some constants for the mode:
      # Get/Set BitMode use constant PFT_BITMODE_RESET => 0x00; use constant PFT_BITMODE_ASYNCBB => 0x01; use constant PFT_BITMODE_MPSSE => 0x02; use constant PFT_BITMODE_SYNCBB => 0x04; use constant PFT_BITMODE_MHBEM => 0x08; use constant PFT_BITMODE_FOISM => 0x10; use constant PFT_BITMODE_CBUSBB => 0x20;
      The mask is telling it which pins are input and which are output. A 0 bit is an input, a 1 is an output. The lowest bit is D0 (TXD), next is D1 (RXD), and so forth. Google "FTDI2XX mask mode bitbang" and you'll find the whole mapping. So, to set all lines/outputs to output in async bitbang:
      # # assuming you called OpenByIndex on this object already # $mode = $FTDIdev->SetBitMode(0xFF, 0x01);
        $FTDIdev->OpenDevByIndex(1); my $x = $FTDIdev->SetBitMode(0xFF, 0x01); print "$x"; #$x prints 1 my $mode = $FTDIdev->GetBitMode() || die "unable to get mode"; #fails here #GetBitMode(0x01) also fails

        The program now dies at GetBitMode.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1070757]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2018-07-19 13:38 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (408 votes). Check out past polls.