All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.foxtech.device.protocol.v1.s7plc.S7PLCWriteData Maven / Gradle / Ivy

/* ----------------------------------------------------------------------------
 * Copyright (c) Guangzhou Fox-Tech Co., Ltd. 2020-2024. All rights reserved.
 * --------------------------------------------------------------------------- */

package cn.foxtech.device.protocol.v1.s7plc;

import cn.foxtech.device.protocol.v1.core.annotation.FoxEdgeDeviceType;
import cn.foxtech.device.protocol.v1.core.annotation.FoxEdgeOperate;
import cn.foxtech.device.protocol.v1.core.exception.ProtocolException;
import cn.foxtech.device.protocol.v1.core.template.TemplateFactory;
import cn.foxtech.device.protocol.v1.s7plc.template.JDefaultTemplate;
import cn.foxtech.device.protocol.v1.utils.MethodUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 读数据
 */
@FoxEdgeDeviceType(value = "S7 PLC", manufacturer = "Siemens")
public class S7PLCWriteData {

    @FoxEdgeOperate(name = "writeData", polling = true, type = FoxEdgeOperate.encoder, timeout = 2000)
    public static Map packGetData(Map param) {
        // 提取业务参数:设备地址/对象名称/CSV模板文件
        Map objectValues = (Map) param.get("objectValues");
        String templateName = (String) param.get("templateName");

        // 简单校验参数
        if (MethodUtils.hasNull(objectValues, templateName)) {
            throw new ProtocolException("参数不能为空: objectNames, templateName");
        }

        JDefaultTemplate template = TemplateFactory.getTemplate("fox-edge-server-protocol-s7plc").getTemplate("jsn", templateName, JDefaultTemplate.class);


        List> params = template.encodeWriteObjects(objectValues);

        Map result = new HashMap<>();
        result.put("method", "writeData");
        result.put("params", params);

        return result;
    }

    @FoxEdgeOperate(name = "writeData", polling = true, type = FoxEdgeOperate.decoder, timeout = 2000)
    public static Map unpackReadData(Map respond, Map param) {
        String templateName = (String) param.get("templateName");

        // 简单校验参数
        if (MethodUtils.hasNull(templateName)) {
            throw new ProtocolException("参数不能为空:templateName");
        }

        return new HashMap<>();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy