I’m trying to write some code to drive an FTDI USB-COM422-PLUS2.

The plan is to use one of the ports as a VCP and run the other with the D2XX driver in asynchronous Bit Bang mode.

This requires overriding the EEPROM driver settings in FTDIBUS.INF

Let’s assume I’ve done this part correctly.

I put together some code to test this:


#!/usr/bin/perl use strict; use warnings; use Win32::FTDI::FTD2XX; use Win32::SerialPort; my $FTDIdev = Win32::FTDI::FTD2XX->new(); my $PortName = "COM6"; #name of port we want to use my $stuff = pack(“a”, “stuff I want to write”); my $CPort6 = Win32::SerialPort-> new($PortName) || die "Can't open $PortName: $^E\n"; #initalise port #write to comport my $count_out = $CPort6->write($stuff); warn "write failed\n" unless ($count_out); sleep 1; my $PrintData = $CPort10->input; #expected return data #print print "Data: $PrintData 1\n"; my $Num = 2;# GetNumDevices(); print "No. Dev: $Num\n"; my $devOpen; #check if we can talk to the device with FTD2XX if($Num) { my $i = 1; $devOpen = $FTDIdev->OpenByIndex($i); my $devInfo = $FTDIdev->GetDeviceInfo($i) || die "Unable to get device info"; # if($devInfo) # { # my $out = sprintf(" Type:\t\t%d(%s)\n ID:\t\tVID(%04X) PID( +%04X)\n Serial:\t%s\n Descr:\t%s\n", $devInfo->{TypeID}, $devInfo->{T +ypeNm}, $devInfo->{VID}, $devInfo->{PID}, $devInfo->{Serial}, $devInf +o->{Descr} ); # print "$out"; # } } my $ID = $FTDIdev->PFT_HANDLE(); # point to the port we want my $sucecess = $FTDIdev->SetBitMode($ID, 0x03, 0x1); #FTDI chip, select pin 1 an pin 2, Asynchronous bit bang print "sucecess? $sucecess\n"; my $mode = $FTDIdev->GetBitMode($ID) || die "unable to get mode"; print "Mode is $mode\n"; my $devClose = $FTDIdev->Close(); $devOpen = $FTDIdev->OpenByIndex(1); print "$devOpen\n"; my $TrigOn = pack("C", 0xFF); #Test output $FTDIdev->SetWriteTimeout(1); $FTDIdev->write($ID, $TrigOn) || die "unable to write1"; Print “it works”; #end



Writing to COM6 works as expected. $mode returns 245, which seems to be bit bang mode from what I can tell. So, I'm assuming these aren't the problem.
...245 might not be normal for mode....

The program goes into an infinite loop @ $FTDIdev->write($ID, $TrigOn) and never prints “it works”.

The perl module (see FTDI site or CPAN) seems to require fewer inputs than what is defined in the D2XX programmer’s guide.

I suspect the issue is related to not clearly specifying which port I’m writing to.


In reply to Problem Writing to FTDI COM Port using Win32::FTDI::FTD2XX by PrfrrdUsrNm

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.