0

Sorry for my ignorance but I am very new in FTDI chip Linux software development. I have module based on FT245RL chip, programmed to be 4 port output (relays) and 4 port opto isolated input unit. I found out in Internet program in C to turn on/off relays connected to outputs D0 to D3. After compiling it works properly. Below draft of this working program:

/* switch4.c
* # gcc -o switch4 switch4.c -L. -lftd2xx -Wl,-rpath,/usr/local/lib
* Usage
* # switch4 [0-15], for example # switch4 1
* */
#include <stdio.h>
#include <stdlib.h>
#include "./ftd2xx.h"

int main(int argc, char *argv[])
{
   FT_STATUS ftStatus;
   FT_HANDLE ftHandle0;
   int parametr;
   LPVOID pkod;
   DWORD   nBufferSize = 0x0001;
   DWORD dwBytesWritten;

          if(argc > 1) {
                  sscanf(argv[1], "%d", ¶metr);
          }
          else {
                  parametr = 0;
          }  

     FT_SetVIDPID(0x5555,0x0001);  // id from lsusb
     FT_Open(0,&ftHandle0);
     FT_SetBitMode(ftHandle0,15,1);

     pkod=&parametr;

    ftStatus = FT_Write(ftHandle0,pkod,nBufferSize,&dwBytesWritten);
    ftStatus = FT_Close(ftHandle0);
}

My question is. How can I read in the same program, status of D4 to D7 pins, programmed as inputs? I mean about "printf" to stdout the number representing status (zero or one) of input pins (or all input/output pins). Can anybody help newbie ?

UPDATE-1

This is my program with FT_GetBitMode

//  # gcc -o read5 read5.c -L. -lftd2xx -Wl,-rpath,/usr/local/lib

#include <stdio.h>
#include <stdlib.h>
#include "./ftd2xx.h"

int main(int argc, char *argv[])
{
    FT_STATUS ftStatus;
    FT_HANDLE ftHandle0;
    UCHAR BitMode;

      FT_SetVIDPID(0x5555,0x0001);  // id from lsusb
      ftStatus = FT_Open(0,&ftHandle0);
      if(ftStatus != FT_OK) {
      printf("FT_Open failed");
      return;
      }
      FT_SetBitMode(ftHandle0,15,1);

      ftStatus = FT_GetBitMode(ftHandle0, &BitMode);
      if (ftStatus == FT_OK) {
      printf("BitMode contains - %d",BitMode);
      }
      else {
      printf("FT_GetBitMode FAILED!");
      }

      ftStatus = FT_Close(ftHandle0);
}

But it returns "FT_GetBitMode FAILED!" instead value of BitMode

mackowiakp
  • 203
  • 1
  • 4
  • 12

2 Answers2

0

FT_GetBitMode returns the instantaneous value of the pins. A single byte will be returned containing the current values of the pins, both those which are inputs and those which are outputs.

Source.

spatial
  • 26
  • 3
  • So i try to use FT_GetBitMode as documentation stands. But it returns "FT_GetBitMode FAILED!" instead value of BitMode. Source of my program in UPDATE-1 to the first post. Can anybody tell me what I am doing wrong? – mackowiakp Sep 06 '16 at 12:10
  • What is the ftStatus code return from your call to FT_GetBitMode()? From your code there it doesn't look like you are doing anything wrong. You could send them an email, I'm sure they would help you out: support1@ftdichip.com – spatial Sep 07 '16 at 08:17
  • Hmm, strange. ftStatus code return from call to FT_GetBitMode() is digit 4. But is not hardware failure because I have test program for Windows and it works properly. – mackowiakp Sep 07 '16 at 15:50
0

Finally I found out whats going wrong. I used incorrect version of ftdi library. The correct version dedicated for x86_64 platform is located here:

Link to FTDI library

mackowiakp
  • 203
  • 1
  • 4
  • 12