“Machine Utilization Example” - Machine Connectivity¶
This this file, Modbus TCP based machine connectivity has been handled. Additionally, data has been pre-processed using Connectware Rules.
Download: utilization-connectivity.yml
Note
The example below uses an additional Docker image provided by Cybus that requires a suitable license. You can check the current capabilities and permissions of your Connectware license in the Cybus Portal (https://portal.cybus.io). If your license is not eligible to use the example Docker image, please contact Cybus Sales (sales@cybus.io).
1description: >
2 Machine connectivity and data mapping
3
4metadata:
5 name: ModBus Machine Connectivity
6 icon: https://www.cybus.io/wp-content/uploads/2019/03/Cybus-logo-Claim-lang.svg
7 provider: cybus
8 homepage: https://www.cybus.io
9 version: 0.0.1
10
11parameters:
12 modbus_connection_ip:
13 type: string
14 default: 172.17.0.1
15
16 modbus_connection_port:
17 type: integer
18 default: 10502
19
20resources:
21
22 # Modbus simulator service for this example
23 machineSimulator:
24 type: Cybus::Container
25 properties:
26 image: registry.cybus.io/cybus-testing/modbus-machine-simulator:0.0.1
27 ports:
28 - !sub '${modbus_connection_port}:10502/tcp'
29
30 modbusConnection:
31 type: Cybus::Connection
32 properties:
33 protocol: Modbus
34 targetState: connected
35 connection:
36 host: !ref modbus_connection_ip
37 port: !ref modbus_connection_port
38
39 powerLevel:
40 type: Cybus::Endpoint
41 properties:
42 protocol: Modbus
43 connection: !ref modbusConnection
44 subscribe:
45 fc: 3
46 length: 2
47 interval: 1000
48 address: 0
49 dataType: floatBE
50
51 mapping:
52 type: Cybus::Mapping
53 properties:
54 mappings:
55 - subscribe:
56 endpoint: !ref powerLevel
57 publish:
58 topic: !sub "${Cybus::MqttRoot}/power-level"
59 - subscribe:
60 endpoint: !ref powerLevel
61 rules:
62 - transform:
63 expression: |
64 (
65 $stateMap := [
66 {
67 "lower": 0,
68 "upper": 0,
69 "state": "OFF"
70 },
71 {
72 "lower": 1,
73 "upper": 10,
74 "state": "IDLE"
75 },
76 {
77 "lower": 11,
78 "upper": 40,
79 "state": "JOG"
80 },
81 {
82 "lower": 41,
83 "upper": 100,
84 "state": "RUNNING"
85 }
86 ];
87 $findState := function($stateRaw) {
88 (
89 $result := $filter($stateMap, function($v) {
90 ($stateRaw >= $v.lower and $stateRaw <= $v.upper)
91 });
92 $result ? $result[0].state : "ERROR"
93 )
94 };
95 {
96 "powerlevel": value,
97 "state": $findState(value),
98 "timestamp": timestamp
99 }
100 )
101 publish:
102 topic: !sub "${Cybus::MqttRoot}/machine-state"