File: simple.py

package info (click to toggle)
libftdi1 1.5-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,024 kB
  • sloc: ansic: 6,255; cpp: 875; python: 537; sh: 116; makefile: 48
file content (34 lines) | stat: -rw-r--r-- 883 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Python example program.

Small program to demonstrate the usage
of the swig generated python wrapper

You need to build and install the wrapper first"""

import ftdi1 as ftdi


def main():
    """Main program"""
    context = ftdi.new()

    version_info = ftdi.get_library_version()
    print("[FTDI version] major: %d, minor: %d, micro: %d"
          ", version_str: %s, snapshot_str: %s" %
         (version_info.major, version_info.minor, version_info.micro,
          version_info.version_str, version_info.snapshot_str))

    # try to open an ftdi 0x6010 or 0x6001
    ret = ftdi.usb_open(context, 0x0403, 0x6010)
    if ret < 0:
        ret = ftdi.usb_open(context, 0x0403, 0x6001)

    print("ftdi.usb_open(): %d" % ret)
    print("ftdi.set_baudrate(): %d" % ftdi.set_baudrate(context, 9600))

    ftdi.free(context)

main()