2
2
This module provides a class for interfacing with digital, analog and PWM plugins.
3
3
"""
4
4
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
6
6
7
7
8
8
class InputOutput ():
@@ -62,16 +62,19 @@ def read(self, channel, value_type=None):
62
62
63
63
def read_value (self , channel , value_type = None ):
64
64
"""Read the data value on the specified channel."""
65
+ result = None
65
66
self .set_plugin ()
67
+ if not self .plugin :
68
+ error ('Plugin {} is not loaded' .format (self .plugin_id ))
69
+ return result
66
70
self .set_function (channel )
67
- result = None
68
71
try :
69
72
read_args = self .read_args
70
73
if value_type :
71
74
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 )
73
76
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 ))
75
78
return result
76
79
77
80
def write (self , value , channel , value_type = None ):
@@ -80,16 +83,19 @@ def write(self, value, channel, value_type=None):
80
83
81
84
def write_value (self , value , channel , value_type = None ):
82
85
"""Write the data value on the specified channel."""
86
+ result = None
83
87
self .set_plugin ()
88
+ if not self .plugin :
89
+ error ('Plugin {} not loaded' .format (self .plugin_id ))
90
+ return result
84
91
self .set_function (channel )
85
- result = None
86
92
try :
87
93
write_args = self .write_args
88
94
if value_type :
89
95
write_args ['value_type' ] = value_type
90
96
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 ) )
93
99
return result
94
100
95
101
def register_callback (self , callback ):
0 commit comments