本文整理汇总了C#中Solid.Arduino.Test.MockSerialConnection.EnqueueResponse方法的典型用法代码示例。如果您正苦于以下问题:C# MockSerialConnection.EnqueueResponse方法的具体用法?C# MockSerialConnection.EnqueueResponse怎么用?C# MockSerialConnection.EnqueueResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solid.Arduino.Test.MockSerialConnection
的用法示例。
在下文中一共展示了MockSerialConnection.EnqueueResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetI2CReply_BytesToRead_Parameter_Is0
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);
}
示例2: GetI2CReply_WithSlaveRegister
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]);
}
示例3: Receive_StringDataMessage
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.");
}
示例4: GetI2CReply
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]);
}
示例5: RequestPinState
public void RequestPinState()
{
var connection = new MockSerialConnection();
var session = CreateFirmataSession(connection);
connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x6D, 0x01, 0xF7 }, 0xF0, 0x6E);
// Pin 1 Digital Output mode, value = 0
connection.EnqueueResponse(0x01, 0x01, 0x00);
connection.EnqueueResponse(0xF7);
session.RequestPinState(1);
FirmataMessage message = _messagesReceived.Dequeue();
Assert.AreEqual(MessageType.PinStateResponse, message.Type);
PinState state = (PinState)message.Value;
Assert.AreEqual(1, state.PinNumber);
Assert.AreEqual(PinMode.DigitalOutput, state.Mode);
Assert.AreEqual(0, state.Value);
}
示例6: GetFirmware
public void GetFirmware()
{
const int majorVersion = 3;
const int minorVersion = 7;
const string Name = "Arduino Firmata";
var connection = new MockSerialConnection();
var session = new ArduinoSession(connection);
connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x79, 0xF7 }, new byte[] { 0xF0, 0x79, majorVersion, minorVersion });
connection.EnqueueResponse(Name.To14BitIso());
connection.EnqueueResponse(0xF7);
Firmware firmware = session.GetFirmware();
Assert.AreEqual(firmware.MajorVersion, majorVersion);
Assert.AreEqual(firmware.MinorVersion, minorVersion);
Assert.AreEqual(firmware.Name, Name);
}
示例7: GetPinState_PinNumber_Argument_Is127
public void GetPinState_PinNumber_Argument_Is127()
{
var connection = new MockSerialConnection();
var session = CreateFirmataSession(connection);
connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x6D, 0x7F, 0xF7 }, 0xF0, 0x6E);
// Pin 127 PWM mode, value = 256
connection.EnqueueResponse(0x7F, 0x03, 0x00, 0x02);
connection.EnqueueResponse(0xF7);
PinState state = session.GetPinState(127);
Assert.AreEqual(127, state.PinNumber);
Assert.AreEqual(PinMode.PwmOutput, state.Mode);
Assert.AreEqual(256U, state.Value);
}
示例8: GetBoardCapabilityAsync
public void GetBoardCapabilityAsync()
{
var connection = new MockSerialConnection();
var session = CreateFirmataSession(connection);
// DIGITAL INPUT/DIGITAL OUTPUT/ANALOG/PWM/SERVO, 0/1/2/3/4
connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x6B, 0xF7 }, 0xF0, 0x6C);
connection.EnqueueResponse(2, 8, 0x7F);
connection.EnqueueResponse(0, 1, 1, 1, 0x7F);
connection.EnqueueResponse(1, 1, 3, 7, 4, 7, 0x7F);
connection.EnqueueResponse(0xF7);
BoardCapability capability = session.GetBoardCapabilityAsync().Result;
Assert.AreEqual(3, capability.PinCapabilities.Length);
Assert.AreEqual(0, capability.PinCapabilities[0].PinNumber);
Assert.AreEqual(false, capability.PinCapabilities[0].DigitalInput);
Assert.AreEqual(false, capability.PinCapabilities[0].DigitalOutput);
Assert.AreEqual(true, capability.PinCapabilities[0].Analog);
Assert.AreEqual(8, capability.PinCapabilities[0].AnalogResolution);
Assert.AreEqual(false, capability.PinCapabilities[0].Pwm);
Assert.AreEqual(0, capability.PinCapabilities[0].PwmResolution);
Assert.AreEqual(false, capability.PinCapabilities[0].Servo);
Assert.AreEqual(0, capability.PinCapabilities[0].ServoResolution);
Assert.AreEqual(1, capability.PinCapabilities[1].PinNumber);
Assert.AreEqual(true, capability.PinCapabilities[1].DigitalInput);
Assert.AreEqual(true, capability.PinCapabilities[1].DigitalOutput);
Assert.AreEqual(false, capability.PinCapabilities[1].Analog);
Assert.AreEqual(0, capability.PinCapabilities[1].AnalogResolution);
Assert.AreEqual(false, capability.PinCapabilities[1].Pwm);
Assert.AreEqual(0, capability.PinCapabilities[1].PwmResolution);
Assert.AreEqual(false, capability.PinCapabilities[1].Servo);
Assert.AreEqual(0, capability.PinCapabilities[1].ServoResolution);
Assert.AreEqual(2, capability.PinCapabilities[2].PinNumber);
Assert.AreEqual(false, capability.PinCapabilities[2].DigitalInput);
Assert.AreEqual(true, capability.PinCapabilities[2].DigitalOutput);
Assert.AreEqual(false, capability.PinCapabilities[2].Analog);
Assert.AreEqual(0, capability.PinCapabilities[2].AnalogResolution);
Assert.AreEqual(true, capability.PinCapabilities[2].Pwm);
Assert.AreEqual(7, capability.PinCapabilities[2].PwmResolution);
Assert.AreEqual(true, capability.PinCapabilities[2].Servo);
Assert.AreEqual(7, capability.PinCapabilities[2].ServoResolution);
}
示例9: GetPinState_PinNumber_Argument_Is128
public void GetPinState_PinNumber_Argument_Is128()
{
var connection = new MockSerialConnection();
var session = CreateFirmataSession(connection);
connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x6D, 0x00, 0xF7 }, 0xF0, 0x6E);
// Pin 0 analog mode, value = 1023
connection.EnqueueResponse(0x00, 0x02, 0x7F, 0x07);
connection.EnqueueResponse(0xF7);
PinState state = session.GetPinState(128);
}
示例10: GetPinState_PinNumber_Argument_Is127_Returned_Pin0
public void GetPinState_PinNumber_Argument_Is127_Returned_Pin0()
{
var connection = new MockSerialConnection();
var session = CreateFirmataSession(connection);
connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x6D, 0x7F, 0xF7 }, 0xF0, 0x6E);
// Pin 0 analog mode, value = 1023
connection.EnqueueResponse(0x00, 0x02, 0x7F, 0x07);
connection.EnqueueResponse(0xF7);
PinState state = session.GetPinState(127);
Assert.AreEqual(0, state.PinNumber);
Assert.AreEqual(PinMode.AnalogInput, state.Mode);
Assert.AreEqual(1023U, state.Value);
}
示例11: RequestBoardAnalogMapping
public void RequestBoardAnalogMapping()
{
var connection = new MockSerialConnection();
var session = CreateFirmataSession(connection);
connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x69, 0xF7 }, 0xF0, 0x6A);
connection.EnqueueResponse(0x0F);
connection.EnqueueResponse(0xF7);
session.RequestBoardAnalogMapping();
FirmataMessage message = _messagesReceived.Dequeue();
Assert.AreEqual(MessageType.AnalogMappingResponse, message.Type);
BoardAnalogMapping mapping = (BoardAnalogMapping)message.Value;
Assert.AreEqual(1, mapping.PinMappings.Length);
Assert.AreEqual(0, mapping.PinMappings[0].PinNumber);
Assert.AreEqual(15, mapping.PinMappings[0].Channel);
}
示例12: GetBoardAnalogMappingAsync
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);
}
示例13: RequestBoardCapability
public void RequestBoardCapability()
{
var connection = new MockSerialConnection();
var session = CreateFirmataSession(connection);
// DIGITAL INPUT/DIGITAL OUTPUT/ANALOG/PWM/SERVO, 0/1/2/3/4
connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x6B, 0xF7 }, 0xF0, 0x6C);
connection.EnqueueResponse(2, 8, 0x7F);
connection.EnqueueResponse(0, 127, 1, 127, 0x7F);
connection.EnqueueResponse(0xF7);
session.RequestBoardCapability();
FirmataMessage message = _messagesReceived.Dequeue();
Assert.AreEqual(MessageType.CapabilityResponse, message.Type);
BoardCapability capability = (BoardCapability)message.Value;
Assert.AreEqual(2, capability.PinCapabilities.Length);
Assert.AreEqual(0, capability.PinCapabilities[0].PinNumber);
Assert.AreEqual(false, capability.PinCapabilities[0].DigitalInput);
Assert.AreEqual(false, capability.PinCapabilities[0].DigitalOutput);
Assert.AreEqual(true, capability.PinCapabilities[0].Analog);
Assert.AreEqual(8, capability.PinCapabilities[0].AnalogResolution);
Assert.AreEqual(false, capability.PinCapabilities[0].Pwm);
Assert.AreEqual(0, capability.PinCapabilities[0].PwmResolution);
Assert.AreEqual(false, capability.PinCapabilities[0].Servo);
Assert.AreEqual(0, capability.PinCapabilities[0].ServoResolution);
Assert.AreEqual(1, capability.PinCapabilities[1].PinNumber);
Assert.AreEqual(true, capability.PinCapabilities[1].DigitalInput);
Assert.AreEqual(true, capability.PinCapabilities[1].DigitalOutput);
Assert.AreEqual(false, capability.PinCapabilities[1].Analog);
Assert.AreEqual(0, capability.PinCapabilities[1].AnalogResolution);
Assert.AreEqual(false, capability.PinCapabilities[1].Pwm);
Assert.AreEqual(0, capability.PinCapabilities[1].PwmResolution);
Assert.AreEqual(false, capability.PinCapabilities[1].Servo);
Assert.AreEqual(0, capability.PinCapabilities[1].ServoResolution);
}
示例14: GetI2CReplyAsync_WithSlaveRegister
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]);
}
示例15: GetPinStateAsync
public void GetPinStateAsync()
{
var connection = new MockSerialConnection();
var session = CreateFirmataSession(connection);
connection.EnqueueRequestAndResponse(new byte[] { 0xF0, 0x6D, 0x05, 0xF7 }, 0xF0, 0x6E);
// Pin 5 Digital Input mode, value = 1
connection.EnqueueResponse(0x05, 0x00, 0x01);
connection.EnqueueResponse(0xF7);
PinState state = session.GetPinStateAsync(5).Result;
Assert.AreEqual(5, state.PinNumber);
Assert.AreEqual(PinMode.DigitalInput, state.Mode);
Assert.AreEqual(1U, state.Value);
}