-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
43 lines (32 loc) · 1.13 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import time
from opcua import Server
def main():
server = Server()
server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
uri = "https://opcturkey.com/"
namespace = server.register_namespace(uri)
objects = server.get_objects_node()
object1 = objects.add_object(namespace, "demo_object_for_OPCTURKEY")
object_variable1 = object1.add_variable(namespace, "demo_object_variable_for_OPCTURKEY", 0.0)
object_variable1.set_writable()
object2 = objects.add_object(namespace, "demo_object_for_OPCTURKEY_2")
object_variable2 = object2.add_variable(namespace, "demo_object_variable_for_OPCTURKEY_2", 1.0)
object_variable2.set_writable()
server.start()
try:
count = 0
while True:
time.sleep(5)
if count < 100:
count += 0.1
else:
count=0
object_variable1.set_value(round(count, 2))
if count >= 25 and count < 100:
object_variable2.set_value(count*1.5)
except KeyboardInterrupt:
pass
finally:
server.stop()
if __name__ == "__main__":
main()