Exemplo n.º 1
0
        internal static bool FirstAvailable(
            int TimeOutInterval,
            out SerialPacketReader reader,
            out SerialPacketWriter writer,
            out Sender sender,
            bool SyncTyme)
        {
            sender = null;
            reader = null; writer = null;
            var ports = SerialPort.GetPortNames();

            if (ports == null)
            {
                return(false);
            }
            foreach (var item in ports)
            {
                var port = new SerialPort(item, 115200);
                try { port.Open(); }
                catch { return(false); }
                if (port.IsOpen)
                {
                    reader = new SerialPacketReader(port, 500);
                    writer = new SerialPacketWriter(port);
                    var a   = new GeneralPacketHandler(Sender.Empty, new PacketListener(reader, writer));
                    var res = a.Device_Test();
                    if (res != null)
                    {
                        if (SyncTyme)
                        {
                            if (a.Device_SyncTime() == -1)
                            {
                                throw new FailOperationException("Неудалось синхронизировать время.");
                            }
                        }
                        reader.TimeOutInterval = TimeOutInterval;
                        sender = res;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
 internal static SdCardDirectory Root(GeneralPacketHandler ph)
 {
     //TODO: Что-то сделать с этим дерьмом
     //return new SdCardDirectory("/", );
     throw new NotImplementedException();
 }
Exemplo n.º 3
0
 internal SdCardBinnaryFile(SdCardFile ParentFile, GeneralPacketHandler ph)
 {
     this.ph         = ph;
     this.ParentFile = ParentFile;
     cacheLength     = ParentFile.Length;
 }