diff --git a/.gitignore b/.gitignore index 131d9b6cc8e86bfbe3b9e8199a1d2823df569bde..2abff9f9708ccae49116acc9e578626566a58579 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ **/env **/__pycache__ **/*.pyc +**/.DS_Store diff --git a/clk/Vars.py b/clk/Vars.py index 7e49e3aee89ac518d634f2bedf12afd16ff573cd..c9d89948dd8ec0bce5ca7aaed6bd658bf715f792 100644 --- a/clk/Vars.py +++ b/clk/Vars.py @@ -50,4 +50,22 @@ CLK_PLL_setup=Instrs("CLK_PLL_setup",15,[ Instr(DevType.VarUpdate,CLK_lock1,1,[0]) ]) +def SPIinst(reg,value): + return Instr(DevType.SPIbb,DevReg(SPIBB_PLL,0,reg,0),1,[value]), +CLK_PLL_setup=Instrs("CLK_PLL_setup",2,[ + SPIinst(0x03,0x08), + SPIinst(0x05,0x97), + SPIinst(0x06,0x10), + SPIinst(0x07,0x04), + SPIinst(0x08,0x01), + SPIinst(0x07,0x00), + SPIinst(0x09,0x10), + SPIinst(0x0A,0x14), + SPIinst(0x09,0x00), + SPIinst(0x0D,0x01),#was 2 + SPIinst(0x0F,0x01), + SPIinst(0x11,0x01), + SPIinst(0x13,0x01) +]) + OPC_methods=[CLK_on,CLK_off,CLK_PLL_setup] diff --git a/clk/spibitbang2.py b/clk/spibitbang2.py index f51d9a2f21d344b4868670733bb0ae9c81615a98..d312d5b6560f7bfaaaa75a9cef2773bc9b636f71 100644 --- a/clk/spibitbang2.py +++ b/clk/spibitbang2.py @@ -19,8 +19,8 @@ def SetSPIbb(SetI2C,RCUi,dev,value): CLKdev=dev.Addr.devs[SPIBB_pins.CLK.value] CLKpin=dev.Addr.pins[SPIBB_pins.CLK.value] - logging.warn(str(("SPIbb set",ADC_address,value))) - + logging.info(str(("SPIbb set",ADC_address,value))) + # dev_rw = 0x00 # 0 for write, 1 for read # data2 = ( reg_address << 9 ) + ( dev_rw << 8 ) + value[0] data2 = ( ADC_address << 9 ) + value[0] @@ -50,7 +50,7 @@ def GetSPIbb(SetI2C,GetI2C,RCUi,dev,value): CLKdev=dev.Addr.devs[SPIBB_pins.CLK.value] CLKpin=dev.Addr.pins[SPIBB_pins.CLK.value] - logging.warn(str(("SPIbb get",ADC_reg_address))) + logging.info(str(("SPIbb get",ADC_reg_address))) ADC_bytes = 0x00 # ADC_rw = 0x01 # 0 for write, 1 for read data = (ADC_reg_address << 1) + 1 #was 7?? diff --git a/i2c/I2C.py b/i2c/I2C.py index 1982b43c9c0e13bf33d61d4bf48e8c2b940b5d06..d3a60c9655f3b77cb094800511f99f5b6b41dd3b 100644 --- a/i2c/I2C.py +++ b/i2c/I2C.py @@ -1,4 +1,5 @@ -import pylibi2c; +if os.sys.platform is 'linux': + import pylibi2c; import time import logging #bus = pylibi2c.I2CDevice('/dev/i2c-1' @@ -55,6 +56,35 @@ def I2C4server(addr,data,reg=None,read=0): bus.ioctl_write(0,str(bytearray([reg]))) data[:]=[int(x) for x in bus.ioctl_read(0,length)] # print(data) + 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; + + +def I2C2server(addr,data,reg=None,read=0): + try: + if read==3: + time.sleep(data[0]/1000.) + return True + logging.debug(str(("I2C2",addr,reg,data,read))) + +# print("I2C",addr,reg,data,read) +# return True; + bus=pylibi2c.I2CDevice('/dev/i2c-2',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 diff --git a/requirements.txt b/requirements.txt index 818caf7311d7521391980a3a53c5a8b2397feef1..a60ca7ecbd7bfebc36f787dd6425b771587835b1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -pylibi2c (github.com/amaork/libi2c) +git+https://github.com/amaork/libi2c.git; platform_system == "linux" opcua numpy recordclass diff --git a/scripts/test1.py b/scripts/test1.py new file mode 100644 index 0000000000000000000000000000000000000000..a691a74530fd5645c34f885bb2fcc5b59e8a2355 --- /dev/null +++ b/scripts/test1.py @@ -0,0 +1,23 @@ +from test_common import * + +name="RCU_LED0_RW" +#RCU=0; +#LEDvalue=0; + +#setRCUmask([RCU]) + +A=get_value(name) +print(A) +#A[0]=1.; +A[0]='on'; +print(A) +set_value(name,A) +#print("LED old:",led) +#led[RCU]=LEDvalue + +#set_value(name+"_RW",led) +#time.sleep(0.1) + +#print("LED new:",get_value(name+"_R")) + +disconnect()