protected override ImagingParameter ExecuteSubCommand(IFTDI device)
        {
            Write(device, SubCommandCode);
            var data = Read(device, 5);

            if (data[0] == 0x00)
            {
                var gain         = data[1];
                var exposureTime = ToUShort(data[2], data[3]);
                var threshold    = data[4];

                return(new ImagingParameter(gain, exposureTime, threshold));
            }
            else if (data[0] == 0xf1)
            {
                throw new AnotherCommandInProgressException();
            }
            else if (data[0] == 0xf0)
            {
                throw new UILockedException();
            }
            else
            {
                throw new UnexpectedReturnCodeException();
            }
        }
Example #2
0
        protected override MGENResult ExecuteSubCommand(IFTDI device)
        {
            Write(device, SubCommandCode);
            var data = Read(device, 1);

            if (data[0] == 0x00)
            {
                return(new MGENResult(true));
            }
            else if (data[0] == 0x01)
            {
                throw new NoStarSeenException();
            }
            else if (data[0] == 0x02)
            {
                throw new InvalidScreenException();
            }
            else if (data[0] == 0xf0)
            {
                throw new CannotDoFunctionsException();
            }
            else
            {
                throw new UnexpectedReturnCodeException();
            }
        }
        protected override MGENResult ExecuteSubCommand(IFTDI device)
        {
            Write(device, SubCommandCode);
            var data = Read(device, 5);

            if (data[0] == 0x00)
            {
                var exposureTimeBytes = GetBytes(exposureTime);
                //For exposure time LSB has to be first
                var parameters = new byte[] { gain, exposureTimeBytes[0], exposureTimeBytes[1], threshold };
                Write(device, parameters);

                return(new MGENResult(true));
            }
            else if (data[0] == 0xf2)
            {
                throw new CameraIsOffException();
            }
            else if (data[0] == 0xf1)
            {
                throw new AnotherCommandInProgressException();
            }
            else if (data[0] == 0xf0)
            {
                throw new UILockedException();
            }
            else
            {
                throw new UnexpectedReturnCodeException();
            }
        }
Example #4
0
        protected override StarSearchResult ExecuteSubCommand(IFTDI device)
        {
            Write(device, SubCommandCode);
            var data = Read(device, 1);

            if (data[0] == 0x00)
            {
                var exposureTimeBytes = GetBytes(exposureTime);
                //For exposure time LSB has to be first
                var parameters = new byte[] { gain, exposureTimeBytes[0], exposureTimeBytes[1] };
                Write(device, parameters);
                var numStars = Read(device, 1);
                return(new StarSearchResult(numStars[0]));
            }
            else if (data[0] == 0xf2)
            {
                throw new CameraIsOffException();
            }
            else if (data[0] == 0xf3)
            {
                throw new AutoGuidingActiveException();
            }
            else if (data[0] == 0xf1)
            {
                throw new AnotherCommandInProgressException();
            }
            else if (data[0] == 0xf0)
            {
                throw new UILockedException();
            }
            else
            {
                throw new UnexpectedReturnCodeException();
            }
        }
Example #5
0
        protected override MGENResult ExecuteSubCommand(IFTDI device)
        {
            Write(device, SubCommandCode);
            var data = Read(device, 1);

            if (data[0] == 0x00)
            {
                var posX       = GetBytes(starData.PositionX);
                var posY       = GetBytes(starData.PositionY);
                var parameters = new byte[] { posX[0], posX[1], posY[0], posY[1] };
                Write(device, parameters);

                return(new MGENResult(true));
            }
            else if (data[0] == 0xf2)
            {
                throw new CameraIsOffException();
            }
            else if (data[0] == 0xf3)
            {
                throw new AutoGuidingActiveException();
            }
            else if (data[0] == 0xf1)
            {
                throw new AnotherCommandInProgressException();
            }
            else if (data[0] == 0xf0)
            {
                throw new UILockedException();
            }
            else
            {
                throw new UnexpectedReturnCodeException();
            }
        }
Example #6
0
        protected override MGENResult ExecuteSubCommand(IFTDI device)
        {
            Write(device, SubCommandCode);
            var data = Read(device, 1);

            if (data[0] == 0x00)
            {
                return(new MGENResult(true));
            }
            else if (data[0] == 0xf2)
            {
                throw new CameraIsOffException();
            }
            else if (data[0] == 0xf3)
            {
                throw new AutoGuidingActiveException();
            }
            else if (data[0] == 0xf1)
            {
                throw new AnotherCommandInProgressException();
            }
            else if (data[0] == 0xf0)
            {
                throw new UILockedException();
            }
            else
            {
                throw new UnexpectedReturnCodeException();
            }
        }
