Test comunicazione modbus [GUIDA]

Discussioni relative all'uso di contatori SDM120 SDM220 modbus
Avatar utente
Flane
Messaggi: 2460
Iscritto il: 16/01/2016, 15:02

Test comunicazione modbus [GUIDA]

Messaggioda Flane » 06/03/2017, 10:01

Per capire se il vostro bus funziona correttamente, nelle ultime immagini Solarjessie ho inserito un file /var/www/comapps/testcom.php che permette di effettuare appunto dei test di comunicazione sul bus, restituendone l'esito.

Questo il contenuto del file:

Codice: Seleziona tutto

#!/usr/bin/php
<?php
// A simple script to test your com app to adjust the com parameters
// You'll need to setup correct permission chmod +x
// then ln -s /var/www/comapps/testcom.php /usr/bin/testcom
// Request command with 'testcom'
//uncomment the correct line to be tested
$command = 'sdm120c -a2 -b9600 -z10 -j10 -w10 -PN -qpievfg -d0 /dev/ttyUSB0';
//$command = 'aurora -a 2 -c -T -Y3 -l3 -d0 -e /dev/tty-USB0';

date_default_timezone_set('Europe/Brussels');
if (isset($_SERVER['REMOTE_ADDR'])) {
    die('Direct access not permitted');
}
////
$try       = 10;
$timemax   = 0;
$timemin   = 10000000;
$countdown = $try;
$log       = '/var/www/comapps/comtest.log';
$errcnt    = 0;
$stamp     = date('d/m/Y H:i:s');

for ($i = 1; $i <= $try; $i++) {
    system('clear');
    echo "Testing in progress ($countdown)\n";
    $start = microtime(true);
    exec("$command", $output, $error);
    if ($error == 0) {
        $time_elapsed_secs = microtime(true) - $start;
        if ($time_elapsed_secs > $timemax) {
            $timemax = $time_elapsed_secs;
        }
        if ($time_elapsed_secs < $timemin) {
            $timemin = $time_elapsed_secs;
        }
        print_r($output);
    } else {
        $errcnt++;
    }
    $countdown--;
}
//system('clear');
$timemin = round($timemin*1000, 4);
$timemax = round($timemax*1000, 4);
if ($errcnt != $try) {
    $data = "$stamp : $command\nResult : best $timemin ms - worst $timemax ms - $errcnt error(s)\n\n";
    echo "$data";
    file_put_contents($log, $data, FILE_APPEND);
} else {
    echo "Errors while testing : $command\n";
}
?>

Il symlink testcom è già stato inserito nella Solarjessie e non serve ricrearlo.

ATTENZIONE: controllate se nella vostra versione del file è necessario correggere il BUG di questo file segnalato QUI

Per il TEST del bus basterà editare il file /var/www/comapps/testcom.php e correggere il comando da eseguire con il contatore che volete provare modificando la riga:

Codice: Seleziona tutto

$command = 'sdm120c -a2 -b9600 -z10 -j10 -w10 -PN -qpievfg -d0 /dev/ttyUSB0';


Potete anche commentare la riga relativa al contare (basterà aggiungere // ad inizio ricga) ed eseguire dei test nei confronti dell'inverte ABB Power-One con il comando aurora (per fare ciò eliminate il commento alla riga aurora togliendo le // iniziali)
Fate attenzione a lasciare una sola riga non commentata con il comando da eseguire.

Per eseguire il test basta digitare da terminale il comando:

Codice: Seleziona tutto

testcom


Lo script eseguirà 10 prove di lettura restituendone a video l'esito con la velocità massima e minima delle varie letture.
Vi sarà restituito qualcosa del genere:
test_bus.jpg

in questo caso tutte le letture sono state eseguite correttamente, ma in almeno un caso come vedete una lettura ha impiegato più di 10s :?

Verrà inoltre generato un file di log /var/www/comapps/comtest.txt con l'esito di tutti i test eseguiti.

Potete provare con diversi valori dei parametri j, z, w, W che permettono appunto di tarare al meglio le letture sul vostro bus.


Torna a “Contatori Modbus”

Chi c’è in linea

Visitano il forum: Nessuno e 3 ospiti