|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 |
|
3 | 3 | VERSION = '0.1.8' |
4 | | -## ModBus/TCP |
| 4 | +# ModBus/TCP |
5 | 5 | MODBUS_PORT = 502 |
6 | | -## Modbus mode |
| 6 | +# Modbus mode |
7 | 7 | MODBUS_TCP = 1 |
8 | 8 | MODBUS_RTU = 2 |
9 | | -## Modbus function code |
| 9 | +# Modbus function code |
10 | 10 | # standard |
11 | 11 | READ_COILS = 0x01 |
12 | 12 | READ_DISCRETE_INPUTS = 0x02 |
|
17 | 17 | WRITE_MULTIPLE_COILS = 0x0F |
18 | 18 | WRITE_MULTIPLE_REGISTERS = 0x10 |
19 | 19 | MODBUS_ENCAPSULATED_INTERFACE = 0x2B |
20 | | -## Modbus except code |
| 20 | +# Modbus except code |
21 | 21 | EXP_NONE = 0x00 |
22 | 22 | EXP_ILLEGAL_FUNCTION = 0x01 |
23 | 23 | EXP_DATA_ADDRESS = 0x02 |
24 | 24 | EXP_DATA_VALUE = 0x03 |
25 | 25 | EXP_SLAVE_DEVICE_FAILURE = 0x04 |
26 | 26 | EXP_ACKNOWLEDGE = 0x05 |
27 | 27 | EXP_SLAVE_DEVICE_BUSY = 0x06 |
| 28 | +EXP_NEGATIVE_ACKNOWLEDGE = 0x07 |
28 | 29 | EXP_MEMORY_PARITY_ERROR = 0x08 |
29 | 30 | EXP_GATEWAY_PATH_UNAVAILABLE = 0x0A |
30 | 31 | EXP_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND = 0x0B |
31 | | -## Module error codes |
| 32 | +# Exception as short human readable |
| 33 | +EXP_TXT = { |
| 34 | + EXP_NONE: 'no exception', |
| 35 | + EXP_ILLEGAL_FUNCTION: 'illegal function', |
| 36 | + EXP_DATA_ADDRESS: 'illegal data address', |
| 37 | + EXP_DATA_VALUE: 'illegal data value', |
| 38 | + EXP_SLAVE_DEVICE_FAILURE: 'slave device failure', |
| 39 | + EXP_ACKNOWLEDGE: 'acknowledge', |
| 40 | + EXP_SLAVE_DEVICE_BUSY: 'slave device busy', |
| 41 | + EXP_NEGATIVE_ACKNOWLEDGE: 'negative acknowledge', |
| 42 | + EXP_MEMORY_PARITY_ERROR: 'memory parity error', |
| 43 | + EXP_GATEWAY_PATH_UNAVAILABLE: 'gateway path unavailable', |
| 44 | + EXP_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND: 'gateway target device failed to respond' |
| 45 | +} |
| 46 | +# Exception as details human readable |
| 47 | +EXP_DETAILS = { |
| 48 | + EXP_NONE: 'The last request produced no exceptions.', |
| 49 | + EXP_ILLEGAL_FUNCTION: 'Function code received in the query is not recognized or allowed by slave.', |
| 50 | + EXP_DATA_ADDRESS: 'Data address of some or all the required entities are not allowed or do not exist in slave.', |
| 51 | + EXP_DATA_VALUE: 'Value is not accepted by slave.', |
| 52 | + EXP_SLAVE_DEVICE_FAILURE: 'Unrecoverable error occurred while slave was attempting to perform requested action.', |
| 53 | + EXP_ACKNOWLEDGE: 'Slave has accepted request and is processing it, but a long duration of time is required. ' |
| 54 | + 'This response is returned to prevent a timeout error from occurring in the master. ' |
| 55 | + 'Master can next issue a Poll Program Complete message to determine whether processing is completed.', |
| 56 | + EXP_SLAVE_DEVICE_BUSY: 'Slave is engaged in processing a long-duration command. Master should retry later.', |
| 57 | + EXP_NEGATIVE_ACKNOWLEDGE: 'Slave cannot perform the programming functions. ' |
| 58 | + 'Master should request diagnostic or error information from slave.', |
| 59 | + EXP_MEMORY_PARITY_ERROR: 'Slave detected a parity error in memory. ' |
| 60 | + 'Master can retry the request, but service may be required on the slave device.', |
| 61 | + EXP_GATEWAY_PATH_UNAVAILABLE: 'Specialized for Modbus gateways, this indicates a misconfigured gateway.', |
| 62 | + EXP_GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND: 'Specialized for Modbus gateways, sent when slave fails to respond.' |
| 63 | +} |
| 64 | +# Module error codes |
32 | 65 | MB_NO_ERR = 0 |
33 | 66 | MB_RESOLVE_ERR = 1 |
34 | 67 | MB_CONNECT_ERR = 2 |
|
38 | 71 | MB_FRAME_ERR = 6 |
39 | 72 | MB_EXCEPT_ERR = 7 |
40 | 73 | MB_CRC_ERR = 8 |
| 74 | +MB_SOCK_CLOSE_ERR = 9 |
| 75 | +# Module error as short human readable |
| 76 | +MB_ERR_TXT = { |
| 77 | + MB_NO_ERR: 'no error', |
| 78 | + MB_RESOLVE_ERR: 'name resolve error', |
| 79 | + MB_CONNECT_ERR: 'connect error', |
| 80 | + MB_SEND_ERR: 'socket send error', |
| 81 | + MB_RECV_ERR: 'socket recv error', |
| 82 | + MB_TIMEOUT_ERR: 'recv timeout occur', |
| 83 | + MB_FRAME_ERR: 'frame format error', |
| 84 | + MB_EXCEPT_ERR: 'modbus exception occur', |
| 85 | + MB_CRC_ERR: 'bad CRC on receive frame', |
| 86 | + MB_SOCK_CLOSE_ERR: 'socket is closed' |
| 87 | +} |
0 commit comments