コード例 #1
0
        /// <summary>
        /// Init. camera with required settings.
        /// </summary>
        private void Initialize()
        {
            TxRx(0x4f, 0x52);                   // Boot the FPGA
            TxRx(0x4f, 0x57);                   // Set system state
            TxRx(0x53, 0xe0, 0x02, 0x00, 0x01); // Set FPGA control register

            TxRx(0x53, 0xae, 0x05, 0x01, 0x00, 0x00, 0x02, 0x00);
            string cal       = BitFun.ByteToHex(TxRx(0x53, 0xaf, 0x12)).Substring(20, 16);
            ushort calADC0C  = (ushort)BitFun.ByteToInt(BitFun.HexToByte(cal.Substring(0, 4)));
            ushort calADC40C = (ushort)BitFun.ByteToInt(BitFun.HexToByte(cal.Substring(4, 4)));
            ushort calDAC0C  = (ushort)BitFun.ByteToInt(BitFun.HexToByte(cal.Substring(8, 4)));
            ushort calDAC40C = (ushort)BitFun.ByteToInt(BitFun.HexToByte(cal.Substring(12, 4)));

            calibrationADC[0] = -40.0 / Convert.ToDouble(calADC0C - calADC40C);           // slope
            calibrationADC[1] = 40.0 - (calibrationADC[0] * Convert.ToDouble(calADC40C)); // intercept
            calibrationDAC[0] = -40.0 / Convert.ToDouble(calDAC0C - calDAC40C);           // slope
            calibrationDAC[1] = 40.0 - (calibrationDAC[0] * Convert.ToDouble(calDAC40C)); // intercept

            GetStatus();
        }
コード例 #2
0
        /// <summary>
        /// Read from device output queue.
        /// </summary>
        private void ReadQ()
        {
            while (go)
            {
                Thread.Sleep(1);

                while (dataAvailable)
                {
                    try
                    {
                        string[] msg = outQ.Dequeue().ToString().Split(',');
                        string[] val = new string[msg.Length - 1];
                        for (int i = 0; i < val.Length; i++)
                        {
                            val[i] = msg[i + 1];
                        }
                        byte[] data = new byte[2];

                        switch (msg[0])
                        {
                        case "IP":
                            ip = val[1];
                            break;

                        case "PING":     // Connected status
                            _connected = val[0] == "PING";
                            break;

                        case "WDT":
                            watchDogState = Convert.ToBoolean(Convert.ToByte(val[0]));
                            watchDogTime  = Convert.ToInt16(val[1]);
                            break;

                        case "VERSION":     // Version from SVN repo of code running on device
                            version = val[0];
                            break;

                        case "TIME":

                            break;

                        case "TEMPB":     // Temperature in bytes

                            break;

                        case "TEMPK":     // Temperature in Kelvin

                            break;

                        case "TEMPC":     // Temperature in Celsius
                            temp = Convert.ToDouble(val[0]);
                            break;

                        case "TEMPF":     // Temperature in Farenheit

                            break;

                        case "LED_TEST":     // LED testing on

                            break;

                        case "LED_DONE":     // LED done on

                            break;

                        case "LED_ERROR":     // LED error on

                            break;

                        case "KV_ENABLE":     // KV enable on
                            kVEnable = Convert.ToBoolean(Convert.ToByte(val[0]));
                            break;

                        case "FIL_READY":     // Fil ready
                            _filReady = Convert.ToBoolean(Convert.ToByte(val[0]));
                            break;

                        case "INTERLOCK":     // Interlock closed
                            interlock = Convert.ToBoolean(Convert.ToByte(val[0]));
                            break;

                        case "XRAYS":     // Xrays detected
                            xRaysOn = Convert.ToBoolean(Convert.ToByte(val[0]));
                            break;

                        case "HVPWR_ADJ":     // HV adjustable volts
                            _hvPwrAdj = Convert.ToDouble(val[0]);
                            break;

                        case "HVPWR_EN":     // HV adj./24v enable

                            break;

                        case "TBPWR_EN":     // Tube aux voltages (+/-5v +3.3v) enable

                            break;

                        case "ADC_BYTES":

                            break;

                        case "ADC_VOLTS":
                            int channel = Convert.ToByte(val[0]);
                            switch (channel)
                            {
                            case monVCh:
                                monV = Convert.ToDouble(val[1]);
                                break;

                            case monACh:
                                monA = Convert.ToDouble(val[1]);
                                break;
                            }
                            break;

                        case "ADC_CONVERT":

                            break;

                        case "ADC_SLOPE":

                            break;

                        case "ADC_OFFSET":

                            break;

                        case "ADC_DEFAULTS":

                            break;

                        case "DAC_BYTES":

                            break;

                        case "DAC_VOLTS":
                            channel = Convert.ToByte(val[0]);
                            switch (channel)
                            {
                            case 0:
                                _setV = Convert.ToDouble(val[1]);
                                break;

                            case 1:
                                _setA = Convert.ToDouble(val[1]);
                                break;
                            }
                            break;

                        case "DAC_CONVERT":

                            break;

                        case "DAC_SLOPE":

                            break;

                        case "DAC_OFFSET":

                            break;

                        case "DAC_DEFAULT":

                            break;

                        case "EXT_COMM":

                            break;

                        case "00@I2C_READ":
                            for (int i = 0; i < 128; i++)
                            {
                                registers[i] = Convert.ToByte(val[1 + i]);
                            }
                            break;

                        case "01@I2C_READ":
                            bool[] s = BitFun.HexToBitArray(Convert.ToByte(val[1]).ToString("X2"));
                            status["Interlock"]  = s[0];
                            status["HV On"]      = s[1];
                            status["HVPG"]       = s[2];
                            status["Tube Ready"] = s[3];
                            status["Faulted"]    = s[7];
                            break;

                        case "02@I2C_READ":
                            bool[] f = BitFun.HexToBitArray(Convert.ToByte(val[1]).ToString("X2"));
                            faults["Booted"]      = f[0];
                            faults["Interlock"]   = f[1];
                            faults["Unstable"]    = f[2];
                            faults["HV"]          = f[3];
                            faults["Temperature"] = f[4];
                            faults["Timeout"]     = f[5];
                            break;

                        case "1B@I2C_READ":
                            data[0] = Convert.ToByte(val[1]);
                            data[1] = Convert.ToByte(val[2]);
                            _setV   = BitFun.ByteToInt(data, true) / bitsPerkV;
                            data[0] = Convert.ToByte(val[3]);
                            data[1] = Convert.ToByte(val[4]);
                            _setA   = BitFun.ByteToInt(data, true) / bitsPeruA;
                            data[0] = Convert.ToByte(val[5]);
                            data[1] = Convert.ToByte(val[6]);
                            monV    = BitFun.ByteToInt(data, true) / bitsPerkV;
                            data[0] = Convert.ToByte(val[7]);
                            data[1] = Convert.ToByte(val[8]);
                            monA    = BitFun.ByteToInt(data, true) / bitsPeruA;
                            break;

                        case "38@I2C_READ":
                            kVEnable = Convert.ToByte(val[1]) == 1;
                            break;

                        case "128@SPI_READ":
                            data[0] = Convert.ToByte(val[1]);
                            data[1] = Convert.ToByte(val[2]);
                            monV    = BitFun.ByteToInt(data, true) / bitsPerkV;
                            break;

                        case "192@SPI_READ":
                            data[0] = Convert.ToByte(val[1]);
                            data[1] = Convert.ToByte(val[2]);
                            monA    = BitFun.ByteToInt(data, true) / bitsPeruA;
                            break;
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }