예제 #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");
 }