http://qs1969.pair.com?node_id=1148902

packetstormer has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks, the following is a long-shot!

I have a small raspberry pi relay board that I am trying to use. The manufacturer has provided some sample Python code to open and close the relay. However, as the rest of the project is written in perl I'd like to get it working all in one module

Could anyone take a shot at explaining what the python lines below do and how they might translate to perl?

I can manage to open all ports (at the same time!), using Device::SMBus on the relay board in perl but I can't figure out what "&=" and "|&" means in the source script

class Relay(): global bus def __init__(self): self.DEVICE_ADDRESS = 0x20 #7 bit address (will be left shift +ed to add the read write bit) self.DEVICE_REG_MODE1 = 0x06 self.DEVICE_REG_DATA = 0xff bus.write_byte_data(self.DEVICE_ADDRESS, self.DEVICE_REG_MODE1, se +lf.DEVICE_REG_DATA) def ON_1(self): print 'ON_1...' self.DEVICE_REG_DATA &= ~(0x1<<0) bus.write_byte_data(self.DEVICE_ADDRESS, self.DEVICE_REG_MODE1 +, self.DEVICE_REG_DATA)

And my Perl Code

#!/usr/bin/perl use strict; use Device::SMBus; use Data::Dumper; my $dev = Device::SMBus->new( I2CBusDevicePath => '/dev/i2c-1', I2CDeviceAddress => 0x20, ); $dev->writeByteData(0x06,0x1<<0); print Dumper $dev

With the perl code all the relays open (or close). So it's really this line self.DEVICE_REG_DATA &= ~(0x1<<0) that's causing my trouble.

Like I said, I know this is a long shot but I'd appreciate some input