Commit | Line | Data |
---|---|---|
50280d45 MZ |
1 | #!/usr/bin/env python |
2 | # -*- coding: utf-8 -*- | |
3 | ||
4b7a5e13 TJ |
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 | ||
bcf4a08b | 11 | import ftdi1 as ftdi |
4b7a5e13 | 12 | |
1cbfde94 | 13 | |
4b7a5e13 TJ |
14 | def main(): |
15 | """Main program""" | |
4c5afeb9 | 16 | context = ftdi.new() |
4b7a5e13 | 17 | |
4c5afeb9 | 18 | version_info = ftdi.get_library_version() |
1cbfde94 MZ |
19 | print("[FTDI version] major: %d, minor: %d, micro: %d" |
20 | ", version_str: %s, snapshot_str: %s" % | |
21 | (version_info.major, version_info.minor, version_info.micro, | |
22 | version_info.version_str, version_info.snapshot_str)) | |
4b7a5e13 | 23 | |
31fba51d MZ |
24 | # try to open an ftdi 0x6010 or 0x6001 |
25 | ret = ftdi.usb_open(context, 0x0403, 0x6010) | |
26 | if ret < 0: | |
27 | ret = ftdi.usb_open(context, 0x0403, 0x6001) | |
1cbfde94 | 28 | |
31fba51d | 29 | print("ftdi.usb_open(): %d" % ret) |
4c5afeb9 | 30 | print("ftdi.set_baudrate(): %d" % ftdi.set_baudrate(context, 9600)) |
4b7a5e13 | 31 | |
4c5afeb9 | 32 | ftdi.free(context) |
4b7a5e13 TJ |
33 | |
34 | main() |