| 1 | #!/usr/bin/env python |
| 2 | # -*- coding: utf-8 -*- |
| 3 | |
| 4 | """Python example program. |
| 5 | |
| 6 | Small program to demonstrate the usage |
| 7 | of the swig generated python wrapper |
| 8 | |
| 9 | You need to build and install the wrapper first""" |
| 10 | |
| 11 | import ftdi1 as ftdi |
| 12 | |
| 13 | def main(): |
| 14 | """Main program""" |
| 15 | context = ftdi.new() |
| 16 | |
| 17 | version_info = ftdi.get_library_version() |
| 18 | print("[FTDI version] major: %d, minor: %d, micro: %d" \ |
| 19 | ", version_str: %s, snapshot_str: %s" % |
| 20 | (version_info.major, version_info.minor, version_info.micro, |
| 21 | version_info.version_str, version_info.snapshot_str)) |
| 22 | |
| 23 | # try to open an ftdi 0x6010 or 0x6001 |
| 24 | ret = ftdi.usb_open(context, 0x0403, 0x6010) |
| 25 | if ret < 0: |
| 26 | ret = ftdi.usb_open(context, 0x0403, 0x6001) |
| 27 | |
| 28 | print("ftdi.usb_open(): %d" % ret) |
| 29 | print("ftdi.set_baudrate(): %d" % ftdi.set_baudrate(context, 9600)) |
| 30 | |
| 31 | ftdi.free(context) |
| 32 | |
| 33 | main() |