Skip to content

Commit

Permalink
Remove some non-ASCII characters.
Browse files Browse the repository at this point in the history
  • Loading branch information
OrangeTux committed Nov 9, 2015
1 parent 4754c7a commit 0e84d24
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions umodbus/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,19 @@ def pack_mbap(transaction_id, protocol_id, length, unit_id):
return struct.pack('>HHHB', transaction_id, protocol_id, length, unit_id)


def get_function_code_from_request_pdu(pdu):
""" Return function code from request PDU.
:return pdu: Array with bytes.
:return: Function code.
"""
return struct.unpack('>B', pdu[:1])[0]


def pack_exception_pdu(function_code, error_code):
""" Return exception PDU of 2 bytes.
"The exception response message has two fields that differentiate it
from a nor mal response: Function Code Field: In a normal response, the
server echoes the function code of the original request in the function
code field of the response. All function codes have a most significant
code field of the response. All function codes have a most - significant
bit (MSB) of 0 (their values are all below 80 hexadecimal). In an
exception response, the server sets the MSB of the function code to 1.
This makes the function code value in an exception response exactly 80
hexadecimal higher than the value would be for a normal response.
With the function codes MSB set, the client's application program can
With the function code's MSB set, the client's application program can
recognize the exception response and can examine the data field for the
exception code. Data Field: In a normal response, the server may return
data or statistics in the data field (any information that was requested
Expand All @@ -99,6 +90,15 @@ def pack_exception_pdu(function_code, error_code):
return struct.pack('>BB', function_code + 0x80, error_code)


def get_function_code_from_request_pdu(pdu):
""" Return function code from request PDU.
:return pdu: Array with bytes.
:return: Function code.
"""
return struct.unpack('>B', pdu[:1])[0]


def memoize(f):
""" Decorator which caches function's return value each it is called.
If called later with same arguments, the cached value is returned.
Expand Down

0 comments on commit 0e84d24

Please sign in to comment.