在 OCI 容器中使用 grpcurl 与 PLCnext Control 进行本地 gRPC 交互
这是关于使用 gRPC 与 PLCnext Control 设备上 PLCnext Runtime 交互系列的最新篇章。
系列早期文章包括:
- 使用 grpcurl 远程 gRPC
- 使用 grpcurl 安全远程 gRPC
- 使用反射远程 gRPC
上述文章展示如何从远程客户端设备访问 PLCnext Control 设备上的 gRPC 服务器。本文给出本地 gRPC 客户端示例——即运行在 PLCnext Control 设备上、访问同一设备上 gRPC 服务器的 gRPC 客户端。
PLCnext Control 设备上其他本地 gRPC 客户端示例:
- 如何用 C# 创建 PLCnext Control gRPC 服务器客户端
- 使用 gRPC 将 Python 脚本与 PLCnext Engineer 项目对接
因 PLCnext Control 设备标准未安装 gRPC 客户端软件,本文展示如何用 Podman 和 dockerhub 合适镜像在 OCI 容器中运行 gRPC 客户端(本例为 grpcurl)。
前提条件
合适的 PLCnext Control 设备,有互联网访问。例:固件 2025.0 或更高的 AXC F 3152;固件 2026.0 或更高的 AXC F 1252。目前本文用的 OCI 镜像不适用于 armv7 目标如 AXC F 2152。
在浏览器打开设备 Web 管理 (WBM) 站点,在系统服务页确保 GRPC LOCAL SERVER 功能已激活。
步骤:
用 admin 用户账户在 PLCnext Control 设备打开安全 shell 会话。
在 shell 会话执行:
podman pull docker.io/fullstorydev/grpcurl:latest-alpine下载含 grpcurl 命令行工具的 OCI 镜像到 PLCnext Control 设备。
列出本地 PLCnext Control 设备可用 gRPC 服务:
podman run -it --rm -v /run/plcnext/:/run/plcnext/ --userns=keep-id docker.io/fullstorydev/grpcurl:latest-alpine --plaintext unix:///run/plcnext/grpc.sock list响应:
Arp.Device.Interface.Services.Grpc.IDeviceControlService Arp.Device.Interface.Services.Grpc.IDeviceInfoService Arp.Device.Interface.Services.Grpc.IDeviceSettingsService Arp.Device.Interface.Services.Grpc.IDeviceStatusService Arp.Io.Axioline.Services.Grpc.IAcyclicCommunicationService Arp.Io.Axioline.Services.Grpc.IAxioMasterService Arp.Plc.Gds.Services.Grpc.IDataAccessService Arp.Plc.Gds.Services.Grpc.IForceService Arp.Plc.Gds.Services.Grpc.ISubscriptionService Arp.Services.DataLogger.Services.Grpc.IDataLoggerService2 Arp.Services.NotificationLogger.Services.Grpc.INotificationLoggerService Arp.System.Commons.Services.Io.Grpc.IDirectoryService Arp.System.Commons.Services.Io.Grpc.IFileService Arp.System.Commons.Services.Io.Grpc.IFileSystemInfoService Arp.System.Lm.Services.Grpc.ILicenseStatusService Arp.System.Nm.Services.Grpc.INotificationManagerService Arp.System.Security.Services.Grpc.IAuthenticationService Arp.System.Um.Services.Grpc.IAuthorizationInfoService Arp.System.Um.Services.Grpc.IPasswordAuthenticationService grpc.reflection.v1.ServerReflection grpc.reflection.v1alpha.ServerReflection(可选) 创建别名简化后续 grpcurl 命令:
alias grpcurl="podman run -it --rm -v /run/plcnext/:/run/plcnext/ --userns=keep-id docker.io/fullstorydev/grpcurl:latest-alpine"从 PLCnext Control 设备获取板载温度:
grpcurl -format json -d '{"identifier":"Status.Board.Temperature.Centigrade"}' --plaintext unix:///run/plcnext/grpc.sock Arp.Device.Interface.Services.Grpc.IDeviceStatusService.GetItem响应:
{ "_ReturnValue": { "TypeCode": "CT_Int8", "Int8Value": 46 } }
注意:
Makers Blog 展示社区成员应用和用户故事,未经 Phoenix Contact 测试或审核。使用风险自负。
工业技术