Exemple #1
0
        public void SendStringData()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(new byte[] { 0xF0, 0x71 });
            connection.EnqueueRequest("Test".To14BitIso());
            connection.EnqueueRequest(new byte[] { 0xF7 });
            session.SendStringData("Test");
        }
        public void ReadI2COnce_BytesToRead_Parameter_IsNegative()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x00, 0x08, 0x00, 0x00, 0xF7);
            session.ReadI2COnce(0, -1);
        }
        public void ReadI2COnce_SlaveRegister_Parameter_Is0x4000()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x00, 0x08, 0x00, 0x00, 0xF7);
            session.ReadI2COnce(0, 0x4000, 1);
        }
        public void ReadI2COnce_MinimumParameters()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x00, 0x08, 0x00, 0x00, 0xF7);
            session.ReadI2COnce(0, 0);
        }
        public void ReadI2COnce_MaximumParameters_WithSlaveRegister()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x7F, 0x2F, 0x7F, 0x7F, 0x7F, 0x7F, 0xF7);
            session.ReadI2COnce(0x3FF, 0x3FFF, 0x3FFF);
        }
        public void ReadI2CContinous_WithSlaveRegister()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x45, 0x10, 0x07, 0x0C, 0x7F, 0x01, 0xF7);
            session.ReadI2CContinuous(0x45, 0x0607, 255);
        }
        public void StopI2CReading()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x00, 0x18, 0xF7);
            session.StopI2CReading();
        }
        public void WriteI2C_SlaveAddress_Parameter_Is0x3FF()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x7F, 0x27, 0x7F, 0x01, 0xF7);
            session.WriteI2C(0x3FF, 255);
        }
        public void WriteI2C_SlaveAddress_Parameter_Is127()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x7F, 0x00, 0x11, 0x00, 0x22, 0x00, 0x33, 0x00, 0x44, 0x00, 0x7F, 0x01, 0xF7);
            session.WriteI2C(127, 0x11, 0x22, 0x33, 0x44, 0xFF);
        }
Exemple #10
0
        public void WriteI2C_SlaveAddress_Parameter_IsNegative()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x02, 0x21, 0xF7);
            session.WriteI2C(-1);
        }
Exemple #11
0
        public void SetDigitalPin_Level_Is0_PinNumber_Argument_Is16()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x6F, 0x10, 0x00, 0x00, 0xF7);
            session.SetDigitalPin(16, 0);
        }
Exemple #12
0
        public void SendStringData_NullString()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x71, 0xF7);
            session.SendStringData(null);
        }
        public void WriteI2C_SlaveAddress_Parameter_Is0x3FF()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x7F, 0x27, 0x7F, 0x01, 0xF7);
            session.WriteI2C(0x3FF, 255);
        }
Exemple #14
0
        public void WriteI2C_Data_Parameter_IsNull()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x02, 0x21, 0xF7);
            session.WriteI2C(130);
        }
Exemple #15
0
        //[TestMethod]
        //[ExpectedException(typeof(TimeoutException))]
        public void TimedoutResponse()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection, 550);

            connection.EnqueueRequest(0xF0, 0x6B, 0xF7);

            session.GetBoardCapability();
        }
Exemple #16
0
        public void GetI2CReply_BytesToRead_Parameter_Is0()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x01, 0x08, 0x00, 0x00, 0xF7);
            connection.EnqueueResponse(0xF0, 0x77, 0x01, 0x00, 0x00, 0x00, 0xF7);
            I2CReply reply = session.GetI2CReply(1, 0);

            Assert.AreEqual(1, reply.Address);
            Assert.AreEqual(0, reply.Register);
            Assert.AreEqual(0, reply.Data.Length);
        }
Exemple #17
0
        public void GetI2CReply_WithSlaveRegister()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x01, 0x08, 0x02, 0x00, 0x01, 0x00, 0xF7);
            connection.EnqueueResponse(0xF0, 0x77, 0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0xF7);
            I2CReply reply = session.GetI2CReply(1, 2, 1);

            Assert.AreEqual(1, reply.Address);
            Assert.AreEqual(2, reply.Register);
            Assert.AreEqual(1, reply.Data.Length);
            Assert.AreEqual(4, reply.Data[0]);
        }
