You need to enable JavaScript to run this app. Eclipse Milo通过OPC UA读取图片的支持情况及实现方法问询
优惠活动
大模型
产品
解决方案
定价
更多

Eclipse Milo通过OPC UA读取图片的支持情况及实现方法问询

结论

当前版本的Eclipse Milo完全支持读取你提到的这4种OPC UA规范定义的图片格式。
你在org.eclipse.milo.opcua.stack.core.Identifiers类中看到的ImageBMP、ImageGIF、ImageJPG、ImagePNG这几个类型,本质是OPC UA规范中内置的ByteString类型的子类型,Milo原生支持ByteString类型的序列化与反序列化,因此不需要额外适配就可以直接读写这些类型的节点。

客户端读取实现示例

核心读取逻辑和普通ByteString类型节点完全一致,读取到的字节数组就是对应格式图片的原始二进制内容,直接写入本地文件即可正常打开:

import org.eclipse.milo.opcua.stack.core.types.builtin.ByteString;
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;

import java.io.FileOutputStream;

public class OpcUaImageReader {
    public static void main(String[] args) throws Exception {
        // 替换为实际OPC UA服务器的endpoint地址
        String endpointUrl = "opc.tcp://192.168.1.100:4840";
        
        // 创建并连接客户端(连接的鉴权等配置可参考Milo基础客户端示例)
        OpcUaClient client = OpcUaClient.create(endpointUrl);
        client.connect().get();

        try {
            // 替换为你要读取的图片节点的实际NodeId
            NodeId imageNode = new NodeId(2, "Device/Camera/CaptureImage");
            
            // 读取节点值
            DataValue dataValue = client.readValue(0.0, null, imageNode).get();
            ByteString imageByteString = (ByteString) dataValue.getValue().getValue();

            if (imageByteString != null && imageByteString.isNotNull()) {
                // 写入本地文件,后缀和图片节点的格式对应即可
                try (FileOutputStream fos = new FileOutputStream("captured.jpg")) {
                    fos.write(imageByteString.bytes());
                }
            }
        } finally {
            // 断开客户端连接
            client.disconnect().get();
        }
    }
}

补充说明

如果是需要在服务端发布图片类型的节点,逻辑也类似:只需要把对应格式的图片读取为字节数组,封装为ByteString后赋值给对应类型的节点即可,Milo会自动完成后续的序列化传输。

内容的提问来源于stack exchange,提问作者silver_mx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.17 03:54:06