Exemple #1
0
    def test_get_variable_width_object_from_serial_port(self):
        pn = MockSerialPortNode()

        #pn.debug = 5

        # Initialize some data to be 'read' from our mock serial port node.
        for x in chr(0x03) + chr(0xAA) + chr(0x03) + chr(0xFF):
            pn.addbuffer(ord(x))

        #print pn.get_buffer_str()
        
        conn = gc.FrameworkSerialPortWrapper(pn)

        lines = "" \
                "# Variable Buffer 1 Class\n" \
                "class testvbuffer1 {\n" \
                "   vbuffer1 vbuffer01;\n" \
                "}\n"


        lines = lines.split('\n')

        pc = ProtoCompiler()

        pc.parseLines(lines)

        c = pc.emitCode()

        pyfilename = os.path.join(properties.TEMP_DIR, "testvbuffer1.py")

        f = open(pyfilename, 'w')
        f.write(c)
        f.close()

        # Now try to import it.
        import testvbuffer1

        request_obj = testvbuffer1.testvbuffer1()
        response_obj = testvbuffer1.testvbuffer1()

        req_vbuffer_obj = request_obj.findChildByName('vbuffer01')
        #
        resp_vbuffer_obj = response_obj.findChildByName('vbuffer01')
        
        lh = gdlh.SimpleLineHandler(conn)

        req_vbuffer_obj.setValue("abc")

        res = lh.send_request_with_response(request_obj, response_obj, 30)

        assert res == 1, "send_request_with_response() should have returned 1."

        assert resp_vbuffer_obj.getValue() == chr(0xAA) + chr(0x03) + chr(0xFF), "Did not get expected value."
        
        os.remove(pyfilename)
Exemple #2
0
    def test_get_variable_width_object_from_serial_port(self):
        pn = MockSerialPortNode()

        #pn.debug = 5

        # Initialize some data to be 'read' from our mock serial port node.
        for x in chr(0x03) + chr(0xAA) + chr(0x03) + chr(0xFF):
            pn.addbuffer(ord(x))

        #print pn.get_buffer_str()

        conn = gc.FrameworkSerialPortWrapper(pn)

        lines = "" \
                "# Variable Buffer 1 Class\n" \
                "class testvbuffer1 {\n" \
                "   vbuffer1 vbuffer01;\n" \
                "}\n"

        lines = lines.split('\n')

        pc = ProtoCompiler()

        pc.parseLines(lines)

        c = pc.emitCode()

        pyfilename = os.path.join(properties.TEMP_DIR, "testvbuffer1.py")

        f = open(pyfilename, 'w')
        f.write(c)
        f.close()

        # Now try to import it.
        import testvbuffer1

        request_obj = testvbuffer1.testvbuffer1()
        response_obj = testvbuffer1.testvbuffer1()

        req_vbuffer_obj = request_obj.findChildByName('vbuffer01')
        #
        resp_vbuffer_obj = response_obj.findChildByName('vbuffer01')

        lh = gdlh.SimpleLineHandler(conn)

        req_vbuffer_obj.setValue("abc")

        res = lh.send_request_with_response(request_obj, response_obj, 30)

        assert res == 1, "send_request_with_response() should have returned 1."

        assert resp_vbuffer_obj.getValue(
        ) == chr(0xAA) + chr(0x03) + chr(0xFF), "Did not get expected value."

        os.remove(pyfilename)
Exemple #3
0
    def test_get_fixed_width_object_from_serial_port(self):
        pn = MockSerialPortNode()

        #pn.debug = 5

        # Initialize some data to be 'read' from our mock serial port node.
        for x in chr(0xAA) + chr(0x03) + chr(0xFF):
            pn.addbuffer(ord(x))

        #print pn.get_buffer_str()
        
        conn = gc.FrameworkSerialPortWrapper(pn)

        lines = "" \
                "# Single byte Class\n" \
                "class singlebyte {\n" \
                "   uint8 preamble = 0xAA;\n" \
                "   uint8 data;\n" \
                "   uint8 postamble = 0xFF;\n" \
                "}\n"

        lines = lines.split('\n')

        pc = ProtoCompiler()

        pc.parseLines(lines)

        c = pc.emitCode()

        pyfilename = os.path.join(properties.TEMP_DIR, "singlebyte.py")

        f = open(pyfilename, 'w')
        f.write(c)
        f.close()

        # Now try to import it.
        import singlebyte

        request_obj = singlebyte.singlebyte()
        response_obj = singlebyte.singlebyte()

        req_data_obj = request_obj.findChildByName('data')
        #
        resp_data_obj = response_obj.findChildByName('data')
        
        lh = gdlh.SimpleLineHandler(conn)

        req_data_obj.setValue(0x01)

        res = lh.send_request_with_response(request_obj, response_obj, 30)

        #print res
        
        os.remove(pyfilename)
Exemple #4
0
    def test_get_fixed_width_object_from_serial_port(self):
        pn = MockSerialPortNode()

        #pn.debug = 5

        # Initialize some data to be 'read' from our mock serial port node.
        for x in chr(0xAA) + chr(0x03) + chr(0xFF):
            pn.addbuffer(ord(x))

        #print pn.get_buffer_str()

        conn = gc.FrameworkSerialPortWrapper(pn)

        lines = "" \
                "# Single byte Class\n" \
                "class singlebyte {\n" \
                "   uint8 preamble = 0xAA;\n" \
                "   uint8 data;\n" \
                "   uint8 postamble = 0xFF;\n" \
                "}\n"

        lines = lines.split('\n')

        pc = ProtoCompiler()

        pc.parseLines(lines)

        c = pc.emitCode()

        pyfilename = os.path.join(properties.TEMP_DIR, "singlebyte.py")

        f = open(pyfilename, 'w')
        f.write(c)
        f.close()

        # Now try to import it.
        import singlebyte

        request_obj = singlebyte.singlebyte()
        response_obj = singlebyte.singlebyte()

        req_data_obj = request_obj.findChildByName('data')
        #
        resp_data_obj = response_obj.findChildByName('data')

        lh = gdlh.SimpleLineHandler(conn)

        req_data_obj.setValue(0x01)

        res = lh.send_request_with_response(request_obj, response_obj, 30)

        #print res

        os.remove(pyfilename)