from PyChipsUser import *
from FmcTluI2c import *
import time

boardIpAddr = "192.168.200.16"
boardPortNum = 50001

addrTable = AddressTable("./aida_mini_tlu_addr_map.txt")

board = ChipsBusUdp(addrTable, boardIpAddr, boardPortNum)

# Check the bus for I2C devices
boardi2c = FmcTluI2c(board)

boardFirmware = board.read("FirmwareId")
print "Firmware version = " , hex(boardFirmware)

print "Scanning I2C bus:"
scanResults = boardi2c.i2c_scan()
print scanResults

boardId = boardi2c.get_serial_number()
print "FMC-TLU serial number = " , boardId

#dacValue = 0x4100
#dacValue = 0xFFFF
#dacValue = 0x0000
#dacValue = 0x7FFF
#print "Setting Vthreshold for all DACs. Code = ", dacValue
#boardi2c.set_dac(7,dacValue)

#time.sleep(2.0)

#dacValue = 0x6000
#print "Setting Vthreshold for DAC 0. Code = ", dacValue
#boardi2c.set_dac(0,dacValue)

#time.sleep(2.0)

# set DACs to -100mV
Vthresh = -0.10
print "Setting Vthreshold for all DACs. Voltage = " , Vthresh
boardi2c.set_threshold_voltage(7, Vthresh)