Exemple #18
0
        public void GetI2CReplyAsync_WithSlaveRegister()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x7F, 0x08, 0x04, 0x02, 0x02, 0x00, 0xF7);
            connection.EnqueueResponse(0xF0, 0x77, 0x7F, 0x00, 0x04, 0x02, 0x7F, 0x01, 0x7E, 0x01, 0xF7);
            I2CReply reply = session.GetI2CReplyAsync(127, 260, 2).Result;

            Assert.AreEqual(127, reply.Address);
            Assert.AreEqual(260, reply.Register);
            Assert.AreEqual(2, reply.Data.Length);
            Assert.AreEqual(255, reply.Data[0]);
            Assert.AreEqual(254, reply.Data[1]);
        }
Exemple #19
0
        public void GetI2CReply()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x01, 0x08, 0x03, 0x00, 0xF7);
            connection.EnqueueResponse(0xF0, 0x77, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0xF7);
            I2CReply reply = session.GetI2CReply(1, 3);

            Assert.AreEqual(1, reply.Address);
            Assert.AreEqual(0, reply.Register);
            Assert.AreEqual(3, reply.Data.Length);
            Assert.AreEqual(5, reply.Data[0]);
            Assert.AreEqual(6, reply.Data[1]);
            Assert.AreEqual(7, reply.Data[2]);
        }
Exemple #20
0
        public void Receive_StringDataMessage()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);
            int eventHits  = 0;

            session.MessageReceived += (o, e) =>
            {
                Assert.AreEqual(MessageType.StringData, e.Value.Type);
                Assert.AreEqual("Hello!", ((StringData)e.Value.Value).Text);
                eventHits++;
            };

            connection.EnqueueRequest(0xF0, 0x71, 0xF7);
            connection.EnqueueResponse(0xF0, 0x71, 0x48, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x21, 0x00, 0xF7);
            session.SendStringData(null);
            Assert.AreEqual(1, eventHits, "MessageReceived event not hit once.");
        }
Exemple #21
0
        public void I2CReplyReceived()
        {
            var connection = new MockSerialConnection();
            var session    = CreateFirmataSession(connection);
            int eventHits  = 0;

            session.I2CReplyReceived += (o, e) =>
            {
                Assert.AreEqual(1, e.Value.Address);
                Assert.AreEqual(0, e.Value.Register);
                Assert.AreEqual(3, e.Value.Data.Length);
                Assert.AreEqual(5, e.Value.Data[0]);
                Assert.AreEqual(6, e.Value.Data[1]);
                Assert.AreEqual(7, e.Value.Data[2]);
                eventHits++;
            };

            connection.EnqueueRequest(0xF0, 0x76, 0x01, 0x08, 0x03, 0x00, 0xF7);
            connection.EnqueueResponse(0xF0, 0x77, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0xF7);
            I2CReply reply = session.GetI2CReply(1, 3);

            Assert.AreEqual(1, eventHits);
        }
        public void ReadI2COnce_BytesToRead_Parameter_IsNegative()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x00, 0x08, 0x00, 0x00, 0xF7);
            session.ReadI2COnce(0, -1);
        }
        public void ReadI2COnce_SlaveRegister_Parameter_Is0x4000()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x00, 0x08, 0x00, 0x00, 0xF7);
            session.ReadI2COnce(0, 0x4000, 1);
        }
        public void ReadI2COnce_MinimumParameters()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x00, 0x08, 0x00, 0x00, 0xF7);
            session.ReadI2COnce(0, 0);
        }
        public void GetI2CReplyAsync_WithSlaveRegister()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x7F, 0x08, 0x04, 0x02, 0x02, 0x00, 0xF7);
            connection.EnqueueResponse(0xF0, 0x77, 0x7F, 0x00, 0x04, 0x02, 0x7F, 0x01, 0x7E, 0x01, 0xF7);
            I2CReply reply = session.GetI2CReplyAsync(127, 260, 2).Result;
            Assert.AreEqual(127, reply.Address);
            Assert.AreEqual(260, reply.Register);
            Assert.AreEqual(2, reply.Data.Length);
            Assert.AreEqual(255, reply.Data[0]);
            Assert.AreEqual(254, reply.Data[1]);
        }
        public void SendStringData()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(new byte[] { 0xF0, 0x71 });
            connection.EnqueueRequest("Test".To14BitIso());
            connection.EnqueueRequest(new byte[] { 0xF7 });
            session.SendStringData("Test");
        }
        public void Receive_StringDataMessage()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);
            int eventHits = 0;

            session.MessageReceived += (o, e) =>
            {
                Assert.AreEqual(MessageType.StringData, e.Value.Type);
                Assert.AreEqual("Hello!", ((StringData)e.Value.Value).Text);
                eventHits++;
            };

            connection.EnqueueRequest(0xF0, 0x71, 0xF7);
            connection.EnqueueResponse(0xF0, 0x71, 0x48, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x21, 0x00, 0xF7);
            session.SendStringData(null);
            Assert.AreEqual(1, eventHits, "MessageReceived event not hit once.");
        }
        public void ReadI2CContinous_WithSlaveRegister()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x45, 0x10, 0x07, 0x0C, 0x7F, 0x01, 0xF7);
            session.ReadI2CContinuous(0x45, 0x0607, 255);
        }
        public void ReadI2COnce_MaximumParameters_WithSlaveRegister()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x7F, 0x2F, 0x7F, 0x7F, 0x7F, 0x7F, 0xF7);
            session.ReadI2COnce(0x3FF, 0x3FFF, 0x3FFF);
        }
        public void GetI2CReply()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x01, 0x08, 0x03, 0x00, 0xF7);
            connection.EnqueueResponse(0xF0, 0x77, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0xF7);
            I2CReply reply = session.GetI2CReply(1, 3);
            Assert.AreEqual(1, reply.Address);
            Assert.AreEqual(0, reply.Register);
            Assert.AreEqual(3, reply.Data.Length);
            Assert.AreEqual(5, reply.Data[0]);
            Assert.AreEqual(6, reply.Data[1]);
            Assert.AreEqual(7, reply.Data[2]);
        }
        public void GetI2CReply_BytesToRead_Parameter_Is0()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x01, 0x08, 0x00, 0x00, 0xF7);
            connection.EnqueueResponse(0xF0, 0x77, 0x01, 0x00, 0x00, 0x00, 0xF7);
            I2CReply reply = session.GetI2CReply(1, 0);
            Assert.AreEqual(1, reply.Address);
            Assert.AreEqual(0, reply.Register);
            Assert.AreEqual(0, reply.Data.Length);
        }
        public void GetI2CReply_WithSlaveRegister()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x01, 0x08, 0x02, 0x00, 0x01, 0x00, 0xF7);
            connection.EnqueueResponse(0xF0, 0x77, 0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0xF7);
            I2CReply reply = session.GetI2CReply(1, 2, 1);
            Assert.AreEqual(1, reply.Address);
            Assert.AreEqual(2, reply.Register);
            Assert.AreEqual(1, reply.Data.Length);
            Assert.AreEqual(4, reply.Data[0]);
        }
        public void WriteI2C_Data_Parameter_IsNull()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x02, 0x21, 0xF7);
            session.WriteI2C(130);
        }
        public void StopI2CReading()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x00, 0x18, 0xF7);
            session.StopI2CReading();
        }
        //[TestMethod]
        //[ExpectedException(typeof(TimeoutException))]
        public void TimedoutResponse()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection, 550);

            connection.EnqueueRequest(0xF0, 0x6B, 0xF7);

            session.GetBoardCapability();
        }
        public void WriteI2C_SlaveAddress_Parameter_Is127()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x7F, 0x00, 0x11, 0x00, 0x22, 0x00, 0x33, 0x00, 0x44, 0x00, 0x7F, 0x01, 0xF7);
            session.WriteI2C(127, 0x11, 0x22, 0x33, 0x44, 0xFF);
        }
        public void SendStringData_NullString()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x71, 0xF7);
            session.SendStringData(null);
        }
        public void WriteI2C_SlaveAddress_Parameter_IsNegative()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x76, 0x02, 0x21, 0xF7);
            session.WriteI2C(-1);
        }
        public void SetDigitalPin_Level_Is0_PinNumber_Argument_Is16()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);

            connection.EnqueueRequest(0xF0, 0x6F, 0x10, 0x00, 0x00, 0xF7);
            session.SetDigitalPin(16, 0);
        }
        public void I2CReplyReceived()
        {
            var connection = new MockSerialConnection();
            var session = CreateFirmataSession(connection);
            int eventHits = 0;

            session.I2CReplyReceived += (o, e) =>
            {
                Assert.AreEqual(1, e.Value.Address);
                Assert.AreEqual(0, e.Value.Register);
                Assert.AreEqual(3, e.Value.Data.Length);
                Assert.AreEqual(5, e.Value.Data[0]);
                Assert.AreEqual(6, e.Value.Data[1]);
                Assert.AreEqual(7, e.Value.Data[2]);
                eventHits++;
            };

            connection.EnqueueRequest(0xF0, 0x76, 0x01, 0x08, 0x03, 0x00, 0xF7);
            connection.EnqueueResponse(0xF0, 0x77, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0xF7);
            I2CReply reply = session.GetI2CReply(1, 3);
            Assert.AreEqual(1, eventHits);
        }