Quantcast

Read status of FT245RL pins

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Read status of FT245RL pins

mackowiakp
This post was updated on .
Sorry for my ignorance but I am very new in FTDI chip 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 z lsusb
              FT_Open(0,&ftHandle0);
              FT_SetBitMode(ftHandle0,15,1);

             pkod=¶metr;

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

My question is. How can I read 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 ?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Read status of FT245RL pins

Jim Paris
mackowiakp wrote:

> Sorry for my ignorance but I am very new in FTDI chip 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
>      * */
...
> My question is. How can I read 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 ?

That code is using the proprietary D2XX driver, not the open-source
libftdi drivers that this mailing list discusses.  Maybe look for
documentation from your vendor.

For libftdi, a "ftdi_read_data" should do the trick, or
"ftdi_read_pins" is probably even simpler:
  https://www.intra2net.com/en/developer/libftdi/documentation/group__libftdi.html#gab823dd90f2359612b1546ef0ceebdc0e

Jim

--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [hidden email]  

Loading...