Exemplo n.º 1
0
        private static Bus <T> Connect <T>(BusMaster <T> master, BusSlave <T> slave, string busName = null)
            where T : BusData, new()
        {
            if (master.IsConnected && slave.IsConnected)
            {
                if (master.Bus != slave.Bus)
                {
                    throw new InvalidOperationException("Both Master and Slave are already connected to different buses.");
                }

                return(master.Bus);
            }

            Bus <T> bus = null;

            if (master.IsConnected)
            {
                bus = master.Bus;
                slave.ConnectTo(bus);
            }
            else if (slave.IsConnected)
            {
                bus = slave.Bus;
                master.ConnectTo(bus);
            }

            return(bus);
        }
Exemplo n.º 2
0
        public void Connected_AllLevelsAreFloating()
        {
            var uut = new BusSlave <BusData8>();
            var bus = new Bus <BusData8>();

            uut.ConnectTo(bus);

            uut.Value.AssertAllLevelsAre(DigitalLevel.Floating);
        }
Exemplo n.º 3
0
        public static BusMaster <T> CreateConnection <T>(this BusSlave <T> slave, string busName = null)
            where T : BusData, new()
        {
            var master = new BusMaster <T>();
            var bus    = new Bus <T>(busName);

            slave.ConnectTo(bus);
            master.ConnectTo(bus);

            return(master);
        }
Exemplo n.º 4
0
        public void Write_SingleMaster_SlaveSeesChanges()
        {
            var master = new BusMaster <BusData8>();
            var slave  = new BusSlave <BusData8>();
            var bus    = new Bus <BusData8>();

            master.ConnectTo(bus);
            slave.ConnectTo(bus);
            master.IsEnabled = true;

            var newValue = new BusData8(0);

            master.Write(newValue);

            slave.Value.AssertAllLevelsAre(DigitalLevel.Low);
        }
Exemplo n.º 5
0
        public static Bus GetOrAddBus(this BusSlave slave, string busName = null)
        {
            Bus bus;

            if (!slave.IsConnected)
            {
                bus = new Bus(slave.Value.Width, busName);
                slave.ConnectTo(bus);
            }
            else
            {
                bus = slave.Bus;
            }

            return(bus);
        }
Exemplo n.º 6
0
        public static Bus <T> ConnectTo <T>(this BusMaster <T> master, BusSlave <T> slave, string busName = null)
            where T : BusData, new()
        {
            Bus <T> bus = Connect(master, slave, busName);

            if (bus == null)
            {
                if (busName == null)
                {
                    busName = master.Name;
                }
                bus = master.GetOrAddBus(busName);
                slave.ConnectTo(bus);
            }

            return(bus);
        }
Exemplo n.º 7
0
        public static Bus <T> GetOrAddBus <T>(this BusSlave <T> slave, string busName = null)
            where T : BusData, new()
        {
            Bus <T> bus;

            if (!slave.IsConnected)
            {
                bus = new Bus <T>(busName);
                slave.ConnectTo(bus);
            }
            else
            {
                bus = slave.Bus;
            }

            return(bus);
        }