Example #7
0
        protected override DisplayData ExecuteSubCommand(IFTDI device)
        {
            Write(device, SubCommandCode);
            Write(device, new byte[] { (byte)address, (byte)(address >> 8), chunkSize });
            var displayData = Read(device, chunkSize);

            return(new DisplayData(displayData));
        }
Example #8
0
        protected override StartDitherResult ExecuteSubCommand(IFTDI device)
        {
            Write(device, SubCommandCode);
            var data  = Read(device, 1);
            var state = (DitherState)data[0];

            return(new StartDitherResult(state.HasFlag(DitherState.RDActive), true));
        }
Example #9
0
 /// <summary>
 /// Create instance of <see cref="Device" />
 /// </summary>
 /// <param name="description">Description of device</param>
 /// <param name="speed">BaudRate</param>
 /// <param name="readTimeout">Read timeout</param>
 /// <param name="writeTimeout">Write timeout</param>
 public Device(string description, uint speed, uint readTimeout, uint writeTimeout)
 {
     _crc16Ccitt = new Crc16Ccitt(Crc16Ccitt.InitialCrcValue.NonZero1);
     _description = description;
     _speed = speed;
     _readTimeout = readTimeout;
     _writeTimeout = writeTimeout;
     _myFtdiDevice = DriverFactory.GetDriver();
 }
Example #10
0
        protected override LEDState ExecuteSubCommand(IFTDI device)
        {
            Write(device, SubCommandCode);
            Write(device, 1);
            var data = Read(device, 1);

            LEDS leds = (LEDS)data[0];

            return(new LEDState(leds));
        }
Example #11
0
        protected void Write(IFTDI device, byte[] data)
        {
            ValidateDeviceParameter(device);
            var status = device.Write(data, data.Length, out var writtenBytes);

            if (status != FT_STATUS.FT_OK)
            {
                throw new FTDIWriteException();
            }
        }
Example #12
0
        public override MGENResult Execute(IFTDI device)
        {
            Write(device, CommandCode);
            var data = Read(device, 1);

            if (data[0] != AcknowledgeCode && data[0] != NotAcknowledgeCode)
            {
                return(null);
            }
            return(new MGENResult(data[0] == AcknowledgeCode));
        }
Example #13
0
        protected override MGENResult ExecuteSubCommand(IFTDI device)
        {
            Write(device, SubCommandCode);
            var data = Read(device, 2);

            if (data[0] != 0x00)
            {
                throw new UnexpectedReturnCodeException();
            }
            return(new MGENResult(true));
        }
Example #14
0
        public override QueryDevice Execute(IFTDI device)
        {
            Write(device, new byte[] { CommandCode, 0x01, 0x01 });
            var data       = Read(device, 5);
            var isBootMode = Enumerable.SequenceEqual(BootModeAnswer, data);
            var isAppMode  = Enumerable.SequenceEqual(AppModeAnswer, data);

            if (!isBootMode && !isAppMode)
            {
                return(null);
            }
            return(new QueryDevice(isBootMode));
        }
Example #15
0
        protected override DitherAmplitudeResult ExecuteSubCommand(IFTDI device)
        {
            Write(device, SubCommandCode);
            var numBytes = Read(device, 1);

            if (numBytes[0] > 2)
            {
                var data      = Read(device, numBytes[0]);
                var amplitude = data[1] / 100.0 + data[2];
                return(new DitherAmplitudeResult(amplitude, true));
            }
            return(new DitherAmplitudeResult(0.0, false));
        }
Example #16
0
        protected byte[] Read(IFTDI device, int length)
        {
            ValidateDeviceParameter(device);

            byte[] buffer = new byte[length];
            var    status = device.Read(buffer, buffer.Length, out var readBytes);

            if (status != FT_STATUS.FT_OK)
            {
                throw new FTDIReadException();
            }
            return(buffer);
        }
