|
10 | 10 | except ImportError: |
11 | 11 | pass |
12 | 12 |
|
13 | | -from pymodbus.interfaces import IModbusSlaveContext |
| 13 | +from pymodbus.datastore import ModbusBaseSlaveContext |
14 | 14 | from pymodbus.logging import Log |
15 | 15 |
|
16 | 16 |
|
17 | 17 | # --------------------------------------------------------------------------- # |
18 | 18 | # Context |
19 | 19 | # --------------------------------------------------------------------------- # |
20 | | -class SqlSlaveContext(IModbusSlaveContext): |
| 20 | +class SqlSlaveContext(ModbusBaseSlaveContext): |
21 | 21 | """This creates a modbus data model with each data access in its a block.""" |
22 | 22 |
|
23 | 23 | def __init__(self, *args, **kwargs): # pylint: disable=unused-argument |
@@ -45,44 +45,44 @@ def reset(self): |
45 | 45 | self._metadata.drop_all(None) |
46 | 46 | self._db_create(self.table, self.database) |
47 | 47 |
|
48 | | - def validate(self, fx, address, count=1): |
| 48 | + def validate(self, fc, address, count=1): |
49 | 49 | """Validate the request to make sure it is in range. |
50 | 50 |
|
51 | | - :param fx: The function we are working with |
| 51 | + :param fc: The function we are working with |
52 | 52 | :param address: The starting address |
53 | 53 | :param count: The number of values to test |
54 | 54 | :returns: True if the request in within range, False otherwise |
55 | 55 | """ |
56 | 56 | address = address + 1 # section 4.4 of specification |
57 | | - Log.debug("validate[{}] {}:{}", fx, address, count) |
58 | | - return self._validate(self.decode(fx), address, count) |
| 57 | + Log.debug("validate[{}] {}:{}", fc, address, count) |
| 58 | + return self._validate(self.decode(fc), address, count) |
59 | 59 |
|
60 | | - def getValues(self, fx, address, count=1): |
| 60 | + def getValues(self, fc, address, count=1): |
61 | 61 | """Get `count` values from datastore. |
62 | 62 |
|
63 | | - :param fx: The function we are working with |
| 63 | + :param fc: The function we are working with |
64 | 64 | :param address: The starting address |
65 | 65 | :param count: The number of values to retrieve |
66 | 66 | :returns: The requested values from a:a+c |
67 | 67 | """ |
68 | 68 | address = address + 1 # section 4.4 of specification |
69 | | - Log.debug("get-values[{}] {}:{}", fx, address, count) |
70 | | - return self._get(self.decode(fx), address, count) |
| 69 | + Log.debug("get-values[{}] {}:{}", fc, address, count) |
| 70 | + return self._get(self.decode(fc), address, count) |
71 | 71 |
|
72 | | - def setValues(self, fx, address, values, update=True): |
| 72 | + def setValues(self, fc, address, values, update=True): |
73 | 73 | """Set the datastore with the supplied values. |
74 | 74 |
|
75 | | - :param fx: The function we are working with |
| 75 | + :param fc: The function we are working with |
76 | 76 | :param address: The starting address |
77 | 77 | :param values: The new values to be set |
78 | 78 | :param update: Update existing register in the db |
79 | 79 | """ |
80 | 80 | address = address + 1 # section 4.4 of specification |
81 | | - Log.debug("set-values[{}] {}:{}", fx, address, len(values)) |
| 81 | + Log.debug("set-values[{}] {}:{}", fc, address, len(values)) |
82 | 82 | if update: |
83 | | - self._update(self.decode(fx), address, values) |
| 83 | + self._update(self.decode(fc), address, values) |
84 | 84 | else: |
85 | | - self._set(self.decode(fx), address, values) |
| 85 | + self._set(self.decode(fc), address, values) |
86 | 86 |
|
87 | 87 | # ----------------------------------------------------------------------- # |
88 | 88 | # Sqlite Helper Methods |
|
0 commit comments