示例#1
0
        private PaddlePosition GetPosition(int encodedPosition, PaddleIDs paddleId)
        {
            decimal p1 = decimal.Round(DeviceInfo.PulseToUnit(encodedPosition), 3);

            return(new PaddlePosition()
            {
                PaddleId = paddleId, Position = p1
            });
        }
示例#2
0
 private bool WaitForPosition(PaddleIDs paddleID, int msTimeout = MoveTimeout)
 {
     try
     {
         string        command   = $"p{(char)paddleID}";
         string        response  = $"P{(char)paddleID}";
         List <string> responses = new List <string> {
             "GS", response
         };
         int counter = 10;
         while (true)
         {
             string msg = ELLDevicePort.WaitForResponse(Address, responses, msTimeout);
             if (!string.IsNullOrEmpty(msg))
             {
                 bool returnValue;
                 if (TestStatus(msg, command, true, ref counter, out returnValue))
                 {
                     return(returnValue);
                 }
                 if (msg.Substring(1, 2) == response)
                 {
                     if (msg.Length != 7)
                     {
                         return(false);
                     }
                     PaddlePosition position = GetPosition(msg.Substring(3).ToBytes(4).ToInt(true), paddleID);
                     UpdateParameter(MessageUpdater.UpdateTypes.PaddlePosition, Address, position);
                     return(true);
                 }
             }
         }
     }
     catch (ELLException ex)
     {
         UpdateOutput($"Get Device Status: {ex.Message}", true);
     }
     return(false);
 }
示例#3
0
 /// <summary>   Move microsecond steps. </summary>
 /// <param name="paddleID"> Identifier for the paddle. </param>
 /// <param name="timeMS">   The time in milliseconds. </param>
 /// <param name="backward"> True to backward. </param>
 /// <returns>   True if it succeeds, false if it fails. </returns>
 public bool MoveMicrosecondSteps(PaddleIDs paddleID, short timeMS, bool backward)
 {
     try
     {
         if (timeMS < 0 || timeMS > 8000)
         {
             throw new ArgumentOutOfRangeException($"Range 0 to 8000");
         }
         if (backward)
         {
             timeMS = (short)((timeMS & 0x1FFF) | 0x8000);
         }
         UpdateOutput(string.Format("Move paddle {0} for {1} ms...", (char)paddleID, timeMS));
         ELLDevicePort.SendStringI16(Address, $"t{(char)paddleID}", timeMS);
         return(WaitForPosition(paddleID));
     }
     catch (OverflowException)
     {
         UpdateOutput(string.Format("Parameter out of range {0}...", timeMS));
     }
     return(false);
 }
示例#4
0
 public bool RequestPosition(PaddleIDs paddleID)
 {
     UpdateOutput($"Get Position {(char)paddleID}...");
     ELLDevicePort.SendString(Address, $"p{(char)paddleID}");
     return(WaitForPosition(paddleID));
 }