Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

@GrandFather I would rather not combine my scripts, as they each have very different purposes, and the two scripts are also used independently on other machines. I think that creating a daemon is worth a try. As I have no formal IT training, this is going to be an interesting learning experience.

As to the common module with a lock file, I am still stuck with how to have two scripts accessing a common module. I have now tried running a script that has package functions and calls the two test scripts. Pretty messy to put it mildly, but is was just an experiment.

#!/usr/bin/perl package Hvac::i2cAccess; use strict; use HiPi::Device::I2C; use Exporter qw( import ); our @EXPORT_OK = qw( i2c_test1 i2c_test2 ); my $copyit = "Empty"; # call test scripts # test1 just gets the $copyit value # test2 sends an i2c object and gets the voltage value in return # the voltage value is also copied into $copyit do "/home/huw/cron_scripts/test1.pl"; print "A\n"; do "/home/huw/cron_scripts/test2.pl"; print "B\n"; do "/home/huw/cron_scripts/test1.pl"; print "C\n"; while( 1 ){ sleep 1; } exit 0; # ********************************************************* # sub i2c_test2 { # i2c object passed from test2.pl my $obj = $_[0]; # read 2 bytes of data from bus voltage register (address 0x02) my @bvr; eval{ @bvr = $obj->bus_read( 0x02, 2 ); 1; } or do { $bvr[0] = 0; $bvr[1] = 0; }; # result in upper 13 bits - big-endian order my $busV = pack 'C2', $bvr[0], $bvr[1]; $busV = ( unpack 'S>', $busV ) >> 3; # scale bus voltage register value my $bv = 16; my $bvScale = 4000; $busV = $bv / $bvScale * $busV; $copyit = $busV; return $copyit; } # ********************************************************* # sub i2c_test1 { print "Test 1 subroutine\n"; return "Copy $copyit"; } # ********************************************************* # # must end modules with a 'true' value 1;

but I don't get past the first 'do'. I presume that 'do' is waiting for the script it calls to end and return a value. 'A' is never printed

The module code without the 'calls' to the two test scripts was used to test the common module approach, but as I said, it looks like each test script invokes a separate copy of the module.


In reply to Re^2: i2c bus contention by anita2R
in thread i2c bus contention by anita2R

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-24 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found