libftdi是一个用以跟FTDI的FT232/245BM,FT2232C/D,和FT232/245R类型芯片通讯的开发包,包括使用libusb的bitbang模式。该库在用户空间和程序进行链接,无需内核驱动。
因为libusb的帮助,libftdi可以很好的支持Windows、Linux、BSD和Mac系统。
示例代码:
/*simple.cSimplelibftdiusageexampleThisprogramisdistributedundertheGPL,version2*/#include<stdio.h>#include<stdlib.h>#include<ftdi.h>intmain(void){intret;structftdi_context*ftdi;structftdi_version_infoversion;if((ftdi=ftdi_new())==0){fprintf(stderr,"ftdi_newfailed\n");returnEXIT_FAILURE;}version=ftdi_get_library_version();printf("Initializedlibftdi%s(major:%d,minor:%d,micro:%d,snapshotver:%s)\n",version.version_str,version.major,version.minor,version.micro,version.snapshot_str);if((ret=ftdi_usb_open(ftdi,0x0403,0x6001))<0){fprintf(stderr,"unabletoopenftdidevice:%d(%s)\n",ret,ftdi_get_error_string(ftdi));ftdi_free(ftdi);returnEXIT_FAILURE;}//ReadoutFTDIChip-IDofRtypechipsif(ftdi->type==TYPE_R){unsignedintchipid;printf("ftdi_read_chipid:%d\n",ftdi_read_chipid(ftdi,&chipid));printf("FTDIchipid:%X\n",chipid);}if((ret=ftdi_usb_close(ftdi))<0){fprintf(stderr,"unabletocloseftdidevice:%d(%s)\n",ret,ftdi_get_error_string(ftdi));ftdi_free(ftdi);returnEXIT_FAILURE;}ftdi_free(ftdi);returnEXIT_SUCCESS;}
评论