Skip to content

Commit 631551f

Browse files
committed
Display error when plugin instance is not found.
1 parent 8971bae commit 631551f

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

myDevices/plugins/io.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
This module provides a class for interfacing with digital, analog and PWM plugins.
33
"""
44
from myDevices.plugins.manager import PluginManager
5-
from myDevices.utils.logger import debug, info, exception
5+
from myDevices.utils.logger import debug, info, error, exception
66

77

88
class InputOutput():
@@ -62,16 +62,19 @@ def read(self, channel, value_type=None):
6262

6363
def read_value(self, channel, value_type=None):
6464
"""Read the data value on the specified channel."""
65+
result = None
6566
self.set_plugin()
67+
if not self.plugin:
68+
error('Plugin {} is not loaded'.format(self.plugin_id))
69+
return result
6670
self.set_function(channel)
67-
result = None
6871
try:
6972
read_args = self.read_args
7073
if value_type:
7174
read_args['value_type'] = value_type
72-
result = getattr(self.plugin['instance'], self.plugin['read'])(channel, **read_args)
75+
result = getattr(self.plugin['instance'], self.plugin['read'])(channel, **read_args)
7376
except:
74-
exception('Error reading value from plugin {}, channel {}, {}'.format(self.plugin_id, channel, self.plugin))
77+
error('Error reading value from plugin {}, channel {}'.format(self.plugin_id, channel))
7578
return result
7679

7780
def write(self, value, channel, value_type=None):
@@ -80,16 +83,19 @@ def write(self, value, channel, value_type=None):
8083

8184
def write_value(self, value, channel, value_type=None):
8285
"""Write the data value on the specified channel."""
86+
result = None
8387
self.set_plugin()
88+
if not self.plugin:
89+
error('Plugin {} not loaded'.format(self.plugin_id))
90+
return result
8491
self.set_function(channel)
85-
result = None
8692
try:
8793
write_args = self.write_args
8894
if value_type:
8995
write_args['value_type'] = value_type
9096
result = getattr(self.plugin['instance'], self.plugin['write'])(channel, value, **write_args)
91-
except ValueError as e:
92-
debug(e)
97+
except:
98+
error('Error writing value to plugin {}, channel {}'.format(self.plugin_id, channel))
9399
return result
94100

95101
def register_callback(self, callback):

0 commit comments

Comments
 (0)