Beispiel #1
0
 /**
  * WriteSingleRegister
  * @param integer $UnitId
  * @param integer $Reference
  * @param integer $Data
  */
 protected function WriteSingleRegister($UnitId, $Reference, $Data)
 {
     include_once __DIR__ . "/lib/ModbusMaster.php";
     $URL = "http://" . $this->ReadPropertyString("IPAddress");
     //$headers = @get_headers($URL);
     if (!Sys_Ping($this->ReadPropertyString("IPAddress"), 1000)) {
         $this->SetStatus(201);
         trigger_error("Invalid IP-Address", E_USER_ERROR);
         exit;
     }
     $this->SetStatus(102);
     if ($this->ReadPropertyInteger("GatewayMode") === 0) {
         $modbus = new ModbusMasterTcp($this->ReadPropertyString("IPAddress"));
     } else {
         $modbus = new ModbusMasterUdp($this->ReadPropertyString("IPAddress"));
     }
     //FC 6
     try {
         if (IPS_SemaphoreEnter("ModbusMaster", 1000)) {
             $this->Log("WriteSingleRegister({$UnitId}|{$Reference}|{$Data})");
             $modbus->writeSingleRegister($UnitId, $Reference, array($Data), array("INT"));
             IPS_SemaphoreLeave("ModbusMaster");
         }
     } catch (Exception $e) {
         $this->SetStatus(200);
         trigger_error("ModbusMaster: " . $e->getMessage() . "!", E_USER_ERROR);
         exit;
     }
 }
Beispiel #2
0
<?php

require_once dirname(__FILE__) . '/../../Phpmodbus/ModbusMasterUdp.php';
require_once dirname(__FILE__) . '/../config.php';
// Create Modbus object
$modbus = new ModbusMasterUdp($test_host_ip);
// Data to be writen - TRUE, FALSE
$data_true = array(TRUE);
$data_false = array(FALSE);
// Reset target WORD
$modbus->writeSingleRegister(0, 12288, array(0), array('WORD'));
// Write single coil - FC5
$modbus->writeSingleCoil(0, 12288, $data_true);
$modbus->writeSingleCoil(0, 12289, $data_false);
$modbus->writeSingleCoil(0, 12290, $data_true);
$modbus->writeSingleCoil(0, 12291, $data_false);
// Read data - FC3
$recData = $modbus->readMultipleRegisters(0, 12288, 1);
print_r($recData);
Beispiel #3
0
<?php

require_once dirname(__FILE__) . '/../../Phpmodbus/ModbusMasterUdp.php';
require_once dirname(__FILE__) . '/../config.php';
// Create Modbus object
$modbus = new ModbusMasterUdp($test_host_ip);
// Data to be writen - INT
$data = array(-12345);
$dataTypes = array("INT");
// Write data - FC6
$modbus->writeSingleRegister(0, 12288, $data, $dataTypes);
// Read data - FC3
$recData = $modbus->readMultipleRegisters(0, 12288, 1);
print_r($recData);