public void LEDShouldDisplay() { //准备Com设备和LED数码管 ComBase comIO = new MyComDevice(); ComLED.ComLED led = new ComLED.ComLED(); //连线 ComConnector connector = new ComConnector(); connector.Bind(comIO, led.com); Assert.AreEqual(led.A, '0'); Assert.AreEqual(led.B, '0'); //串口发送 ((MyComDevice)comIO).Display(0xFC); Assert.AreEqual(led.A, 'F'); Assert.AreEqual(led.B, 'C'); //断开连线 connector.Close(); ((MyComDevice)comIO).Display(0xDA); Assert.AreNotEqual(led.A, 'D'); Assert.AreNotEqual(led.B, 'A'); Assert.AreEqual(led.A, 'F'); Assert.AreEqual(led.B, 'C'); }
public void ComIOBindToComBaseByConnector() { //初始化两个设备 ComBase comIO = new MyTestComDev(); ComBase comBase = new MyVirtualCom(); //初始化一个连接线Connector ComConnector connector = new ComConnector(); //链接 connector.Bind(comIO, comBase); Assert.IsNotNull(comBase.Connector); Console.WriteLine("ComBase send data to ComIO"); (comBase as MyVirtualCom)?.SendTest(); Console.WriteLine("ComIO receive data from real device to ComBase"); (comIO as MyTestComDev)?.SendTest(); //移除连接线 connector.Close(); Assert.IsNull(comBase.Connector); }
public override void Remove() { connector.Close(); base.Remove(); }