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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.