使用 PLC4x 连接 西门子S7 PLC
Shifu 还可以使用 PLC4X的形式 实现对 西门子S7系列
PLC兼容。本文将介绍如何使用 deviceshifu-plc4x-http
接入一台 西门子S7-1200 1214C PLC
并且与之交互。
连接
第1步
在接入 Shifu 之前,PLC应当已经通过以太网与运行 Shifu 的上位机完成物理连接,并且拥有一个IP地址,这里我们使用192.168.0.1
。
提示
如果您的PLC设备不为192.168.0.1
可以将edgedevice-plc4x.yaml
文件中的address
改成您的设备的IP)
第2步
创建一个文件夹,在示例中我们将其命名为plc4x_configuration_directory
。将下述的四个配置文件都保存在该文件夹下 。
首先我们需要一个配置文件来获取IP地址与设备类型:
点此查看deviceshifu-plc4x-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: deviceshifu-plc4x-deployment
name: deviceshifu-plc4x-deployment
namespace: deviceshifu
spec:
replicas: 1
selector:
matchLabels:
app: deviceshifu-plc4x-deployment
template:
metadata:
labels:
app: deviceshifu-plc4x-deployment
spec:
containers:
- image: edgehub/deviceshifu-http-plc4x:v0.1.1
name: deviceshifu-http
ports:
- containerPort: 8080
volumeMounts:
- name: deviceshifu-config
mountPath: "/etc/edgedevice/config"
readOnly: true
env:
- name: EDGEDEVICE_NAME
value: "edgedevice-plc4x"
- name: EDGEDEVICE_NAMESPACE
value: "devices"
volumes:
- name: deviceshifu-config
configMap:
name: plc4x-configmap
serviceAccountName: edgedevice-sa
同时,还需要一些通用的配置文件:
点此查看deviceshifu-plcs4x-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: plc4x-configmap
namespace: deviceshifu
data:
driverProperties: |
driverSku: testPlc4x
driverImage:
instructions: |
instructions:
telemetries: |
telemetrySettings:
点此查看deviceshifu-plc4x-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: deviceshifu-plc4x-deployment
name: deviceshifu-plc4x
namespace: deviceshifu
spec:
ports:
- port: 80
protocol: TCP
targetPort: 8080
selector:
app: deviceshifu-plc4x-deployment
type: LoadBalancer
点此查看edgedevice-plc4x.yaml
apiVersion: shifu.edgenesis.io/v1alpha1
kind: EdgeDevice
metadata:
name: edgedevice-plc4x
namespace: devices
spec:
sku: "testPlc4x"
connection: Ethernet
address: 192.168.0.1 #change this accordingly
protocol: PLC4X
protocolSettings:
PLC4XSetting:
protocol: s7
第3步
向 Shifu 添加PLC设备,创建和启动 deviceShifu:
kubectl apply -f ../plc4x_configuration_directory