Skip to content
Snippets Groups Projects
Select Git revision
  • e3a7499c842d64608de9e1bffa8039b71ec7ebff
  • master default protected
  • dither_on_off_disabled
  • yocto
  • pypcc2
  • pypcc3
  • 2020-12-07-the_only_working_copy
  • v2.0
  • v1.0
  • v0.9
  • Working-RCU_ADC,ID
  • 2020-12-11-Holiday_Season_release
12 results

I2C.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    I2C.py 1.01 KiB
    if os.sys.platform is 'linux':
        import pylibi2c;
    import time
    import logging
    #bus = pylibi2c.I2CDevice('/dev/i2c-1'
    #read=0: write to register
    #read=1: read from register
    #read=2: write to register (common in group)
    #read=3: wait ms second
    I2Ccounter=0;
    
    def I2C1server(addr,data,reg=None,read=0):
      try:
           if read==3:
               time.sleep(data[0]/1000.)
               return True
           logging.debug(str(("I2C",addr,reg,data,read)))
    
    #       print("I2C",addr,reg,data,read)
    #       return True;
           bus=pylibi2c.I2CDevice('/dev/i2c-1',addr)
           if read==1:
             length=len(data)
             bus.iaddr_bytes=0
             if not(reg is None):
                 bus.ioctl_write(0,str(bytearray([reg])))
             data[:]=[int(x) for x in bus.ioctl_read(0,length)]
           else:
                if reg is None:
                   bus.iaddr_bytes=0
                   reg=0;
                bus.ioctl_write(reg,str(bytearray(data)))
           bus.close()
           return True;
      except:
           if bus: bus.close()
    #       data[0]=0
           return False;