Example #17
0
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            FtdiDeviceInfoStruct device = (FtdiDeviceInfoStruct)comboBoxFtdiDevice.SelectedItem;

            _uart = new FTDI(
                device.SerialNumber,
                921600,
                FtdiParity.None,
                8,
                FtdiStopBits.One,
                FtdiFlowControl.NONE);
            _uart.Open();

            buttonConnect.Enabled         = false;
            comboBoxFtdiDevice.Enabled    = false;
            buttonDisconnect.Enabled      = true;
            groupBoxCommunication.Enabled = true;
            richTextBoxInfo.Enabled       = true;
            groupBoxIo.Enabled            = true;
            buttonClearLog.Enabled        = true;

            // Default every IO to output (output is enabled when bit is 1)
            UInt32[] regConfigAddrs =
            {
                RegAddrFromName(FpgaRegisters.Config32To1),
                RegAddrFromName(FpgaRegisters.Config64To33),
                RegAddrFromName(FpgaRegisters.ConfigH10To1AndGpio80To65)
            };
            foreach (var regAddr in regConfigAddrs)
            {
                if (!WriteRegister(regAddr, 0xFFFFFFFF))
                {
                    WriteLine("Error setting IO config");
                }
            }

            // Default every IO to output a LOW (output is low when bit is 0)
            UInt32[] regStateAddrs =
            {
                RegAddrFromName(FpgaRegisters.Gpio32To1),
                RegAddrFromName(FpgaRegisters.Gpio64To33),
                RegAddrFromName(FpgaRegisters.GpioH10To1AndGpio80To65)
            };
            foreach (var regAddr in regStateAddrs)
            {
                if (!WriteRegister(regAddr, 0))
                {
                    WriteLine("Error setting IO state");
                }
            }
        }
Example #18
0
        public override TResult Execute(IFTDI device)
        {
            Write(device, CommandCode);
            var data = Read(device, 1);

            if (data[0] == AcknowledgeCode)
            {
                // Autoguiding Command intitialized - Sub Command can follow
                return(ExecuteSubCommand(device));
            }
            else
            {
                throw new UnexpectedReturnCodeException();
            }
        }
Example #19
0
        public override FirmwareVersion Execute(IFTDI device)
        {
            Write(device, CommandCode);
            var data = Read(device, 3);

            if (data[0] == AcknowledgeCode)
            {
                var version = Convert.ToString(data[2], 16) + "." + Convert.ToString(data[1], 16);
                return(new FirmwareVersion(true, version));
            }
            else
            {
                //throw generic error
                throw new UnexpectedReturnCodeException();
            }
        }
Example #20
0
        protected override StarData ExecuteSubCommand(IFTDI device)
        {
            Write(device, SubCommandCode);
            var data = Read(device, 1);

            if (data[0] == 0x00)
            {
                Write(device, starIndex);
                var mirror = Read(device, 1);
                if (mirror[0] == starIndex)
                {
                    var starDataArray = Read(device, 8);
                    var positionX     = ToUShort(starDataArray[0], starDataArray[1]);
                    var positionY     = ToUShort(starDataArray[2], starDataArray[3]);
                    var brightness    = ToUShort(starDataArray[4], starDataArray[5]);
                    var pixels        = starDataArray[6];
                    var peak          = starDataArray[7];
                    return(new StarData(positionX, positionY, brightness, pixels, peak));
                }
                else
                {
                    throw new Exception($"Invalid Star Index {mirror[0]}");
                }
            }
            else if (data[0] == 0xf2)
            {
                throw new CameraIsOffException();
            }
            else if (data[0] == 0xf3)
            {
                throw new AutoGuidingActiveException();
            }
            else if (data[0] == 0xf1)
            {
                throw new AnotherCommandInProgressException();
            }
            else if (data[0] == 0xf0)
            {
                throw new UILockedException();
            }
            else
            {
                throw new UnexpectedReturnCodeException();
            }
        }
