Exemplo n.º 1
0
    def confirmation(self, pdu):
        """Got a response from the server."""
        if _debug: ModbusClient._debug("confirmation %r", pdu)

        # generic decode
        mpdu = MPDU()
        mpdu.decode(pdu)
        if _debug: ModbusClient._debug("    - mpdu: %r", mpdu)

        # we don't know anything but MODBUS
        if (mpdu.mpduProtocolID != 0):
            return

        # may be sending a problem
        if (mpdu.mpduFunctionCode >= 128):
            klass = ExceptionResponse
        else:
            klass = response_types.get(mpdu.mpduFunctionCode, None)
            if not klass:
                return

        resp = klass()
        resp.decode(mpdu)
        if _debug: ModbusClient._debug("    - resp: %r", resp)

        # pass it along to the application
        self.response(resp)
Exemplo n.º 2
0
    def sap_confirmation(self, resp):
        """Got a response from the ASE."""
        if _debug: ModbusServiceAccessPoint._debug("sap_confirmation %r", resp)

        mpdu = MPDU()
        resp.encode(mpdu)
        if _debug: ModbusServiceAccessPoint._debug("    - mpdu: %r", mpdu)

        pdu = PDU()
        mpdu.encode(pdu)
        if _debug: ModbusServiceAccessPoint._debug("    - pdu: %r", pdu)

        # return the response to the device
        self.response(pdu)
Exemplo n.º 3
0
    def sap_indication(self, req):
        """Got a request from the ASE."""
        if _debug: ModbusServiceAccessPoint._debug("sap_indication %r", req)

        mpdu = MPDU()
        req.encode(mpdu)
        if _debug: ModbusServiceAccessPoint._debug("    - mpdu: %r", mpdu)

        pdu = PDU()
        mpdu.encode(pdu)
        if _debug: ModbusServiceAccessPoint._debug("    - pdu: %r", pdu)

        # pass it along to the device
        self.request(pdu)
Exemplo n.º 4
0
    def indication(self, resp):
        """This is a response from the application."""
        if _debug: ModbusServer._debug("indication %r", resp)

        # encode as a generic MPDU
        mpdu = MPDU()
        resp.encode(mpdu)
        if _debug: ModbusServer._debug("    - mpdu: %r", mpdu)

        # encode as a generic PDU
        pdu = PDU()
        mpdu.encode(pdu)
        if _debug: ModbusServer._debug("    - pdu: %r", pdu)

        # return the response to the device
        self.request(pdu)
Exemplo n.º 5
0
    def indication(self, req):
        """Got a request from the application."""
        if _debug: ModbusClient._debug("indication %r", req)

        # encode it as a generic MPDU
        mpdu = MPDU()
        req.encode(mpdu)
        if _debug: ModbusClient._debug("    - mpdu: %r", mpdu)

        # encode it as a PDU
        pdu = PDU()
        mpdu.encode(pdu)
        if _debug: ModbusClient._debug("    - pdu: %r", pdu)

        # pass it along to the device
        self.request(pdu)
Exemplo n.º 6
0
    def confirmation(self, pdu):
        """This is a request from a client."""
        if _debug: ModbusServer._debug("confirmation %r", pdu)

        # generic decoding
        mpdu = MPDU()
        mpdu.decode(pdu)
        if _debug: ModbusServer._debug("    - mpdu: %r", mpdu)

        # we don't know anything but MODBUS
        if (mpdu.mpduProtocolID != 0):
            return

        # clients shouldn't be sending exceptions
        if (mpdu.mpduFunctionCode >= 128):
            return

        # map the function code
        klass = request_types.get(mpdu.mpduFunctionCode, None)
        if not klass:
            # create an error for now
            resp = ExceptionResponse(
                mpdu.mpduFunctionCode,
                ExceptionResponse.ILLEGAL_FUNCTION,
                )

            # match the transaction information
            resp.pduDestination = mpdu.pduSource
            resp.mpduTransactionID = mpdu.mpduTransactionID
            if _debug: ModbusServer._debug("    - resp: %r", resp)

            # return the response to the device
            self.request(resp)

        req = klass()
        req.decode(mpdu)
        if _debug: ModbusServer._debug("    - req: %r", req)

        # pass it along to the application
        self.response(req)