package com.bonait.bnframework.common.modbus;

import com.licheedev.modbus4android.ModbusWorker;
import com.serotonin.modbus4j.ModbusMaster;

public class ModbusTcpMainHelper extends ModbusWorker {
    private static volatile ModbusTcpMainHelper instance = null;

    public static ModbusTcpMainHelper get() {
        ModbusTcpMainHelper manager = instance;
        if (manager == null) {
            synchronized (ModbusTcpMainHelper.class) {
                manager = instance;
                if (manager == null) {
                    manager = new ModbusTcpMainHelper();
                    instance = manager;
                }
            }
        }
        return manager;
    }

    private ModbusTcpMainHelper() {
    }

    /**
     * 释放整个ModbusManager，单例会被置null
     */
    public synchronized void release() {
        super.release();
        instance = null;
    }

    /**
     * 获取
     * @return
     */
    public synchronized ModbusMaster getModbusMaster()
    {
        return  super.getModbusMaster();
    }

}
