Пример #1
0
        protected override void ExecuteInternal(TeensyBatDevice device)
        {
            int totalSeconds = (int)Math.Round((DateTime.UtcNow - EpochStart).TotalSeconds);

            totalSeconds = totalSeconds + 1;
            device.Send(string.Format(CultureInfo.InvariantCulture, "CT{0}\n", totalSeconds));
        }
Пример #2
0
 protected override bool?HandleLine(TeensyBatDevice device, string data)
 {
     if (data.StartsWith("OK: ", StringComparison.OrdinalIgnoreCase))
     {
         return(true);
     }
     if (data.StartsWith("ERR: ", StringComparison.OrdinalIgnoreCase))
     {
         return(false);
     }
     return(null);
 }
Пример #3
0
        protected override DeviceInfo HandleLine(TeensyBatDevice device, string data)
        {
            Match match = ConfigData.Match(data);

            if (match.Success)
            {
                DeviceInfo info = new DeviceInfo();
                info.NodeId        = int.Parse(match.Groups["NodeId"].Value, CultureInfo.InvariantCulture);
                info.CurrentDate   = DateTime.ParseExact(match.Groups["Date"].Value, "dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                info.RecordingTime = DateTime.UtcNow;
                return(info);
            }
            return(null);
        }
Пример #4
0
        public Task <TResult> Execute(TeensyBatDevice device)
        {
            Task <TResult> task = Task.Run(() =>
            {
                try
                {
                    _responseHandled.Reset();
                    device.LineReceived += DeviceOnLineReceived;
                    if (device.IsConnected)
                    {
                        ExecuteInternal(device);
                        WaitHandle.WaitAny(new[] { device.CancellationToken.Token.WaitHandle, _responseHandled }, Timeout);
                    }
                }
                finally
                {
                    device.LineReceived -= DeviceOnLineReceived;
                }
                return(_result);
            });

            return(task);
        }
Пример #5
0
 protected abstract TResult HandleLine(TeensyBatDevice device, string data);
Пример #6
0
 protected abstract void ExecuteInternal(TeensyBatDevice device);
Пример #7
0
 protected override void ExecuteInternal(TeensyBatDevice device)
 {
     device.Send("CP\n");
 }