PHP code example of erikwang2013 / industrial-protocols-kernel

1. Go to this page and download the library: Download erikwang2013/industrial-protocols-kernel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

erikwang2013 / industrial-protocols-kernel example snippets


use Erikwang2013\IndustrialProtocols\Kernel;
use Erikwang2013\IndustrialProtocols\Modbus\ModbusProtocol;

// AppServiceProvider::boot()
$kernel = app(Kernel::class);
$kernel->getProtocolRegistry()->register(new ModbusProtocol());
$kernel->boot();

$conn = $kernel->getConnectionManager()->connect('device-id');
$result = $conn->read('address');

// 或使用 Facade
\Erikwang2013\IndustrialProtocols\Framework\Laravel\IndustrialProtocolsFacade::connect('device-id')->read('address');

$kernel = \Hyperf\Context\ApplicationContext::getContainer()->get(Kernel::class);
$conn = $kernel->getConnectionManager()->connect('device-id');

use Erikwang2013\IndustrialProtocols\Kernel;
use Erikwang2013\IndustrialProtocols\Modbus\ModbusProtocol;

$kernel = new Kernel(['config_path' => __DIR__ . '/config.php']);
$kernel->getProtocolRegistry()->register(new ModbusProtocol());
$kernel->boot();

// 连接设备
$conn = $kernel->getConnectionManager()->connect('plc-001');
$result = $conn->read('40001');

// 网关引擎
$engine = new GatewayEngine($kernel->getConnectionManager(), ...);
$engine->addRule(new GatewayRule(id: 'rule-1', ...));

// 厂商桥接
$bridge = $kernel->getVendorBridgeFactory()->create('beckhoff', 'CX2030', '3.1');

$kernel->shutdown();

'devices' => [
    'device-id' => [
        'protocol' => 'kernel',
        'host'     => '192.168.1.10',
        'port'     => 0,
        'timeout'  => 3000,
    ],
],