@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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.