Getting Started: Connect a PLC

Shifu's Siemens S7 Suite provides the ability to edit the PLC memory area through HTTP requests. This article will provide an example on connecting a Siemens S7-1200 1214C PLC to Shifu and using Shifu to interact with it.

See Demo Videoarrow-up-right for the video version of the following steps.

Connecting S7 PLC

Before connected to Shifu, an S7 PLC needs to be physically connected over Ethernet with an IP address, for example, 192.168.0.1.

In this scenario, Shifu needs the deployment config to tell Shifu the address and type of the device: plc-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: plc
  name: plc
  namespace: devices
spec:
  replicas: 1
  selector:
    matchLabels:
      app: plc
  template:
    metadata:
      labels:
        app: plc
    spec:
      containers:
        - image: edgehub/plc-device:v0.0.1
          name: plc
          ports:
            - containerPort: 11111
          env:
            - name: PLC_ADDR
              value: "192.168.0.1"
            - name: PLC_RACK
              value: "0"        
            - name: PLC_SLOT
              value: "1"

Other configuration files should also be prepared with necessary information: deviceshifu-plc-configmap.yaml

deviceshifu-plc-deployment.yaml

deviceshifu-plc-service.yaml

plc-edgedevice.yaml

plc-service.yaml

Add the PLC device to Shifu to start:

Operations

Shifu provides the following HTTP APIs to edit memory area.

sendsinglebit: Edit a single bit of a given memory area. It takes the following parameters:

  • rootaddress: the name of the root memory area, e.g., M for Merker, Q for Digital Output Process Image, etc.

  • address: the address in the memory area.

  • start: the starting position in the address.

  • digit: the nth digit of bit to be edited.

  • value: the value to be set to the nth digit of bit.

For example, plc/sendsinglebit?rootaddress=M&address=0&start=2&digit=2&value=1 will make M0.2's second digit to 1.

getcontent: Get the current value of a given memory area in byte. It takes the following parameters:

  • rootaddress: the name of the root memory area, e.g., M for Merker, Q for Digital Output Process Image, etc.

  • address: the address in the memory area.

  • start: the starting position in the address.

For example, plc/sendsinglebit?rootaddress=M&address=0&start=2 will get M0.2's value.

getcpuordercode: Get the S7 PLC static information.

Last updated