Example #21
0
        /// <summary>
        /// Frame index is an increasing number as new CCD frames are read.
        /// The lower 6 bits are provided. If the Camera can see and evaluate a star in it, bit 6 is set (otherwise it’szero).Bit7isalways zero.
        /// Raw CCD coordinates show where the last star has been measured. (If the ‘star present’ flag is zero, this value is the lastest one when that flag was one.)
        /// It’s a signed 16.8 bit fixed point number. (The lower 8 bits are the fractional part, the next 15 bits is the integer part and bit 23 is the sign.).
        /// (Note that the CCD pixels are not exactlysquare, 4.85 um horizontal (X) and 4.65 um vertical (Y)!
        /// For binningmodes, thesesizesaremultiplied.) Drift is the same value as the MGen uses for autoguiding and display.
        /// It’s only valid ifAG is active. It holds the latest measured value as is for the raw coordinates. The value is a signed 8.8 bit fixed point number.
        /// (Note that the drift values are transformed and corrected so that the CCD had 4.85 x 4.85 um square pixels (same forbinned).)
        /// </summary>
        /// <param name="device"></param>
        protected override GuidingResult ExecuteSubCommand(IFTDI device)
        {
            Write(device, SubCommandCode);
            var data = Read(device, 1);

            if (data[0] == 0x00)
            {
                Write(device, (byte)flags);
                var       guiderActive = false;
                FrameInfo frameInfo    = null;
                if (flags.HasFlag(QueryCommandFlag.AutoguidingState))
                {
                    var agState = Read(device, 1);
                    if (agState[0] == 0x01)
                    {
                        guiderActive = true;
                    }
                }
                if (flags.HasFlag(QueryCommandFlag.FrameInfo))
                {
                    var frameInfoData = Read(device, 12);

                    var frameIndex = frameInfoData[0];

                    var posX = ThreeBytesToInt(frameInfoData[1], frameInfoData[2], frameInfoData[3]);
                    var posY = ThreeBytesToInt(frameInfoData[4], frameInfoData[5], frameInfoData[6]);

                    var d_RA  = ToShort(frameInfoData[7], frameInfoData[8]);
                    var d_Dec = ToShort(frameInfoData[9], frameInfoData[10]);
                    var peak  = frameInfoData[11];

                    frameInfo = new FrameInfo(frameIndex, posX, posY, d_RA, d_Dec);
                }
                return(new GuidingResult(guiderActive, frameInfo));
            }
            else if (data[0] == 0xf0)
            {
                return(new GuidingResult(false, null));
            }
            else
            {
                throw new UnexpectedReturnCodeException();
            }
        }
Example #22
0
        protected override CalibrationStatusResult ExecuteSubCommand(IFTDI device)
        {
            Write(device, SubCommandCode);
            var data = Read(device, 3);

            if (data[0] == 0x00)
            {
                var state             = data[1];
                var errorByte         = data[2];
                var error             = string.Empty;
                var calibrationStatus = CalibrationStatus.NotStarted;
                switch (state)
                {
                case 0x00:
                    //CalibrationStatus = "Not yet started";
                    calibrationStatus = CalibrationStatus.NotStarted;
                    break;

                case 0x01:
                    //CalibrationStatus = "Measuring start position";
                    calibrationStatus = CalibrationStatus.MeasuringStartPosition;
                    break;

                case 0x02:
                    //CalibrationStatus = "Moving DEC, eliminating backlash.";
                    calibrationStatus = CalibrationStatus.MovingDecEliminatingBacklash;
                    break;

                case 0x03:
                    //CalibrationStatus = "Measuring / moving DEC.";
                    calibrationStatus = CalibrationStatus.MeasuringDec;
                    break;

                case 0x04:
                    //CalibrationStatus = "Measuring / moving RA.";
                    calibrationStatus = CalibrationStatus.MeasuringRA;
                    break;

                case 0x05:
                    //CalibrationStatus = "Almost done, moving DEC back to original pos";
                    calibrationStatus = CalibrationStatus.AlmostDone;
                    break;

                case 0xff:

                    switch (errorByte)
                    {
                    case 0x00:
                        calibrationStatus = CalibrationStatus.Done;
                        break;

                    case 0x01:
                        calibrationStatus = CalibrationStatus.Error;
                        error             = "The user has canceled the calibration";
                        break;

                    case 0x02:
                        calibrationStatus = CalibrationStatus.Error;
                        error             = "Star has been lost (or wasn't present)";
                        break;

                    case 0x04:
                        calibrationStatus = CalibrationStatus.Error;
                        error             = "Fatal position error detected";
                        break;

                    case 0x05:
                        calibrationStatus = CalibrationStatus.Error;
                        error             = "Orientation error detected";
                        break;
                    }
                    break;
                }
                return(new CalibrationStatusResult(calibrationStatus, error));
            }
            else
            {
                throw new UnexpectedReturnCodeException();
            }
        }
Example #23
0
 protected abstract TResult ExecuteSubCommand(IFTDI device);
Example #24
0
 private void ValidateDeviceParameter(IFTDI device)
 {
     device.SetBaudRate(RequiredBaudRate);
     device.SetTimeouts(Timeout, Timeout);
 }
Example #25
0
 public override MGENResult Execute(IFTDI device)
 {
     Write(device, CommandCode);
     return(new MGENResult(true));
 }
Example #26
0
 public abstract TResult Execute(IFTDI device);
Example #27
0
 protected override MGENResult ExecuteSubCommand(IFTDI device)
 {
     Write(device, SubCommandCode);
     Write(device, (byte)button);
     return(new MGENResult(true));
 }