Go bindings for libFTDI (http://www.intra2net.com/en/developer/libftdi/)
ziutek / ftdi Goto Github PK
View Code? Open in Web Editor NEWGo binding for libFTDI
License: Other
Go binding for libFTDI
License: Other
Go bindings for libFTDI (http://www.intra2net.com/en/developer/libftdi/)
Documentation of io.Reader
says:
Implementations of Read are discouraged from returning a zero byte count with a nil error, except when len(p) == 0. Callers should treat a return of 0 and nil as indicating that nothing happened; in particular it does not indicate EOF.
It looks like Device.Read
is a wrapper on ftdi_read_data
:
Line 441 in f54995a
0
if no data is available on USB.
This BTW breaks io.ReadFull
but maybe this is more a problem on Go side, given that returning 0,nil
is "discouraged" but not "forbidden". Anyway, is there any way to more strictly adhere to io.Reader
and have Device.Read
automatically block until at least a byte is available?
build fails on Go master (what will be Go-1.15):
github.com/ziutek/ftdi
# github.com/ziutek/ftdi
../../../../pkg/mod/github.com/ziutek/[email protected]/device.go:279:43: cannot use _Ctype_enum_ftdi_interface(c) (type _Ctype_enum_ftdi_interface) as type uint32 in assignment
../../../../pkg/mod/github.com/ziutek/[email protected]/eeprom.go:194:39: cannot use names[n] (type _Ctype_enum_ftdi_eeprom_value) as type uint32 in assignment
../../../../pkg/mod/github.com/ziutek/[email protected]/eeprom.go:205:39: cannot use names[n] (type _Ctype_enum_ftdi_eeprom_value) as type uint32 in assignment
../../../../pkg/mod/github.com/ziutek/[email protected]/eeprom.go:358:39: cannot use cbusFunction[n] (type _Ctype_enum_ftdi_eeprom_value) as type uint32 in assignment
../../../../pkg/mod/github.com/ziutek/[email protected]/eeprom.go:366:39: cannot use cbusFunction[n] (type _Ctype_enum_ftdi_eeprom_value) as type uint32 in assignment
../../../../pkg/mod/github.com/ziutek/[email protected]/error.go:24:57: cannot use _Ctype_enum_libusb_error(e) (type _Ctype_enum_libusb_error) as type int32 in argument to _Cfunc_libusb_strerror
could this be addressed?
thanks.
The USB comes up at port /dev/ttyUSB0.
root@abc:/home/mx# dmesg | grep FTDI
[ 10.110208] usbserial: USB Serial support registered for FTDI USB Serial Device
[ 10.117813] ftdi_sio 2-1:1.0: FTDI USB Serial Device converter detected
[ 10.631320] usb 2-1: FTDI USB Serial Device converter now attached to ttyUSB0
[ 70.117061] usbserial: USB Serial deregistering driver FTDI USB Serial Device
[ 70.142658] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
But when I check the list of available ports on device, USB0 is not one of them.
root@abc:/home/mx# ls -l /dev/ttyUSB*
crw-rw---- 1 root dialout 188, 1 Mar 26 19:37 /dev/ttyUSB1
crw-rw---- 1 root dialout 188, 2 Mar 26 19:52 /dev/ttyUSB2
crw-rw---- 1 root dialout 188, 3 Mar 26 19:37 /dev/ttyUSB3
Output of dmesg serial shows the USB device (using FTDI chip):
root@abc:/home/mx# dmesg | grep -i serial
[ 0.201790] Serial: 8250/16550 driver, 3 ports, IRQ sharing disabled
[ 0.203082] 44e09000.serial: ttyS0 at MMIO 0x44e09000 (irq = 158, base_baud = 3000000) is a 8250
[ 0.757937] 48022000.serial: ttyS1 at MMIO 0x48022000 (irq = 159, base_baud = 3000000) is a 8250
[ 0.767271] 481aa000.serial: ttyS2 at MMIO 0x481aa000 (irq = 160, base_baud = 3000000) is a 8250
[ 1.037963] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 1.056786] usb usb1: SerialNumber: musb-hdrc.0.auto
[ 1.104245] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 1.123071] usb usb2: SerialNumber: musb-hdrc.1.auto
[ 1.697707] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1.713459] usb 2-1: SerialNumber: EO4UIWQ1 <--
[ 3.157824] systemd[1]: Created slice system-serial\x2dgetty.slice.
[ 9.339820] usbcore: registered new interface driver usbserial
[ 9.345850] usbcore: registered new interface driver usbserial_generic
[ 9.352454] usbserial: USB Serial support registered for generic
[ 10.110208] usbserial: USB Serial support registered for FTDI USB Serial Device
[ 10.117813] ftdi_sio 2-1:1.0: FTDI USB Serial Device converter detected
[ 10.631320] usb 2-1: FTDI USB Serial Device converter now attached to ttyUSB0
[ 11.950003] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 13.268513] usbcore: registered new interface driver qcserial
[ 13.274376] usbserial: USB Serial support registered for Qualcomm USB modem
[ 13.368442] qcserial 1-1:1.0: Qualcomm USB modem converter detected
[ 13.415999] qcserial 1-1:1.2: Qualcomm USB modem converter detected
[ 13.446006] qcserial 1-1:1.3: Qualcomm USB modem converter detected
[ 70.117061] usbserial: USB Serial deregistering driver FTDI USB Serial Device
[ 70.142658] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
I've tried to unload the VCP drivers:
root@abc:/home/mx# rmmod ftdi_sio
rmmod: ERROR: Module ftdi_sio is not currently loaded
root@abc:/home/mx# rmmod usbserial
rmmod: ERROR: Module usbserial is in use by: qcserial usb_wwan
I cannot connect to /dev/ttyUSB0:
failed to connect, open /dev/ttyUSB0: no such device or address
Hi, I realize this library is fairly dormant now but I have upgraded to the latest libftdi library and it appears that a method make have changed. When I run my go program it fails a particular call:
# github.com/wdevore/hardware/ftdi
../../ftdi/ftdi232h.go:454:29: f.device.WriteLen undefined (type *ftdi.Device has no field or method WriteLen)
Any thoughts on how I could fix this? Thanks.
Hi, I'm trying to run a go get command and I see this issue:
go get github.com/ziutek/ftdi
# pkg-config --cflags -- libftdi1
Package libftdi1 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libftdi1.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libftdi1' found
pkg-config: exit status 1
Any idea what is causing this?
$ go build
# github.com/ziutek/ftdi
./error.go:24:43: cannot use int32(e) (type int32) as type _Ctype_int in argument to _Cfunc_libusb_strerror
$ go version
go version go1.16.5 linux/amd64
Line 24 in f54995a
Reverting the last commit makes it build without error for me. That also fixes the deprecation warnings (which were fixed in #10 but reintroduced due to #14).
The build failures in #14 seem to occur because people aren't building against libftdi 1.5, which is over a year old now. It's a bit unfortunate that Ubuntu LTS (20.04) seems to be on 1.4 - most other distros should have picked it up by now.
with latest master (ie: what will become Go-1.16), one gets:
github.com/ziutek/ftdi
# github.com/ziutek/ftdi
cgo-gcc-prolog: In function ‘_cgo_2ab0b5d0f81b_Cfunc_ftdi_usb_purge_buffers’:
cgo-gcc-prolog:646:2: warning: ‘ftdi_usb_purge_buffers’ is deprecated [-Wdeprecated-declarations]
In file included from ../../../../pkg/mod/github.com/ziutek/[email protected]/device.go:5:
/usr/include/libftdi1/ftdi.h:566:20: note: declared here
566 | int DEPRECATED(ftdi_usb_purge_buffers(struct ftdi_context *ftdi));
| ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/libftdi1/ftdi.h:247:55: note: in definition of macro ‘DEPRECATED’
247 | #define DEPRECATED(func) __attribute__ ((deprecated)) func
| ^~~~
cgo-gcc-prolog: In function ‘_cgo_2ab0b5d0f81b_Cfunc_ftdi_usb_purge_rx_buffer’:
cgo-gcc-prolog:665:2: warning: ‘ftdi_usb_purge_rx_buffer’ is deprecated [-Wdeprecated-declarations]
In file included from ../../../../pkg/mod/github.com/ziutek/[email protected]/device.go:5:
/usr/include/libftdi1/ftdi.h:564:20: note: declared here
564 | int DEPRECATED(ftdi_usb_purge_rx_buffer(struct ftdi_context *ftdi));
| ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/libftdi1/ftdi.h:247:55: note: in definition of macro ‘DEPRECATED’
247 | #define DEPRECATED(func) __attribute__ ((deprecated)) func
| ^~~~
cgo-gcc-prolog: In function ‘_cgo_2ab0b5d0f81b_Cfunc_ftdi_usb_purge_tx_buffer’:
cgo-gcc-prolog:684:2: warning: ‘ftdi_usb_purge_tx_buffer’ is deprecated [-Wdeprecated-declarations]
In file included from ../../../../pkg/mod/github.com/ziutek/[email protected]/device.go:5:
/usr/include/libftdi1/ftdi.h:565:20: note: declared here
565 | int DEPRECATED(ftdi_usb_purge_tx_buffer(struct ftdi_context *ftdi));
| ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/libftdi1/ftdi.h:247:55: note: in definition of macro ‘DEPRECATED’
247 | #define DEPRECATED(func) __attribute__ ((deprecated)) func
| ^~~~
# github.com/ziutek/ftdi
../../../../pkg/mod/github.com/ziutek/[email protected]/error.go:24:43: cannot use int32(e) (type int32) as type _Ctype_int in argument to _Cfunc_libusb_strerror
/home/yj/go/pkg/mod/github.com/ziutek/[email protected]/device.go:386:21: could not determine kind of name for C.ftdi_tciflush
/home/yj/go/pkg/mod/github.com/ziutek/[email protected]/device.go:396:21: could not determine kind of name for C.ftdi_tcioflush
/home/yj/go/pkg/mod/github.com/ziutek/[email protected]/device.go:391:21: could not determine kind of name for C.ftdi_tcoflush
To build ftdi
as part of a static binary, there is a fix required. The line #cgo pkg-config: libftdi1
in device.go must be changed to #cgo pkg-config: --static libftdi1
. This tells go build
to invoke pkg-config
with the --static
argument to provide the correct library list for the static linking case.
This is a known shortcoming of Go, documented in golang/go#26492. The same issue (in the description) reports an example of a common workaround: using two Go files to switch the different pkg-config
invocation, guarded by the static_build
build tag which seems to be the de-facto standard.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.