Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SADAPMAP
Interface
Commits
19b1556f
Commit
19b1556f
authored
Apr 29, 2019
by
Pedro Henrique Kopper
Browse files
Added new protobuf module
parent
347b7107
Changes
4
Hide whitespace changes
Inline
Side-by-side
config.yaml
View file @
19b1556f
# Este arquivo define a interface a ser utilizada
device
:
type
:
arduino
type
:
mock
location
:
"
/dev/ttyUSB0"
channels
:
-
id
:
0
...
...
@@ -10,4 +10,4 @@ device:
-
id
:
1
name
:
"
Corrente"
color
:
"
#0000FF"
unit
:
"
mA"
\ No newline at end of file
unit
:
"
mA"
interfaces/InstrumentInterface.py
0 → 100644
View file @
19b1556f
from
serial
import
Serial
from
interfaces.Protocol.sadapmap_pb2
import
MultiChannelReading
,
ReqMultiChannelReading
class
InstrumentInterface
(
object
):
def
__init__
(
self
,
logger
,
location
,
channels
):
self
.
channels
=
channels
self
.
logger
=
logger
logger
(
"[ARDUINO]"
,
"Opening serial port..."
)
try
:
self
.
ser
=
Serial
(
location
,
115200
,
timeout
=
0.05
)
except
Exception
as
e
:
logger
(
"[ARDUINO]"
,
"ERROR: Could not open serial port"
)
raise
FileNotFoundError
(
"Serial port not found"
)
from
e
logger
(
"[ARDUINO]"
,
"Board started, good luck!"
)
def
read
(
self
):
pass
def
readAll
(
self
):
self
.
ser
.
flushInput
()
# Limpeza do buffer de entrada
req
=
ReqMultiChannelReading
()
[
req
.
id
.
append
(
i
[
'id'
])
for
i
in
self
.
channels
]
self
.
ser
.
flushInput
()
self
.
ser
.
write
(
req
.
SerializeToString
())
reading
=
MultiChannelReading
()
data
=
self
.
ser
.
read
(
128
)
try
:
reading
.
ParseFromString
(
data
)
except
:
self
.
logger
(
"[ARDUINO]"
,
"Got invalid data"
)
return
[
0
for
i
in
range
(
len
(
self
.
channels
))]
if
len
(
reading
.
channels
)
!=
len
(
self
.
channels
):
self
.
logger
(
"[ARDUINO]"
,
"Got null data"
)
return
[
0
for
i
in
range
(
len
(
self
.
channels
))]
return
[
i
.
value
for
i
in
reading
.
channels
]
\ No newline at end of file
interfaces/__init__.py
View file @
19b1556f
...
...
@@ -2,8 +2,10 @@
from
interfaces.Mock
import
*
from
interfaces.Arduino
import
*
from
interfaces.InstrumentInterface
import
*
INTERFACES
=
{
'mock'
:
Mock
,
'arduino'
:
Arduino
'arduino'
:
Arduino
,
'instrument-interface'
:
InstrumentInterface
,
}
test_protobuf.py
View file @
19b1556f
...
...
@@ -6,7 +6,7 @@ with serial.Serial("/dev/ttyUSB0", 115200, timeout=0.1) as ser:
print
(
"Opened serial"
)
while
True
:
req
=
ReqMultiChannelReading
()
req
.
id
.
append
(
0
)
req
.
id
.
append
(
1
)
ser
.
flushInput
()
ser
.
write
(
req
.
SerializeToString
())
reading
=
MultiChannelReading
()
...
...
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