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/v1kind: Deploymentmetadata: labels: app: deviceshifu-plc4x-deployment name: deviceshifu-plc4x-deployment namespace: deviceshifuspec: 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: v1kind: ConfigMapmetadata: name: plc4x-configmap namespace: deviceshifudata: driverProperties: | driverSku: testPlc4x driverImage: instructions: | instructions: telemetries: | telemetrySettings:
deviceshifu-plc4x-service.yaml
apiVersion: v1kind: Servicemetadata: labels: app: deviceshifu-plc4x-deployment name: deviceshifu-plc4x namespace: deviceshifuspec: ports: - port: 80 protocol: TCP targetPort: 8080 selector: app: deviceshifu-plc4x-deployment type: LoadBalancer
edgedevice-plc4x.yaml
apiVersion: shifu.edgenesis.io/v1alpha1kind: EdgeDevicemetadata: name: edgedevice-plc4x namespace: devicesspec: 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
操作
对于PLC,Shifu能够通过HTTP申请来读取和写入其内存。
在执行操作之前,咱们须要启动一个nginx容器
,以用于HTTP申请的收发,启动的相干的命令如下:
kubectl run nginx --image=nginx:1.21 -n deviceshifu kubectl exec -it nginx -n deviceshifu -- bash
deviceshifu-plc4x-http
内置了两个命令read
和write
,咱们能够通过shifu应用这两个命令来对设施进行读写操作。
提醒
本文中的命令
%Q0.0:BOOL
为PLC4X的命令其中Q
为内存区域名称,0.0
示意起始bit的地址及其偏移量。BOOL
为读取(写入)的数据类型。如果您想理解更多对于PLC4X的命令,请返回PLC4X官网。
read
read
示意应用对应命令读取设施的值:
比方,命令curl "deviceshifu-plc4x/read?%Q0.0:BOOL"
会返回内存区域Q0
的地址内容。
curl "deviceshifu-plc4x/read?%Q0.0:BOOL"; echo{"field_%Q0.0:BOOL":"BOOL(1bit):false"}
此时Shifu返回Q区的从左往右第一个指示灯的状态。如果该指示灯为亮的则返回true,否则返回false。因为以后为燃烧状态,返回值为false。
write
write
示意通过命令批改对应地位的值:
比方,命令curl "deviceshifu-plc4x/read?%Q0.0:BOOL=true"
会将 Q0 的第一个 bit 批改为true。
curl "deviceshifu-plc4x/read?%Q0.0:BOOL=true"; echo
更多
如果您须要同时读取或者写入多个命令,您能够应用&
进行连贯应用。
比方,命令curl "deviceshifu-plc4x/read?%Q0.0:BOOL&%Q0.1:BOOL"
会同时将Q0
的第一个 bit 和 第二个 bit 的值返回。
命令curl "deviceshifu-plc4x/write?%Q0.0:BOOL=true&%Q0.1:BOOL=true"
会同时将Q0
的第一个 bit 和 第二个 bit 批改为true。
本文由边无际受权公布