예제 #1
0
        private static IBuffer CreateRequest(PositionControllerCommand command, PositionControllerDirection direction, uint steps, byte[] buffer)
        {
            if (buffer == null || buffer.Length < REQUEST_LENGTH)
            {
                throw new ArgumentException($"'{nameof(buffer)}' parameter is null or too small");
            }

            using (Stream s = new MemoryStream(buffer))
            {
                using (BinaryWriter bw = new BinaryWriter(s))
                {
                    bw.Write((ushort)DATA_HEADER);
                    bw.Write((byte)command);
                    bw.Write((byte)direction);
                    bw.Write((uint)steps);
                }
            }

            Stm32Crc32 crc32 = new Stm32Crc32(CRC32_INITIAL_VALUE, CRC32_POLYNOMIAL);

            using (Stream s = new MemoryStream(buffer))
            {
                using (BinaryReader br = new BinaryReader(s))
                {
                    crc32.Encode(br.ReadUInt32());
                    crc32.Encode(br.ReadUInt32());
                }
            }

            using (Stream s = new MemoryStream(buffer, 8, 4))
            {
                using (BinaryWriter bw = new BinaryWriter(s))
                {
                    bw.Write((uint)crc32.GetValue());
                }
            }

            return(buffer.AsBuffer());
        }
예제 #2
0
        private void SetStatus(string message, PositionControllerCommand fromCommand, PositionControllerResponse status)
        {
            if (status != null &&
                status.Status == PositionControllerStatus.PC_OK_IDLE && /* no errors should be present for calibration to be considered successful */
                fromCommand == PositionControllerCommand.CALIBRATE)
            {
                this.maxPosition = status.Position;
            }

            if (status == null)
            {
                Position          = double.NaN;
                StatusDisplayName = STATUS_DISPLAY_NAME_NOT_AVAILABLE;
            }
            else
            {
                Position           = ((double)status.Position) * PositionController.DISTANCE_PER_TICK_MM;
                StatusDisplayName  = StatusToDisplayName(status.Status);
                IsEmergencyStopped = (status.Status & PositionControllerStatus.PC_OK_EMERGENCY_STOP) == PositionControllerStatus.PC_OK_EMERGENCY_STOP;

                ++PacketsTotalNumber;

                if ((status.Status & ~PositionControllerStatus.PC_OK_MASK) != 0)
                {
                    ++PacketsFailuresNumber;
                }
                if ((status.Status & PositionControllerStatus.PC_ERR_CRC) != 0 ||
                    (status.Status & PositionControllerStatus.CS_ERR_CRC) != 0)
                {
                    ++PacketsCrcFailuresNumber;
                }

                if (!this.positionController.IsOkStatus(status.Status))
                {
                    this.mainModel.LogEntries.Add(new PositionControllerErrorStatusLogEntry(message, fromCommand, status.Status));
                }
            }
        }
예제 #3
0
 public void SetStatus(PositionControllerCommand fromCommand, PositionControllerResponse status)
 {
     SetStatus(null, fromCommand, status);
 }
 public PositionControllerErrorStatusLogEntry(string message, PositionControllerCommand fromCommand, PositionControllerStatus status)
 {
     Title   = message ?? fromCommand.ToString();
     Details = status.ToString();
 }