LW-12, LW-14 Questions

English posts only please

Moderator: Guido Körber

Post Reply
LicControl
Posts: 5
Joined: Mon Dec 20, 2021 8:25 am

LW-12, LW-14 Questions

Post by LicControl »

Hello friends.

I want to ask how you can read the current status of the PWM outputs of the LW-12 through the i2c interface?
To find out the status of a DALI device on the network, I have to submit an address request to each device. This takes a lot of time and loads the network. Is there another way to monitor the status of devices on the network through LW-14, for example, by reading through the i2c interface? Or perhaps there is a command for LW-14 to poll the status of all devices on the network?
And I think there is a bug in the function ReadQuery(), in the program lw14_class.py.
The command i2c.write_byte(self.i2c_bus, defs.LW14_REG_COMMAND) is missing here.
I think the function ReadQuery() should look like this

Code: Select all

#Read data from DALI device
def ReadQuery(self, value):
	data = [self.dali_adr, value]
	self._i2c_write(data)
	res = self.WaitForValidReply()
	if res == defs.RET_SUCCESS:
		i2c.write_byte(self.i2c_bus, defs.LW14_REG_COMMAND)
		sleep(0.001)
		read = self._i2c_read(defs.LW14_REG_COMMAND)
		#Clear command register
		self._i2c_read(defs.LW14_REG_COMMAND)
		return read
	else:
		#print ("WaitForValidReply:	 %d" % res)
		return res #errorcode < 0
LicControl
Posts: 5
Joined: Mon Dec 20, 2021 8:25 am

Re: LW-12, LW-14 Questions

Post by LicControl »

I have already found answers to my own questions.
To monitor commands on the network, it is enough to read the register Command ($01) in LW-14. It stores the last address and command.
To read the PWM value, you need to read register PWM Values ($08) in LW-12.
Here is my example code for the lw14_class.py, class lw14:

Code: Select all

def _i2c_read_block(self, reg, len):
  result = 0
  try:
    return i2c.read_i2c_block_data(self.i2c_bus, reg, len)
  except IOError as e:
    print ("I/O error({0}): {1}".format(e.errno, e.strerror))
  return defs.RET_ERROR
   
#Reading the last command on the network (LW-14)		
def ReadDaliCommand(self):
  i2c.write_byte(self.i2c_bus, defs.LW14_REG_COMMAND)
  return self._i2c_read_block(defs.LW14_REG_COMMAND, 3)	
	
#Reading the current PWM value for LW-12
def ReadPWM(self):
  i2c.write_byte(self.i2c_bus, 0x08)
  raw_pwm = self._i2c_read_block(0x08, 8)
  pwm = []
  for i in range(4):
    pwm.append((raw_pwm[2*i]& 0x00FF) | (raw_pwm[2*i+1]<<8))	
  return pwm	
Guido Körber
Site Admin
Posts: 2856
Joined: Tue Nov 25, 2003 10:25 pm
Location: Germany/Berlin
Contact:

Re: LW-12, LW-14 Questions

Post by Guido Körber »

DALI does not have any option to poll all devices at once, at least not one that will give you a useful result. So there is no way but to query each device separately.

Reading the Command register in the LW14 makes only sense when that status flags indicate that new data has been received.

Not sure what reading the LW12 registers have to do in this context. The I2C interface of LW12 is specific to the LW12 and not standard for DALI.
Post Reply