Skip to content

Commit

Permalink
Finished Rework (#14)
Browse files Browse the repository at this point in the history
* fixed python syntax error, updated config files

* updated docs

* updated docs

* fixed typo

* minor changes to docs

* fixed links
  • Loading branch information
NicoSchoe authored Jan 11, 2024
1 parent c20656a commit 83475b8
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 92 deletions.
57 changes: 29 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Connecting USB QR Code Scanner

Connecting an USB based QR Code Scanner to an Industrial Edge Device.
Connecting an USB based QR code scanner to an Industrial Edge Device.

- [Connecting USB QR Code Scanner](#connecting-usb-qr-code-scanner)
- [Description](#description)
- [Overview](#overview)
- [General task](#general-task)
- [General Task](#general-task)
- [Requirements](#requirements)
- [Used components](#used-components)
- [Used Components](#used-components)
- [TIA Project](#tia-project)
- [Configuring PLC Connection](#configuring-plc-connection)
- [Installation](#installation)
Expand All @@ -22,29 +22,30 @@ Connecting an USB based QR Code Scanner to an Industrial Edge Device.

### Overview

This application examples shows how to connect a QR Code Scanner via USB to the Industrial Edge Device. The scanned QR Code will be sent to a PLC and displayed in an HMI Panel.
This application examples shows how to connect a QR code scanner via USB to the Industrial Edge Device. The scanned QR code will be sent to a PLC and displayed in an HMI Panel.

### General task
### General Task

The application reads the QR Code provided by the scanner and publishes it on the Databus to the topic corresponding to the OPC UA Connector, which sends the data to the PLC. This topic needs to be created in the Databus in advance.
Scanner type, plc tag, databus topic as well as databus credentials can be configured via an external configuration file.
The application reads the QR code provided by the scanner and publishes it on the Databus to the topic corresponding to the OPC UA Connector, which sends the data to the PLC. This topic needs to be created in the Databus in advance.
The scanner type, PLC tag, Databus topic as well as Databus credentials can be configured via an external configuration file.

![deploy VFC](docs/graphics/qrcode_task.png)

## Requirements

### Used components
### Used Components

- Industrial Edge App Publisher V1.10.5
- Docker Engine 18.09.6
- Docker Compose V2.4
- OPC UA Connector V1.8.1
- Common Connector Configurator V1.8.1-4
- Databus V2.1.0-4
- Industrial Edge App Publisher V1.12.7
- Docker Engine 24.0.6
- Docker Compose V2.21.0
- Common Connector Configurator V1.9.1-1
- Databus V2.3.1-2
- Databus Configurator V2.0.0-5
- Industrial Edge Device V1.10.0-9
- Industrial Edge Device V1.12.0-10
- IE App Configuration Service V1.3.2
- OPC UA Connector V2.1.0-0
- QR Code Scanner: SIMATIC MV320
- TIA Portal V16
- TIA Portal V18 (V16 minimum)
- PLC: CPU 1518 FW 2.8.3

### TIA Project
Expand All @@ -55,36 +56,36 @@ The used TIA Portal project can be found in the [miscellaneous repository](https

### Configuring PLC Connection

Further information about how to configure the OPC UA Connection to write data to the PLC can be found in the [docs](docs/PLC_connection.md) section
Further information about how to configure the OPC UA Connector to write data to the PLC can be found in the [docs](docs/PLC_connection.md) section.

- Configure Databus
- Configure OPC UA Connection
- [Configure Databus](docs/PLC_connection.md#configuring-databus)
- [Configure OPC UA Connector](docs/PLC_connection.md#configuring-opc-ua-connector)

## Installation

You can find the further information about the following steps in the [docs](./docs/Installation.md)
You can find further information about the following steps in the [docs](./docs/Installation.md)

- [Configure QR Code Scanner](docs/Installation.md#configure-qr-code-scanner)
- [Build application](docs/Installation.md#build-application)
- [Upload app to Industrial Edge Management](docs/Installation.md#upload-scanner-app-to-the-industrial-edge-managment)
- [Deploying application to Industrial Edge Device](docs/Installation.md#deploying-of-qr-code-scanner-demo)
- [Upload scanner app to the Industrial Edge Management](docs/Installation.md#upload-scanner-app-to-the-industrial-edge-management)
- [Configuring Application](docs/Installation.md#configuring-application)
- [Create & Deploy of QR code scanner demo](docs/Installation.md#create--deploy-configuration-file)

## Usage

Plug your SIMATIC MV320 Bar Code Scanner (or any other USB Scanner) to one of the USB Ports of your Industrial Edge Device.
Plug your SIMATIC MV320 QR code scanner (or any other USB Scanner) to one of the USB ports of your Industrial Edge Device.

Go to the TIA Portal Project, start the HMI Runtime and scan any available QR Code (e.g the following QR Code). A pop up will appear with the content of the scanned code.
Go to the TIA Portal Project, start the HMI Runtime and scan any available QR code (e.g., the following QR code). A pop up will appear with the content of the scanned code.

You can also open the GBD data block in the TIA Portal and check the content of the APP_QRCode variable in the app signals structure.
You can also open the GBD data block in the TIA Portal and check the content of the APP_QRCode variable in the appSignals structure.

![QR_Code_Industrial_Edge](docs/graphics/qr_code_industrial_edge.png)

## Implementation

How to access the USB based QR Code Scanner inside the application as well as further details about the source code can be found in the [implementation section](docs/Implementation.md).
The access to the USB based QR code scanner inside the application as well as further details about the source code can be found in the [implementation](docs/Implementation.md) section.

- [Accessing QR Code Scanner](docs/Implementation.md#accessing-qr-code-scanner) inside the application
- [Publishing QR Code](docs/Implementation.md#accessing-qr-code-scanner) to the Databus
- [Publishing QR Code](docs/Implementation.md#publishing-code-to-databus) to the Databus

## Documentation

Expand Down
6 changes: 3 additions & 3 deletions cfg-data/json_schema/param.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@
},
"Topic": {
"title": "IE Databus topic",
"default": "ie/d/j/simatic/v1/s7c1/dp/w/PLC_S7",
"default": "ie/d/j/simatic/v1/opcuac1/dp/w/PLC_OPC",
"type": "string",
"minLength": 1
},
"Variable": {
"title": "PLC Varibale",
"default": "GDB_appSignals_APP_QRCode",
"default": "GDB.appSignals.APP_QRCode",
"type": "string",
"minLength": 1
},
"Metadata": {
"title": "Metadata",
"default": "ie/m/j/simatic/v1/s7c1/dp",
"default": "ie/m/j/simatic/v1/opcuac1/dp",
"type": "string",
"minLength": 1
},
Expand Down
8 changes: 4 additions & 4 deletions cfg-data/param.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
{
"Scannertype": "Siemens AG MV320",
"Mqtt_Broker_Server": "ie-databus",
"User": "edge",
"Password": "edge",
"Metadata": "ie/m/j/simatic/v1/s7c1/dp",
"Topic": "ie/d/j/simatic/v1/s7c1/dp/w/PLC_S7",
"Variable": "GDB_appSignals_APP_QRCode"
"Metadata": "ie/m/j/simatic/v1/opcuac1/dp",
"Topic": "ie/d/j/simatic/v1/opcuac1/dp/w/PLC_OPC",
"Variable": "GDB.appSignals.APP_QRCode"
}
25 changes: 12 additions & 13 deletions docs/Implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

### Accessing input events

Using an USB QR Code Scanner in Linux the Scanner is mounted to the generic input event interface located in /dev/input/. In this application example the python-evdev library is used to read the input events of the Industrial Edge Device. The evdev interface passes events generated in the kernel directly to user space through character devices typically located in the mentioned /dev/input/ folder.
When using an USB QR code scanner in Linux the scanner is mounted to the generic input event interface located in /dev/input/. In this application example the python-evdev library is used to read the input events of the Industrial Edge Device. The evdev interface passes events generated in the kernel directly to user space through character devices typically located in the mentioned /dev/input/ folder.

The python-evdev libray can be used in your python script by importing evdev: *import evdev*

Expand All @@ -27,7 +27,6 @@ To enable the access to the input devices, the application needs to have access
> build: ./src
> image: scannerap:1.2.0
> restart: on-failure
> privileged: true
> mem_limit: 100mb
> networks:
> - proxy-redirect
Expand All @@ -39,9 +38,9 @@ To enable the access to the input devices, the application needs to have access
### Check for dedicated input device

As not all input events should be monitored, but only the events of the QR Code Scanner the application checks for a device with a dedicated name. The device name can be configured via the configuration file.
As not all input events should be monitored, but only the events of the QR code scanner the application checks for a device with a dedicated name. The device name can be configured via the [config file](../cfg-data/param.json).

The check is done in the **check_for_scanner** function in the **main.py** script. The function lists all devices provided by the evdev library (list_devices), checks for the scanner name and returns the corresponding event to the main function
The check is done in the **check_for_scanner** function in the **main.py** script. The function lists all devices provided by the evdev library (list_devices), checks for the scanner name and returns the corresponding event to the main function.

**Excerpt from main.py:**

Expand All @@ -61,13 +60,13 @@ The check is done in the **check_for_scanner** function in the **main.py** scrip

## Publishing Code to Databus

After the QR Code is scanned and read by the application it is published to the S7 Connector topic of the IE Databus. As the IE Databus is based on a MQTT Broker the python library **paho-mqtt** is used to publish values on the IE Databus.
After the QR code is scanned and read by the application it is published to the OPC UA Connector topic of the IE Databus. As the IE Databus is based on a MQTT broker the python library **paho-mqtt** is used to publish values on the IE Databus.

This library can be import by: **import paho.mqtt.client** **as** **mqtt**
This library can be imported by: **import paho.mqtt.client** **as** **mqtt**

### Initializing MQTT client

Before publishing data to the IE Databus the MQTT Client needs to be initialized, the connection to the broker established and the loop for accessing the broker started. As the IE Databus is protected by user and password the credentials needs to be set before connect to the broker.
Before publishing data to the IE Databus the MQTT client needs to be initialized, the connection to the broker established and the loop for accessing the broker started. As the IE Databus is protected by user and password the credentials need to be set before connecting to the broker.

**Excerpt from main.py:**

Expand All @@ -79,7 +78,7 @@ Before publishing data to the IE Databus the MQTT Client needs to be initialized
self.client.loop_start()
```

The mqtt connection is handled by the the `class mqttclient`, which is initialized when creating the class object. All needed parameters are handed over by the class constructor and can be configured using the [config file](../cfg-data/param.json).
The MQTT connection is handled by the the `class mqttclient`, which is initialized when creating the class object. All needed parameters are handed over by the class constructor and can be configured using the [config file](../cfg-data/param.json).

**Excerpt from main.py:**

Expand All @@ -91,14 +90,14 @@ The mqtt connection is handled by the the `class mqttclient`, which is initiali

### Publishing QR Code

As soon as the suffix (enter character) of the QR Code is detected by the application the scanned code is published to IE Databus. The QR Code as well as the IE Databus topic are printed to the logs using the **print** and **flush** commands.
As soon as the suffix (enter character) of the QR code is detected by the application the scanned code is published to IE Databus. The QR code as well as the IE Databus topic are printed to the logs using the **print** and **flush** commands.

**Excerpt from main.py:**

```python
# Check for QRCode suffix
if event.code == CONST_ENTER:
# Copy barcode to S7 Connector topic
# Copy barcode to OPCUA Connector topic
PLC_QR_Code['vals'][0]['id'] = (my_mqtt_client.IDDict.get(params['Variable']))
PLC_QR_Code['vals'][0]['val'] = barcode
# Publish MQTT Topic and flush to logs
Expand All @@ -110,7 +109,7 @@ As soon as the suffix (enter character) of the QR Code is detected by the applic
barcode = ""
```

The mqtt topic of the S7 Connector for writing to the PLC uses the following format:
The MQTT topic of the OPC UA Connector for writing to the PLC uses the following format:

```json
{
Expand All @@ -122,7 +121,7 @@ The mqtt topic of the S7 Connector for writing to the PLC uses the following for
```

The sequence number **seq** is optional and has no further value here.
The **vals** structure describes the data block variable of the PLC and consist the
The **vals** structure describes the data block variable of the PLC and consists two entries:

- **id**: Variable id, defined in the meta data of the connection.
- **val**: Value of the variable. In this case the *QR Code*.
- **val**: Value of the variable. In this case the *QR code*.
Loading

0 comments on commit 83475b8

Please sign in to comment.