コード例 #1
0
ファイル: BusManager.cs プロジェクト: largesky/autotest
        public bool CloseBus(BusInfo busInfo)
        {
            lock (this.busInstances)
            {
                IBus bus = this.TryGetCreatedBus(busInfo);
                if (bus == null)
                {
                    return(false);
                }

                bus.Close();
                while (busInfo.Parent != null)
                {
                    bus = this.TryGetCreatedBus(busInfo.Parent);
                    if (bus == null)
                    {
                        break;
                    }

                    //该总线被其它设备所占用
                    if (this.busInstances.Keys.Any(obj => MatchBusWithParent(obj, busInfo)))
                    {
                        break;
                    }

                    bus.Close();
                    busInfo = busInfo.Parent;
                }
                return(true);
            }
        }
コード例 #2
0
ファイル: BusManager.cs プロジェクト: largesky/autotest
        public int Read(BusInfo busInfo, byte[] readBuf, int maxReadLen = 0)
        {
            IBus bus = this.CreateBusFromBusInfo(busInfo, true);

            try
            {
                return(bus.Read(readBuf, maxReadLen));
            }
            finally
            {
                if (bus != null && bus.State != BusState.Closed && busInfo.CacheResource == false)
                {
                    bus.Close();
                }
            }
        }
コード例 #3
0
ファイル: BusManager.cs プロジェクト: largesky/autotest
        public void Write(BusInfo busInfo, byte[] writeBuf, int offset, int len)
        {
            IBus bus = this.CreateBusFromBusInfo(busInfo, true);

            try
            {
                bus.Write(writeBuf, offset, len);
            }
            finally
            {
                if (bus != null && bus.State != BusState.Closed && busInfo.CacheResource == false)
                {
                    bus.Close();
                }
            }
        }
コード例 #4
0
ファイル: BusManager.cs プロジェクト: largesky/autotest
        public int WriteAndRead(BusInfo busInfo, byte[] writeBuf, int offset, int len, byte[] readBuf, int maxReadLen = 0, int waitTimeBeforeRead = 0)
        {
            IBus bus = this.CreateBusFromBusInfo(busInfo, true);

            try
            {
                bus.Write(writeBuf, offset, len);
                if (waitTimeBeforeRead > 0)
                {
                    Thread.Sleep(waitTimeBeforeRead);
                }
                return(bus.Read(readBuf, maxReadLen));
            }
            finally
            {
                if (bus != null && bus.State != BusState.Closed && busInfo.CacheResource == false)
                {
                    bus.Close();
                }
            }
        }