Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
59d6a9d0
Commit
59d6a9d0
authored
Oct 12, 2021
by
Pavel Vainerman
Committed by
Pavel Vainerman
Oct 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[python3]: fixed import
parent
3bdd88fa
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
118 additions
and
117 deletions
+118
-117
libuniset2.spec
conf/libuniset2.spec
+4
-1
configure.ac
configure.ac
+2
-2
start_fg_UC.sh
wrappers/python/examples/start_fg_UC.sh
+0
-5
UGlobal.py
wrappers/python/lib/UGlobal.py
+2
-2
UInterface.py
wrappers/python/lib/UInterface.py
+1
-3
UInterfaceModbus.py
wrappers/python/lib/UInterfaceModbus.py
+4
-4
UInterfaceUniSet.py
wrappers/python/lib/UInterfaceUniSet.py
+4
-3
UniSetHTTP.py
wrappers/python/lib/UniSetHTTP.py
+1
-2
UniXML.py
wrappers/python/lib/UniXML.py
+42
-37
__init__.py
wrappers/python/lib/__init__.py
+9
-9
Makefile.am
wrappers/python/lib/pyUniSet/Makefile.am
+1
-1
testUC.py
wrappers/python/tests/UConnector/testUC.py
+16
-16
testUHttp.py
wrappers/python/tests/UHttp/testUHttp.py
+3
-3
testUI.py
wrappers/python/tests/UInterface/testUI.py
+18
-18
testUModbus.py
wrappers/python/tests/UModbus/testUModbus.py
+11
-11
No files found.
conf/libuniset2.spec
View file @
59d6a9d0
...
...
@@ -25,7 +25,7 @@
%define oname uniset2
Name: libuniset2
Version: 2.15.
1
Version: 2.15.
2
Release: alt1
Summary: UniSet - library for building distributed industrial control systems
...
...
@@ -594,6 +594,9 @@ rm -f %buildroot%_docdir/%oname/html/*.md5
# history of current unpublished changes
%changelog
* Tue Oct 12 2021 Pavel Vainerman <pv@altlinux.ru> 2.15.2-alt1
- fixed python3 imports
* Mon Oct 11 2021 Pavel Vainerman <pv@altlinux.ru> 2.15.1-alt1
- supported "hash64/hash32" for ID
...
...
configure.ac
View file @
59d6a9d0
...
...
@@ -3,10 +3,10 @@
# See doc: http://www.gnu.org/software/hello/manual/autoconf/Generic-Programs.html
# AC_PREREQ(2.59)
AC_INIT([uniset2], [2.15.
1
], pv@etersoft.ru)
AC_INIT([uniset2], [2.15.
2
], pv@etersoft.ru)
AM_INIT_AUTOMAKE([subdir-objects])
LIBVER=17:
1
:15
LIBVER=17:
2
:15
AC_SUBST(LIBVER)
# AC_CONFIG_MACRO_DIR([m4])
...
...
wrappers/python/examples/start_fg_UC.sh
deleted
100755 → 0
View file @
3bdd88fa
#!/bin/sh
START
=
uniset2-start.sh
${
START
}
-f
./testUC.py
--ulog-add-levels
info,warn,crit
wrappers/python/lib/UGlobal.py
View file @
59d6a9d0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from
pyUConnector
import
*
import
time
import
sys
from
.pyUniSet.pyUConnector
import
*
def
is_id
(
str_id
):
if
isinstance
(
str_id
,
int
)
or
isinstance
(
str_id
,
int
):
...
...
wrappers/python/lib/UInterface.py
View file @
59d6a9d0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import
sys
from
.pyUniSet.pyUniSet
import
*
from
pyUniSet
import
*
from
pyUExceptions
import
*
class
UInterface
():
def
__init__
(
self
):
...
...
wrappers/python/lib/UInterfaceModbus.py
View file @
59d6a9d0
...
...
@@ -3,9 +3,9 @@
import
sys
from
UInterface
import
*
from
UGlobal
import
*
from
pyUModbus
import
*
from
.
UInterface
import
*
from
.
UGlobal
import
*
from
.pyUniSet.
pyUModbus
import
*
class
UInterfaceModbus
(
UInterface
):
...
...
@@ -14,7 +14,7 @@ class UInterfaceModbus(UInterface):
self
.
itype
=
"modbus"
self
.
i
=
UModbus
()
self
.
i
.
prepare
(
ip
,
port
)
self
.
i
.
prepare
(
ip
,
port
)
# return [id,node,name]
def
getIDinfo
(
self
,
s_id
):
...
...
wrappers/python/lib/UInterfaceUniSet.py
View file @
59d6a9d0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from
UInterface
import
*
from
UGlobal
import
*
from
pyUConnector
import
*
from
.UInterface
import
*
from
.UGlobal
import
*
from
.pyUniSet.pyUConnector
import
*
class
UInterfaceUniSet
(
UInterface
):
def
__init__
(
self
,
xmlfile
,
params
):
...
...
wrappers/python/lib/UniSetHTTP.py
View file @
59d6a9d0
...
...
@@ -144,4 +144,4 @@ class SharedMemoryAPI(UniSetHTTPService):
return
self
.
request
(
'/lost'
)[
self
.
settings
[
'smID'
]]
def
help
(
self
):
return
self
.
request
(
'/help'
)[
self
.
settings
[
'smID'
]]
\ No newline at end of file
return
self
.
request
(
'/help'
)[
self
.
settings
[
'smID'
]]
wrappers/python/lib/UniXML.py
View file @
59d6a9d0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import
re
import
sys
import
libxml2
from
lxml
import
etree
import
re
import
os
# -----------------------------
class
EmptyNode
():
def
__init__
(
self
):
self
.
proplist
=
dict
()
def
__init__
(
self
):
self
.
proplist
=
dict
()
def
prop
(
self
,
name
):
if
name
in
self
.
proplist
:
def
prop
(
self
,
name
):
if
name
in
self
.
proplist
:
return
self
.
proplist
[
name
]
return
""
return
""
def
setProp
(
self
,
name
,
val
):
self
.
proplist
[
name
]
=
val
def
setProp
(
self
,
name
,
val
):
self
.
proplist
[
name
]
=
val
def
reset
(
self
):
self
.
proplist
=
dict
()
def
reset
(
self
):
self
.
proplist
=
dict
()
# -----------------------------
class
UniXMLException
(
Exception
):
def
__init__
(
self
,
e
=
""
):
def
__init__
(
self
,
e
=
""
):
self
.
err
=
e
def
getError
(
self
):
return
self
.
err
# -----------------------------
class
UniXML
():
...
...
@@ -38,11 +43,11 @@ class UniXML():
try
:
self
.
doc
=
None
if
isDoc
:
self
.
fname
=
''
self
.
doc
=
libxml2
.
parseDoc
(
xfile
)
self
.
fname
=
''
self
.
doc
=
libxml2
.
parseDoc
(
xfile
)
else
:
self
.
fname
=
xfile
self
.
doc
=
libxml2
.
parseFile
(
xfile
)
self
.
fname
=
xfile
self
.
doc
=
libxml2
.
parseFile
(
xfile
)
except
libxml2
.
parserError
:
raise
UniXMLException
(
"(UniXML): Can`t open file "
+
xfile
)
...
...
@@ -83,7 +88,7 @@ class UniXML():
while
node
!=
None
:
if
node
.
prop
(
propstr
)
==
valuestr
:
return
[
node
,
node
.
name
,
node
.
prop
(
propstr
)]
ret
=
self
.
findNode_byProp
(
node
.
children
,
propstr
,
valuestr
)
ret
=
self
.
findNode_byProp
(
node
.
children
,
propstr
,
valuestr
)
if
ret
[
0
]
!=
None
:
return
ret
node
=
node
.
__next__
...
...
@@ -95,14 +100,14 @@ class UniXML():
if
node
==
None
:
return
node
if
node
.
name
!=
"text"
and
node
.
name
!=
"comment"
:
return
node
return
node
return
None
def
getNode
(
self
,
node
):
if
node
==
None
:
return
None
return
None
if
node
.
name
!=
"text"
and
node
.
name
!=
"comment"
:
return
node
return
node
return
self
.
nextNode
(
node
)
def
firstNode
(
self
,
node
):
...
...
@@ -117,8 +122,8 @@ class UniXML():
def
lastNode
(
self
,
node
):
prev
=
node
while
node
!=
None
:
prev
=
node
node
=
self
.
nextNode
(
node
)
prev
=
node
node
=
self
.
nextNode
(
node
)
return
prev
...
...
@@ -131,20 +136,20 @@ class UniXML():
def
save
(
self
,
filename
=
None
,
pretty_format
=
True
,
backup
=
False
):
if
filename
==
None
:
filename
=
self
.
fname
filename
=
self
.
fname
if
backup
:
# чтобы "ссылки" не бились, делаем копирование не через rename
#
os.rename(self.fname,str(self.fname+".bak"))
f_in
=
file
(
self
.
fname
,
'rb'
)
f_out
=
file
(
str
(
self
.
fname
+
".bak"
),
'wb'
)
f_in
.
seek
(
0
)
f_out
.
write
(
f_in
.
read
())
f_in
.
close
()
f_out
.
close
()
# чтобы "ссылки" не бились, делаем копирование не через rename
#
os.rename(self.fname,str(self.fname+".bak"))
f_in
=
file
(
self
.
fname
,
'rb'
)
f_out
=
file
(
str
(
self
.
fname
+
".bak"
),
'wb'
)
f_in
.
seek
(
0
)
f_out
.
write
(
f_in
.
read
())
f_in
.
close
()
f_out
.
close
()
if
pretty_format
==
True
:
return
self
.
pretty_save
(
filename
)
return
self
.
pretty_save
(
filename
)
return
self
.
doc
.
saveFile
(
filename
)
...
...
@@ -163,12 +168,12 @@ class UniXML():
def
pretty_save
(
self
,
filename
):
context
=
self
.
doc
.
serialize
(
encoding
=
"utf-8"
)
mdoc
=
etree
.
XML
(
context
)
s
=
etree
.
tostring
(
mdoc
,
pretty_print
=
True
,
encoding
=
"UTF-8"
,
method
=
'xml'
,
xml_declaration
=
True
)
.
split
(
"
\n
"
)
out
=
open
(
filename
,
"w"
)
s
=
etree
.
tostring
(
mdoc
,
pretty_print
=
True
,
encoding
=
"UTF-8"
,
method
=
'xml'
,
xml_declaration
=
True
)
.
split
(
"
\n
"
)
out
=
open
(
filename
,
"w"
)
p
=
re
.
compile
(
r'\ [^\s]{1,}=""'
)
for
l
in
s
:
if
l
.
strip
():
# удаляем пустые свойства prop=""
l
=
p
.
sub
(
''
,
l
)
out
.
write
(
l
+
"
\n
"
)
# удаляем пустые свойства prop=""
l
=
p
.
sub
(
''
,
l
)
out
.
write
(
l
+
"
\n
"
)
out
.
close
()
wrappers/python/lib/__init__.py
View file @
59d6a9d0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from
UGlobal
import
*
from
UniXML
import
*
from
UInterface
import
*
from
UInterfaceUniSet
import
*
from
UInterfaceModbus
import
*
from
.
UGlobal
import
*
from
.
UniXML
import
*
from
.
UInterface
import
*
from
.
UInterfaceUniSet
import
*
from
.
UInterfaceModbus
import
*
from
pyUniSet
import
*
from
pyUModbus
import
*
from
pyUConnector
import
*
from
.pyUniSet.
pyUniSet
import
*
from
.pyUniSet.
pyUModbus
import
*
from
.pyUniSet.
pyUConnector
import
*
from
pyUExceptions
import
*
from
.pyUniSet.
pyUExceptions
import
*
wrappers/python/lib/pyUniSet/Makefile.am
View file @
59d6a9d0
...
...
@@ -3,7 +3,7 @@ if ENABLE_PYTHON
SWIG
=
swig
#python_SCRIPTS = pyUniSet.py pyUConnector.py pyUModbus.py pyUExceptions.py
pydir
=
$(pkgpythondir)
pydir
=
$(pkgpythondir)
/pyUniSet
py_DATA
=
pyUniSet.py pyUConnector.py pyUModbus.py pyUExceptions.py
BUILD_SRCDIR
=
$(srcdir)
/../../../core
...
...
wrappers/python/tests/UConnector/testUC.py
View file @
59d6a9d0
...
...
@@ -36,7 +36,7 @@ if __name__ == "__main__":
lst2
.
add_str
(
pstr2
)
p
=
[]
print
"lst: class: "
+
str
(
p
.
__class__
.
__name__
)
print
(
"lst: class: "
+
str
(
p
.
__class__
.
__name__
)
)
try
:
uc1
=
UConnector
(
lst
,
"test.xml"
)
...
...
@@ -49,19 +49,19 @@ if __name__ == "__main__":
uc1
.
activate_objects
()
while
True
:
print
"getValue(10):
%
d"
%
obj1
.
getValue
(
10
)
print
(
"getValue(10):
%
d"
%
obj1
.
getValue
(
10
)
)
time
.
sleep
(
1
)
# print "Info: %s"%uc1.getObjectInfo("TestProc1","")
print
"apiRequest:
%
s"
%
uc1
.
apiRequest
(
uc1
.
getObjectID
(
"SharedMemory"
),
"get?10"
)
print
(
"apiRequest:
%
s"
%
uc1
.
apiRequest
(
uc1
.
getObjectID
(
"SharedMemory"
),
"get?10"
)
)
# tc = uc1.getTimeChange(2)
# print "TimeChange: %s sup=%d"%(tc.value,tc.supplier)
# print "(0)UIType: %s" % uc1.getUIType()
print
"(1)getShortName: id=
%
d name=
%
s"
%
(
1
,
uc1
.
getShortName
(
1
))
print
"(2)getObjectID('TestProc'):
%
d"
%
uc1
.
getObjectID
(
"TestProc"
)
print
(
"(1)getShortName: id=
%
d name=
%
s"
%
(
1
,
uc1
.
getShortName
(
1
)
))
print
(
"(2)getObjectID('TestProc'):
%
d"
%
uc1
.
getObjectID
(
"TestProc"
)
)
# print " getName: id=%d name=%s" % (1, uc1.getName(101))
# print " getTextName: id=%d name=%s" % (1, uc1.getTextName(101))
...
...
@@ -71,20 +71,20 @@ if __name__ == "__main__":
# print " getTextName: id=%d name=%s" % (2, uc1.getTextName(109))
try
:
print
"(1)setValue:
%
d=
%
d"
%
(
3
,
22
)
print
(
"(1)setValue:
%
d=
%
d"
%
(
3
,
22
)
)
uc1
.
setValue
(
3
,
22
,
DefaultID
)
except
UException
,
e
:
print
"(1)setValue exception: "
+
str
(
e
.
getError
(
))
except
UException
as
e
:
print
(
"(1)setValue exception: "
+
str
(
e
.
getError
()
))
try
:
print
"(2)getValue:
%
d=
%
d"
%
(
3
,
uc1
.
getValue
(
3
,
DefaultID
)
)
except
UException
,
e
:
print
"(2)getValue exception: "
+
str
(
e
.
getError
(
))
print
(
"(2)getValue:
%
d=
%
d"
%
(
3
,
uc1
.
getValue
(
3
,
DefaultID
)
)
)
except
UException
as
e
:
print
(
"(2)getValue exception: "
+
str
(
e
.
getError
()
))
try
:
print
"(3)getValue:
%
d=
%
d"
%
(
100
,
uc1
.
getValue
(
100
,
DefaultID
)
)
except
UException
,
e
:
print
"(3)getValue exception: "
+
str
(
e
.
getError
(
))
print
(
"(3)getValue:
%
d=
%
d"
%
(
100
,
uc1
.
getValue
(
100
,
DefaultID
)
)
)
except
UException
as
e
:
print
(
"(3)getValue exception: "
+
str
(
e
.
getError
()
))
except
UException
,
e
:
print
"(testUI): catch exception: "
+
str
(
e
.
getError
(
))
except
UException
as
e
:
print
(
"(testUI): catch exception: "
+
str
(
e
.
getError
()
))
wrappers/python/tests/UHttp/testUHttp.py
View file @
59d6a9d0
...
...
@@ -25,8 +25,8 @@ if __name__ == "__main__":
# print shm.get(sensors='10,12')
# print shm.lost()
# print shm.help()
print
shm
.
sensors
(
0
,
10
)
print
(
shm
.
sensors
(
0
,
10
)
)
except
UHTTPError
,
e
:
print
e
.
message
except
UHTTPError
as
e
:
print
(
e
.
message
)
wrappers/python/tests/UInterface/testUI.py
View file @
59d6a9d0
...
...
@@ -32,29 +32,29 @@ if __name__ == "__main__":
obj1
.
askSensor
(
10
)
while
True
:
print
"sleep..."
print
"getValue:
%
d=
%
d"
%
(
10
,
obj1
.
getValue
(
10
))
print
(
"sleep..."
)
print
(
"getValue:
%
d=
%
d"
%
(
10
,
obj1
.
getValue
(
10
)
))
time
.
sleep
(
2
)
print
"getShortName: id=
%
d name=
%
s"
%
(
1
,
getShortName
(
1
))
print
" getName: id=
%
d name=
%
s"
%
(
1
,
getName
(
1
))
print
" getTextName: id=
%
d name=
%
s"
%
(
1
,
getTextName
(
1
))
print
"
\n
"
print
"getShortName: id=
%
d name=
%
s"
%
(
2
,
getShortName
(
2
))
print
" getName: id=
%
d name=
%
s"
%
(
2
,
getName
(
2
))
print
" getTextName: id=
%
d name=
%
s"
%
(
2
,
getTextName
(
2
))
print
" getObjectID: id=
%
d name=
%
s"
%
(
getObjectID
(
"TestProc"
),
"TestProc"
)
print
(
"getShortName: id=
%
d name=
%
s"
%
(
1
,
getShortName
(
1
)
))
print
(
" getName: id=
%
d name=
%
s"
%
(
1
,
getName
(
1
)
))
print
(
" getTextName: id=
%
d name=
%
s"
%
(
1
,
getTextName
(
1
)
))
print
(
"
\n
"
)
print
(
"getShortName: id=
%
d name=
%
s"
%
(
2
,
getShortName
(
2
)
))
print
(
" getName: id=
%
d name=
%
s"
%
(
2
,
getName
(
2
)
))
print
(
" getTextName: id=
%
d name=
%
s"
%
(
2
,
getTextName
(
2
)
))
print
(
" getObjectID: id=
%
d name=
%
s"
%
(
getObjectID
(
"TestProc"
),
"TestProc"
)
)
try
:
print
"getValue:
%
d=
%
d"
%
(
1
,
getValue
(
1
))
except
UException
,
e
:
print
"getValue exception: "
+
str
(
e
.
getError
(
))
print
(
"getValue:
%
d=
%
d"
%
(
1
,
getValue
(
1
)
))
except
UException
as
e
:
print
(
"getValue exception: "
+
str
(
e
.
getError
()
))
try
:
print
"setValue:
%
d=
%
d"
%
(
14
,
22
)
print
(
"setValue:
%
d=
%
d"
%
(
14
,
22
)
)
setValue
(
14
,
22
)
except
UException
,
e
:
print
"setValue exception: "
+
str
(
e
.
getError
(
))
except
UException
as
e
:
print
(
"setValue exception: "
+
str
(
e
.
getError
()
))
except
UException
,
e
:
print
"(testUI): catch exception: "
+
str
(
e
.
getError
(
))
except
UException
as
e
:
print
(
"(testUI): catch exception: "
+
str
(
e
.
getError
()
))
wrappers/python/tests/UModbus/testUModbus.py
View file @
59d6a9d0
...
...
@@ -14,27 +14,27 @@ if __name__ == "__main__":
try
:
mb
=
UModbus
()
print
"UIType:
%
s"
%
mb
.
getUIType
(
)
print
(
"UIType:
%
s"
%
mb
.
getUIType
()
)
mb
.
connect
(
"localhost"
,
2048
)
try
:
print
"Test READ functions..."
print
(
"Test READ functions..."
)
for
f
in
range
(
1
,
5
):
print
"func=
%
d reg=
%
d"
%
(
f
,
22
)
print
(
"func=
%
d reg=
%
d"
%
(
f
,
22
)
)
val
=
mb
.
mbread
(
0x01
,
22
,
f
,
"unsigned"
,
-
1
)
# val = mb.mbread(0x01,22)
print
"val=
%
d"
%
val
print
(
"val=
%
d"
%
val
)
print
"getWord:
%
d"
%
mb
.
getWord
(
0x01
,
22
)
print
"getByte:
%
d"
%
mb
.
getByte
(
0x01
,
22
)
print
"getBit:
%
d"
%
mb
.
getBit
(
0x01
,
22
,
3
)
print
(
"getWord:
%
d"
%
mb
.
getWord
(
0x01
,
22
)
)
print
(
"getByte:
%
d"
%
mb
.
getByte
(
0x01
,
22
)
)
print
(
"getBit:
%
d"
%
mb
.
getBit
(
0x01
,
22
,
3
)
)
# print ""
# print "Test WRITE functions..."
# for f in range(1,6):
# print "func=%d reg=%d" % (f,22)
# val = mb.getValue(f,0x01,22,"unsigned",-1)
except
UException
,
e
:
print
"exception: "
+
str
(
e
.
getError
(
))
except
UException
as
e
:
print
(
"exception: "
+
str
(
e
.
getError
()
))
except
UException
,
e
:
print
"(testUModbus): catch exception: "
+
str
(
e
.
getError
(
))
except
UException
as
e
:
print
(
"(testUModbus): catch exception: "
+
str
(
e
.
getError
()
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment