public void CreateSessionWithOpenConnection() { var connection = new MockSerialConnection(); connection.Open(); var session = new ArduinoSession(connection); Assert.AreEqual(true, connection.IsOpen); }
public void RequestFirmware() { const int majorVersion = 5; const int minorVersion = 1; const string Name = "Arduïno Firmata"; var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x79, 0xF7 }, new byte[] { 0xF0, 0x79, majorVersion, minorVersion }); connection.EnqueueResponse(Name.To14BitIso()); connection.EnqueueResponse(0xF7); session.RequestFirmware(); Assert.AreEqual(1, _messagesReceived.Count, "Message event error"); IFirmataMessage message = _messagesReceived.Dequeue(); //Assert.AreEqual(MessageType.FirmwareResponse, message.Type); Assert.IsInstanceOfType(message, typeof(FirmataMessage <Firmware>)); var firmware = (Firmware)message.Value; Assert.AreEqual(firmware.MajorVersion, majorVersion); Assert.AreEqual(firmware.MinorVersion, minorVersion); Assert.AreEqual(firmware.Name, Name); }
public void ClearSession() { var connection = new MockSerialConnection(); var session = new ArduinoSession(connection); session.Clear(); session.Dispose(); }
public void GetBoardAnalogMappingAsync() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x69, 0xF7 }, 0xF0, 0x6A); connection.EnqueueResponse(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x7F, 0x7F); connection.EnqueueResponse(0xF7); BoardAnalogMapping mapping = session.GetBoardAnalogMappingAsync().Result; Assert.AreEqual(6, mapping.PinMappings.Length); Assert.AreEqual(0, mapping.PinMappings[0].PinNumber); Assert.AreEqual(0, mapping.PinMappings[0].Channel); Assert.AreEqual(1, mapping.PinMappings[1].PinNumber); Assert.AreEqual(1, mapping.PinMappings[1].Channel); Assert.AreEqual(2, mapping.PinMappings[2].PinNumber); Assert.AreEqual(2, mapping.PinMappings[2].Channel); Assert.AreEqual(3, mapping.PinMappings[3].PinNumber); Assert.AreEqual(3, mapping.PinMappings[3].Channel); Assert.AreEqual(4, mapping.PinMappings[4].PinNumber); Assert.AreEqual(4, mapping.PinMappings[4].Channel); Assert.AreEqual(5, mapping.PinMappings[5].PinNumber); Assert.AreEqual(5, mapping.PinMappings[5].Channel); }
public void Write_NullString() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); session.Write(null); }
public void Write_NoArgument() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); session.Write(); }
public void Dispose() { var connection = new MockSerialConnection(); var session = new ArduinoSession(connection); session.Dispose(); }
public void TimeOut_SetNegative() { var connection = new MockSerialConnection(); var session = new ArduinoSession(connection); session.TimeOut = -2; }
public void Write_EmptyString() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); session.Write(string.Empty); }
public void TimeOutReached() { var connection = new MockSerialConnection(); var session = new ArduinoSession(connection); session.TimeOut = 1; // TODO: verder uitwerken. }
public void Write() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); connection.EnqueueStringRequest("Test!"); session.Write("Test!"); }
public void GetBoardCapability() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); // DIGITAL INPUT/DIGITAL OUTPUT/ANALOG/PWM/SERVO/I2C, 0/1/2/3/4/6 connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x6B, 0xF7 }, 0xF0, 0x6C); connection.EnqueueResponse(0, 1, 1, 1, 3, 10, 6, 1, 0x7F); connection.EnqueueResponse(0xF7); BoardCapability capability = session.GetBoardCapability(); Assert.AreEqual(1, capability.Pins.Length); Assert.AreEqual(0, capability.Pins[0].PinNumber); Assert.AreEqual(true, capability.Pins[0].DigitalInput); Assert.AreEqual(true, capability.Pins[0].DigitalOutput); Assert.AreEqual(true, capability.Pins[0].Pwm); Assert.AreEqual(10, capability.Pins[0].PwmResolution); Assert.AreEqual(true, capability.Pins[0].I2C); Assert.AreEqual(false, capability.Pins[0].Analog); Assert.AreEqual(0, capability.Pins[0].AnalogResolution); Assert.AreEqual(false, capability.Pins[0].Servo); Assert.AreEqual(0, capability.Pins[0].ServoResolution); }
public void CreateSessionWithClosedConnection() { var connection = new MockSerialConnection(); var session = new ArduinoSession(connection); Assert.AreEqual(true, connection.IsOpen); }
public void SetDigitalPort_PortNumber_Is0_Pins_Is0() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0x90, 0x00, 0x00 }); session.SetDigitalPort(0, 0); }
public void SetDigitalPort_PortNumber_Is15_Pins_Is255() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0x9F, 0x7F, 0x01 }); session.SetDigitalPort(15, 255); }
public void SetDigitalReportMode_PortNumber_Is1_Enable() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xD1, 0x01 }); session.SetDigitalReportMode(1, true); }
public void SetDigitalReportMode_PortNumber_Is0_Disable() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xD0, 0x00 }); session.SetDigitalReportMode(0, false); }
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 SetAnalogReportMode_Channel_Is15_Disable() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xCF, 0x00 }); session.SetAnalogReportMode(15, false); }
public void SetSamplingInterval_Interval_Is0x3FFF() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x7A, 0x7F, 0x7F, 0xF7 }); session.SetSamplingInterval(0x3FFF); }
public void ConfigureServo_MinPulse_Is0x4000() { var connection = new MockSerialConnection(); var session = CreateServoSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00 }); session.ConfigureServo(0, 0x4000, 0); }
public void SetDigitalPin_Level_PinNumber_Argument_Is15() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xEF, 0x00, 0x00 }); session.SetDigitalPin(15, 0); }
public void SetDigitalPort_Pins_Argument_IsNegative() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0x90, 0x00, 0x00 }); session.SetDigitalPort(0, -1); }
public void TimeOut_GetAndSet() { var connection = new MockSerialConnection(); var session = new ArduinoSession(connection); Assert.AreEqual(-1, session.TimeOut); session.TimeOut = 7; Assert.AreEqual(7, session.TimeOut); }
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 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 SetI2CReadInterval_Interval_Is0x3FFF() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x78, 0x7F, 0x7F, 0xF7 }); session.SetI2CReadInterval(0x3FFF); }
public void SetDigitalPin_Level_PinNumber_Argument_Is0_Level_Argument_Is0xFFFF() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x6F, 0x00, 0x7F, 0x7F, 0x03, 0xF7 }); session.SetDigitalPin(0, 0xFFFF); }
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 ConfigureServo_MaxPulse_IsNegative() { var connection = new MockSerialConnection(); var session = CreateServoSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF7 }); session.ConfigureServo(15, 0, -1); }
public void SetI2CReadInterval_Interval_Is0() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x78, 0x00, 0x00, 0xF7 }); session.SetI2CReadInterval(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); }
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 ConfigureServo_PinNumber_Is128() { var connection = new MockSerialConnection(); var session = CreateServoSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00 }); session.ConfigureServo(128, 0, 0); }
public void SendStringData_NullString() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequest(0xF0, 0x71, 0xF7); session.SendStringData(null); }
public void SetAnalogReportMode_Channel_Is0_Enable() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xC0, 0x01 }); session.SetAnalogReportMode(0, true); }
public void SetDigitalPinMode_SetPin127ToAnalog() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xF4, 0x7F, (byte)PinMode.AnalogInput }); session.SetDigitalPinMode(127, PinMode.AnalogInput); }
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 SetDigitalPinMode_PinNumber_Is128() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xF4, 0x00, (byte)PinMode.DigitalInput }); session.SetDigitalPinMode(128, PinMode.DigitalInput); }
public void SetDigitalPinMode_SetPin0ToDigitalOutput() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xF4, 0x00, (byte)PinMode.DigitalOutput }); session.SetDigitalPinMode(0, PinMode.DigitalOutput); }
public void GetProtocolVersionAsync() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xF9 }, new byte[] { 0xF9, 2, 3 }); ProtocolVersion version = session.GetProtocolVersionAsync().Result; Assert.AreEqual(2, version.Major); Assert.AreEqual(3, version.Minor); Assert.AreEqual(1, _messagesReceived.Count); }
public void ResetBoard() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection); connection.EnqueueRequestAndResponse(new byte[] { 0xFF }, new byte[] { 0xF9, 2, 3 }); session.ResetBoard(); Assert.AreEqual(1, _messagesReceived.Count); FirmataMessage message = _messagesReceived.Dequeue(); Assert.AreEqual(MessageType.ProtocolVersion, message.Type); var version = (ProtocolVersion)message.Value; Assert.AreEqual(2, version.Major); Assert.AreEqual(3, version.Minor); }
//[TestMethod] // Verdacht public async Task RequestBufferOverflow() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var tasks = new List<Task<string>>(100); for (int x = 0; x < 100; x++) tasks.Add(session.ReadAsync()); Thread.Sleep(250); connection.MockReceiveDelayed(new string('*', 100)); await Task.WhenAll(tasks); foreach (Task<string> t in tasks) { Assert.AreEqual("*", t.Result); } }
public async Task ReceivedStringBufferOverflow() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.Read(1000); } ); connection.MockReceiveDelayed(new string('*', 3000)); await t; }
//[TestMethod] //[ExpectedException(typeof(TimeoutException))] public async Task Read_WithTimeout() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection, 550); var t = Task.Run(() => { string data = session.Read(6); Assert.AreEqual("Hello!", data); } ); await t; }
public async Task Read_StringBlock() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.Read(6); Assert.AreEqual("Hello!", data); } ); connection.MockReceiveDelayed("Hello!!!"); await t; }
public async Task ReadLine_CarriageReturnPlusLinefeed() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); session.NewLine = "\r\n"; var t = Task.Run(() => { string data = session.ReadLine(); Assert.AreEqual("A line.", data); data = session.ReadLine(); Assert.AreEqual("Second line.", data); } ); connection.MockReceiveDelayed("A line." + session.NewLine + "Second line." + session.NewLine); await t; }
public async Task Read_NegativeLength() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.Read(-1); } ); connection.MockReceiveDelayed("Hello!!!"); await t; }
public async Task ReadTo_EmptyString() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.ReadTo(';'); Assert.AreEqual(string.Empty, data); } ); connection.MockReceiveDelayed(";"); await t; }
public void Write_NullString() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); session.Write(null); }
public async Task ReadAsync_Length_IsNegative() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = session.ReadAsync(-1); connection.MockReceiveDelayed("Test"); string data = await t; }
public async Task ReadAsync_4Characters() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = session.ReadAsync(4); connection.MockReceiveDelayed("Test"); string data = await t; Assert.AreEqual("Test", data); }
public async Task ReadLineAsync() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = session.ReadLineAsync(); connection.MockReceiveDelayed("Test" + session.NewLine); string data = await t; Assert.AreEqual("Test", data); }
public async Task ReadToAsync() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = session.ReadToAsync(','); connection.MockReceiveDelayed("alpha,beta,gamma"); string data = await t; Assert.AreEqual("alpha", data); }
public void Write_NoArgument() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); session.Write(); }
public void TimeOut_SetNegative() { var connection = new MockSerialConnection(); var session = new ArduinoSession(connection); session.TimeOut = -2; }
public async Task ReadTo() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.ReadTo('.'); Assert.AreEqual("A line", data); } ); connection.MockReceiveDelayed("A line."); await t; }
public void Dispose_OnOpenConnection() { var connection = new MockSerialConnection(); connection.Open(); var session = new ArduinoSession(connection); session.Dispose(); }
public void Write_EmptyString() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); session.Write(string.Empty); }