连接 西门子S7 PLC
Shifu 实现了对 西门子S7系列
PLC的兼容。用户可以使用 Shifu,通过 HTTP请求
对 S7 PLC
的内存进行修改。本文将介绍如何接入一台 西门子S7-1200 1214C PLC
并且与之交互。
参见演示视频 (Bilibili)以获得操作流程演示。
连接
第1步
在接入 Shifu 之前,PLC应当已经通过以太网与运行 Shifu 的上位机完成物理连接,并且拥有一个IP地址,这里我们使用192.168.0.1
。
提示
如果您的PLC设备不为192.168.0.1
可以将deviceshifu-plc-deployment.yaml
文件中的PLC_ADDRESS
改成您的设备的IP)
第2步
创建一个文件夹,在示例中我们将其命名为plc_configuration_directory
。将下述的四个配置文件都保存在该文件夹下 。
首先我们需要一个配置文件来获取IP地址与设备类型:
点此查看deviceshifu-plc-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: deviceshifu-plc-deployment
name: deviceshifu-plc-deployment
namespace: deviceshifu
spec:
replicas: 1
selector:
matchLabels:
app: deviceshifu-plc-deployment
template:
metadata:
labels:
app: deviceshifu-plc-deployment
spec:
containers:
- image: edgehub/deviceshifu-http-http:v0.0.1
name: deviceshifu-http
ports:
- containerPort: 8080
volumeMounts:
- name: deviceshifu-config
mountPath: "/etc/edgedevice/config"
readOnly: true
env:
- name: EDGEDEVICE_NAME
value: "edgedevice-plc"
- name: EDGEDEVICE_NAMESPACE
value: "devices"
- image: edgehub/plc-device:v0.0.1
name: plc
env:
- name: PLC_ADDRESS
value: "192.168.0.1"
- name: PLC_RACK
value: "0"
- name: PLC_SLOT
value: "1"
- name: PLC_CONTAINER_PORT
value: "11111"
volumes:
- name: deviceshifu-config
configMap:
name: plc-configmap-0.0.1
serviceAccountName: edgedevice-sa
同时,还需要一些通用的配置文件:
点此查看deviceshifu-plc-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: plc-configmap-0.0.1
namespace: deviceshifu
data:
# device name and image address
driverProperties: |
driverSku: PLC
driverImage: plc-device:v0.0.1
driverExecution: " "
# available instructions
instructions: |
sendsinglebit:
sendcontent:
getcontent:
getcpuordercode:
# telemetry retrieval methods
# in this example, a device_health telemetry is collected by calling hello instruction every 1 second
telemetries: |
device_health:
properties:
instruction: getcpuordercode
initialDelayMs: 1000
intervalMs: 1000
点此查看deviceshifu-plc-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: deviceshifu-plc-deployment
name: deviceshifu-plc
namespace: deviceshifu
spec:
ports:
- port: 80
protocol: TCP
targetPort: 8080
selector:
app: deviceshifu-plc-deployment
type: LoadBalancer
点此查看edgedevice-plc.yaml
apiVersion: shifu.edgenesis.io/v1alpha1
kind: EdgeDevice
metadata:
name: edgedevice-plc
namespace: devices
spec:
sku: "PLC"
connection: Ethernet
address: 0.0.0.0:11111
protocol: HTTP
status:
edgedevicephase: "Pending"