示例#1
0
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))

    print("ftdi.usb_open(): %d" % ftdi.usb_open(context, 0x0403, 0x6010))
    print("ftdi.set_baudrate(): %d" % ftdi.set_baudrate(context, 9600))

    ftdi.free(context)
示例#2
0
 def __init__(self, ftdi_):
     """
     """
     if FTDI_TYPE == 0:
         self._log = MyLogger()
         self._log.info("Initialisation de la teleinfo")
         super(Teleinfo, self).__init__()
         self.__ftdi = ftdi_
     else:
         self.context = ftdi.new()
         ret = ftdi.usb_open(self.context, 0x0403, 0x6001)
         ftdi.set_baudrate(self.context, 1200)
         ftdi.set_line_property(self.context, ftdi.BITS_8, ftdi.EVEN,
                                ftdi.STOP_BIT_1)
 def __init__(self, ftdi_):
     """
     """
     logging.info("TELEINFO------Initialisation de la teleinfo")
     logging.info("TELEINFO------FTDI TYPE : " + str(ftdi_type))
     if ftdi_type == 0:
         globals.ftdi_context = ""
         super(Teleinfo, self).__init__()
         self.__ftdi = ftdi_
     else:
         globals.ftdi_context = ftdi.new()
         ret = ftdi.usb_open(globals.ftdi_context, 0x0403, 0x6001)
         if ret < 0:
             logging.error("Can't open usb (%d, %s)" % (err, ftdi.ftdi_get_error_string(self.__ftdic)))
         ftdi.set_baudrate(globals.ftdi_context, int(globals.vitesse))
     if globals.mode == "historique":
         globals.frame_length = 500
示例#4
0
        for i in range(ret):
            st += '0x%02X,' % ord(data[i])
        print "Received:", st, "ret=", ret, "\n"
    if (DEBUG_LEVEL > 0):
        print "Data written to address 0x%04X" % address, "= 0x%02X" % int(databyte), "\n"








if __name__ == '__main__':
    # initialize
    ftdic = ftdi.new()
    if ftdic == 0:
        print 'new failed: %d', ret
        os._exit( 1 )

    version_info = ftdi.get_library_version()
    print("\nlibFTDI version = major: %d, minor: %d, micro: %d" \
        ", version_str: %s, snapshot_str: %s\n" %
        (version_info.major, version_info.minor, version_info.micro,
        version_info.version_str, version_info.snapshot_str))

    # list all devices
    ret, devlist = ftdi.usb_find_all( ftdic, DEVICE_VID, DEVICE_PID )
    if ret < 0:
        print 'ftdi_usb_find_all failed: %d (%s)' % ( ret, ftdi.get_error_string( ftdic ) )
        os._exit( 1 )
示例#5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Python example program.

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

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

import os
import ftdi
import time

# initialize
ftdic = ftdi.new()
if ftdic == 0:
    print 'new failed: %d', ret
    os._exit(1)

# list all devices
ret, devlist = ftdi.usb_find_all(ftdic, 0x0403, 0x6001)
if ret < 0:
    print 'ftdi_usb_find_all failed: %d (%s)' % (ret,
                                                 ftdi.get_error_string(ftdic))
    os._exit(1)
print 'Number of FTDI devices found: %d\n' % ret
curnode = devlist
i = 0
while (curnode != None):
    ret, manufacturer, description, serial = ftdi.usb_get_strings(
        ftdic, curnode.dev)