コード例 #1
0
        public RfsgTask(SequenceData sequence, SettingsData settings, int channelID, string rfsgDeviceName, DeviceSettings deviceSettings)
        {
            if (!settings.logicalChannelManager.GPIBs.ContainsKey(channelID))
            {
                throw new InvalidDataException("Attempted to create an rfsg task with channel id " + channelID + ", which does not exist in the settings as a gpib channel.");
            }

            this.channelID = channelID;



            int currentStepIndex = -1;

            //measured in ticks. 1 tick = 100 ns.
            long currentTime = 0;

            commandBuffer = new List <RFSGCommand>();

            if (deviceSettings.AutoInitate)
            {
                RFSGCommand com = new RFSGCommand();
                com.commandTime = 0;
                com.commandType = RFSGCommand.CommandType.Initiate;
                commandBuffer.Add(com);
            }

            if (deviceSettings.AutoEnable)
            {
                RFSGCommand com = new RFSGCommand();
                com.commandTime = 0;
                com.commandType = RFSGCommand.CommandType.EnableOutput;
                commandBuffer.Add(com);
            }

            long postRetriggerTime = 100; // corresponds to 10us.

            // A workaround to issue when using software timed groups in
            // fpga-retriggered words

            // the workaround: delay the software timed group by an immesurable amount
            // if it is started in a retriggered word


            // This functionality is sort of somewhat duplicated in sequencedata.generatebuffers. It would be good
            // to come up with a more coherent framework to do these sorts of operations.
            while (true)
            {
                currentStepIndex++;

                if (currentStepIndex >= sequence.TimeSteps.Count)
                {
                    break;
                }

                TimeStep currentStep = sequence.TimeSteps[currentStepIndex];

                if (!currentStep.StepEnabled)
                {
                    continue;
                }

                if (currentStep.GpibGroup == null || !currentStep.GpibGroup.channelEnabled(channelID))
                {
                    currentTime += seconds_to_ticks(currentStep.StepDuration.getBaseValue());
                    continue;
                }

                long postTime = 0;
                if (currentStep.RetriggerOptions.WaitForRetrigger)
                {
                    postTime = postRetriggerTime;
                }

                // determine the index of the next step in which this channel has an action
                int nextEnabledStepIndex = sequence.findNextGpibChannelEnabledTimestep(currentStepIndex, channelID);

                long groupDuration = seconds_to_ticks(sequence.timeBetweenSteps(currentStepIndex, nextEnabledStepIndex));

                // now take action:

                GPIBGroupChannelData channelData = currentStep.GpibGroup.getChannelData(channelID);

                if (channelData.DataType == GPIBGroupChannelData.GpibChannelDataType.raw_string)
                {
                    throw new Exception("Not yet implemented.");

                    /*
                     *
                     * // Raw string commands just get added
                     * string stringWithCorrectNewlines = AddNewlineCharacters(channelData.RawString);
                     *
                     * commandBuffer.Add(new GpibCommand(stringWithCorrectNewlines, currentTime));*/
                }
                else if (channelData.DataType == GPIBGroupChannelData.GpibChannelDataType.voltage_frequency_waveform)
                {
                    double[] amplitudeArray;
                    double[] frequencyArray;

                    // get amplitude and frequency value arrays
                    int    nSamples         = (int)(ticks_to_seconds(groupDuration) * (double)deviceSettings.SampleClockRate);
                    double secondsPerSample = ticks_to_seconds(groupDuration) / (double)nSamples;

                    amplitudeArray = channelData.volts.getInterpolation(nSamples, 0, ticks_to_seconds(groupDuration), sequence.Variables, sequence.CommonWaveforms);
                    frequencyArray = channelData.frequency.getInterpolation(nSamples, 0, ticks_to_seconds(groupDuration), sequence.Variables, sequence.CommonWaveforms);

                    double lastFreq = Double.MinValue;
                    double lastAmp  = Double.MinValue;

                    for (int i = 0; i < nSamples; i++)
                    {
                        double currentFreq = frequencyArray[i];
                        double currentAmp  = amplitudeArray[i];
                        if (currentFreq != lastFreq || currentAmp != lastAmp)
                        {
                            RFSGCommand command = new RFSGCommand();
                            command.commandType = RFSGCommand.CommandType.AmplitudeFrequency;
                            command.frequency   = currentFreq;
                            command.amplitude   = Vpp_to_dBm(currentAmp);
                            command.commandTime = (long)(currentTime + i * secondsPerSample * 10000000) + postTime;

                            commandBuffer.Add(command);
                        }
                        lastAmp  = currentAmp;
                        lastFreq = currentFreq;
                    }
                }

                else if (channelData.DataType == GPIBGroupChannelData.GpibChannelDataType.string_param_string)
                {
                    foreach (StringParameterString sps in channelData.StringParameterStrings)
                    {
                        string clean = sps.Prefix.Trim().ToUpper();
                        if (clean == "ENABLE")
                        {
                            RFSGCommand com = new RFSGCommand();
                            com.commandType = RFSGCommand.CommandType.EnableOutput;
                            com.commandTime = currentTime + postTime;
                            commandBuffer.Add(com);
                        }

                        if (clean == "DISABLE")
                        {
                            RFSGCommand com = new RFSGCommand();
                            com.commandType = RFSGCommand.CommandType.DisableOutput;
                            com.commandTime = currentTime + postTime;
                            commandBuffer.Add(com);
                        }

                        if (clean == "ABORT")
                        {
                            RFSGCommand com = new RFSGCommand();
                            com.commandType = RFSGCommand.CommandType.Abort;
                            com.commandTime = currentTime + postTime;
                            commandBuffer.Add(com);
                        }

                        if (clean == "INITIATE")
                        {
                            RFSGCommand com = new RFSGCommand();
                            com.commandType = RFSGCommand.CommandType.Initiate;
                            com.commandTime = currentTime + postTime;
                            commandBuffer.Add(com);
                        }
                    }
                }

                currentTime += seconds_to_ticks(currentStep.StepDuration.getBaseValue());
            }


            if (rfsgDevices == null)
            {
                rfsgDevices         = new Dictionary <string, niRFSG>();
                rfsgDeviceInitiated = new Dictionary <niRFSG, bool>();
            }

            if (rfsgDevices.ContainsKey(rfsgDeviceName))
            {
                rfsgDevice = rfsgDevices[rfsgDeviceName];
            }
            else
            {
                try
                {
                    rfsgDevice = new niRFSG(rfsgDeviceName, true, false);
                }
                catch (Exception e)
                {
                    throw new InvalidDataException("Caught exception when attempting to instantiate an rfsg device named " + rfsgDeviceName + ". Maybe a device by this name does not exist? Exception message: " + e.Message);
                }
                rfsgDevices.Add(rfsgDeviceName, rfsgDevice);
                rfsgDeviceInitiated.Add(rfsgDevice, false);
            }


            if (deviceSettings.MasterTimebaseSource != null && deviceSettings.MasterTimebaseSource != "")
            {
                rfsgDevice.ConfigureRefClock(deviceSettings.MasterTimebaseSource, 10000000);
            }
        }
コード例 #2
0
        private void outputRfsgCommand(RFSGCommand command)
        {
            bool success = false;
            switch (command.commandType)
            {
                case RFSGCommand.CommandType.AmplitudeFrequency:
                    rfsgDevice.ConfigureRF(command.frequency, command.amplitude);

                    AtticusServer.server.messageLog(this, new MessageEvent("RFSG commanded to frequence(Hz)/amplitude(dBm) " + command.frequency + "/" + command.amplitude, 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));

                    break;
                case RFSGCommand.CommandType.EnableOutput:
                    try
                    {
                        rfsgDevice.ConfigureOutputEnabled(true);
                        success = true;
                    }
                    catch (Exception) { }

                    if (success)
                        AtticusServer.server.messageLog(this, new MessageEvent("RFSG commanded to enable output", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));
                    else
                        AtticusServer.server.messageLog(this, new MessageEvent("RSG command to enable output gave error. Output probably already enabled.", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));

                    break;

                case RFSGCommand.CommandType.DisableOutput:
                    try
                    {
                        rfsgDevice.ConfigureOutputEnabled(false);
                        success = true;
                    }
                    catch (Exception)
                    {
                    }

                    if (success)
                        AtticusServer.server.messageLog(this, new MessageEvent("RFSG commanded to disable output", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));
                    else
                        AtticusServer.server.messageLog(this, new MessageEvent("RFSG command to disable output gave error. Output probably already disabled.", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));

                    break;

                case RFSGCommand.CommandType.Initiate:
                    {

                        if (rfsgDeviceInitiated[rfsgDevice])
                        {

                            AtticusServer.server.messageLog(this, new MessageEvent("RFSG device believed to be initiated already. Skipping initiate command.", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));
                            break;
                        }

                        try
                        {
                            rfsgDevice.Initiate();
                            success = true;
                        }
                        catch (Exception)
                        {
                        }

                        if (success)
                            rfsgDeviceInitiated[rfsgDevice] = true;
                        else
                            rfsgDeviceInitiated[rfsgDevice] = false;

                        if (success)
                            AtticusServer.server.messageLog(this, new MessageEvent("RFSG commanded to initiate output (enter committed state)", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));
                        else
                            AtticusServer.server.messageLog(this, new MessageEvent("RFSG command to initiate device gave error. Device probably already initiated.", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));

                    }
                    break;

                case RFSGCommand.CommandType.Abort:

                    rfsgDevice.Abort();

                    AtticusServer.server.messageLog(this, new MessageEvent("RFSG commanded to abort output (enter configuration state)", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));

                    rfsgDeviceInitiated[rfsgDevice] = false;
                    break;
            }
        }
コード例 #3
0
        private void outputRfsgCommand(RFSGCommand command)
        {
            bool success = false;

            switch (command.commandType)
            {
            case RFSGCommand.CommandType.AmplitudeFrequency:
                rfsgDevice.ConfigureRF(command.frequency, command.amplitude);

                AtticusServer.server.messageLog(this, new MessageEvent("RFSG commanded to frequence(Hz)/amplitude(dBm) " + command.frequency + "/" + command.amplitude, 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));

                break;

            case RFSGCommand.CommandType.EnableOutput:
                try
                {
                    rfsgDevice.ConfigureOutputEnabled(true);
                    success = true;
                }
                catch (Exception) { }


                if (success)
                {
                    AtticusServer.server.messageLog(this, new MessageEvent("RFSG commanded to enable output", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));
                }
                else
                {
                    AtticusServer.server.messageLog(this, new MessageEvent("RSG command to enable output gave error. Output probably already enabled.", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));
                }

                break;

            case RFSGCommand.CommandType.DisableOutput:
                try
                {
                    rfsgDevice.ConfigureOutputEnabled(false);
                    success = true;
                }
                catch (Exception)
                {
                }

                if (success)
                {
                    AtticusServer.server.messageLog(this, new MessageEvent("RFSG commanded to disable output", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));
                }
                else
                {
                    AtticusServer.server.messageLog(this, new MessageEvent("RFSG command to disable output gave error. Output probably already disabled.", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));
                }

                break;

            case RFSGCommand.CommandType.Initiate:
            {
                if (rfsgDeviceInitiated[rfsgDevice])
                {
                    AtticusServer.server.messageLog(this, new MessageEvent("RFSG device believed to be initiated already. Skipping initiate command.", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));
                    break;
                }

                try
                {
                    rfsgDevice.Initiate();
                    success = true;
                }
                catch (Exception)
                {
                }

                if (success)
                {
                    rfsgDeviceInitiated[rfsgDevice] = true;
                }
                else
                {
                    rfsgDeviceInitiated[rfsgDevice] = false;
                }


                if (success)
                {
                    AtticusServer.server.messageLog(this, new MessageEvent("RFSG commanded to initiate output (enter committed state)", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));
                }
                else
                {
                    AtticusServer.server.messageLog(this, new MessageEvent("RFSG command to initiate device gave error. Device probably already initiated.", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));
                }
            }
            break;


            case RFSGCommand.CommandType.Abort:

                rfsgDevice.Abort();

                AtticusServer.server.messageLog(this, new MessageEvent("RFSG commanded to abort output (enter configuration state)", 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.RFSG));

                rfsgDeviceInitiated[rfsgDevice] = false;
                break;
            }
        }
コード例 #4
0
        public RfsgTask(SequenceData sequence, SettingsData settings, int channelID, string rfsgDeviceName, DeviceSettings deviceSettings)
        {
            if (!settings.logicalChannelManager.GPIBs.ContainsKey(channelID))
            {
                throw new InvalidDataException("Attempted to create an rfsg task with channel id " + channelID + ", which does not exist in the settings as a gpib channel.");
            }

            this.channelID = channelID;

            int currentStepIndex = -1;

            //measured in ticks. 1 tick = 100 ns.
            long currentTime = 0;

            commandBuffer = new List<RFSGCommand>();

            if (deviceSettings.AutoInitate)
            {
                RFSGCommand com = new RFSGCommand();
                com.commandTime = 0;
                com.commandType = RFSGCommand.CommandType.Initiate;
                commandBuffer.Add(com);
            }

            if (deviceSettings.AutoEnable)
            {
                RFSGCommand com = new RFSGCommand();
                com.commandTime = 0;
                com.commandType = RFSGCommand.CommandType.EnableOutput;
                commandBuffer.Add(com);
            }

            long postRetriggerTime = 100; // corresponds to 10us.
            // A workaround to issue when using software timed groups in
            // fpga-retriggered words

            // the workaround: delay the software timed group by an immesurable amount
            // if it is started in a retriggered word

            // This functionality is sort of somewhat duplicated in sequencedata.generatebuffers. It would be good
            // to come up with a more coherent framework to do these sorts of operations.
            while (true)
            {
                currentStepIndex++;

                if (currentStepIndex >= sequence.TimeSteps.Count)
                    break;

                TimeStep currentStep = sequence.TimeSteps[currentStepIndex];

                if (!currentStep.StepEnabled)
                    continue;

                if (currentStep.GpibGroup == null || !currentStep.GpibGroup.channelEnabled(channelID))
                {
                    currentTime += seconds_to_ticks(currentStep.StepDuration.getBaseValue());
                    continue;
                }

                long postTime = 0;
                if (currentStep.RetriggerOptions.WaitForRetrigger)
                    postTime = postRetriggerTime;

                // determine the index of the next step in which this channel has an action
                int nextEnabledStepIndex = sequence.findNextGpibChannelEnabledTimestep(currentStepIndex, channelID);

                long groupDuration = seconds_to_ticks(sequence.timeBetweenSteps(currentStepIndex, nextEnabledStepIndex));

                // now take action:

                GPIBGroupChannelData channelData = currentStep.GpibGroup.getChannelData(channelID);

                if (channelData.DataType == GPIBGroupChannelData.GpibChannelDataType.raw_string)
                {

                    throw new Exception("Not yet implemented.");
                    /*

                    // Raw string commands just get added
                    string stringWithCorrectNewlines = AddNewlineCharacters(channelData.RawString);

                    commandBuffer.Add(new GpibCommand(stringWithCorrectNewlines, currentTime));*/
                }
                else if (channelData.DataType == GPIBGroupChannelData.GpibChannelDataType.voltage_frequency_waveform)
                {

                    double[] amplitudeArray;
                    double[] frequencyArray;

                    // get amplitude and frequency value arrays
                    int nSamples = (int)(ticks_to_seconds(groupDuration) * (double)deviceSettings.SampleClockRate);
                    double secondsPerSample = ticks_to_seconds(groupDuration) / (double)nSamples;

                    amplitudeArray = channelData.volts.getInterpolation(nSamples, 0, ticks_to_seconds(groupDuration), sequence.Variables, sequence.CommonWaveforms);
                    frequencyArray = channelData.frequency.getInterpolation(nSamples, 0, ticks_to_seconds(groupDuration), sequence.Variables, sequence.CommonWaveforms);

                    double lastFreq = Double.MinValue;
                    double lastAmp = Double.MinValue;

                    for (int i = 0; i < nSamples; i++)
                    {
                        double currentFreq = frequencyArray[i];
                        double currentAmp = amplitudeArray[i];
                        if (currentFreq != lastFreq || currentAmp != lastAmp)
                        {
                            RFSGCommand command = new RFSGCommand();
                            command.commandType = RFSGCommand.CommandType.AmplitudeFrequency;
                            command.frequency = currentFreq;
                            command.amplitude = Vpp_to_dBm(currentAmp);
                            command.commandTime = (long)(currentTime + i * secondsPerSample * 10000000) + postTime;

                            commandBuffer.Add(command);
                        }
                        lastAmp = currentAmp;
                        lastFreq = currentFreq;

                    }
                }

                else if (channelData.DataType == GPIBGroupChannelData.GpibChannelDataType.string_param_string)
                {
                    foreach (StringParameterString sps in channelData.StringParameterStrings)
                    {
                        string clean = sps.Prefix.Trim().ToUpper();
                        if (clean == "ENABLE")
                        {
                            RFSGCommand com = new RFSGCommand();
                            com.commandType = RFSGCommand.CommandType.EnableOutput;
                            com.commandTime = currentTime + postTime;
                            commandBuffer.Add(com);
                        }

                        if (clean == "DISABLE")
                        {
                            RFSGCommand com = new RFSGCommand();
                            com.commandType = RFSGCommand.CommandType.DisableOutput;
                            com.commandTime = currentTime + postTime;
                            commandBuffer.Add(com);
                        }

                        if (clean == "ABORT")
                        {
                            RFSGCommand com = new RFSGCommand();
                            com.commandType = RFSGCommand.CommandType.Abort;
                            com.commandTime = currentTime + postTime;
                            commandBuffer.Add(com);
                        }

                        if (clean == "INITIATE")
                        {
                            RFSGCommand com = new RFSGCommand();
                            com.commandType = RFSGCommand.CommandType.Initiate;
                            com.commandTime = currentTime + postTime;
                            commandBuffer.Add(com);
                        }
                    }
                }

                currentTime += seconds_to_ticks(currentStep.StepDuration.getBaseValue());
            }

            if (rfsgDevices == null)
            {
                rfsgDevices = new Dictionary<string, niRFSG>();
                rfsgDeviceInitiated = new Dictionary<niRFSG, bool>();
            }

            if (rfsgDevices.ContainsKey(rfsgDeviceName))
            {
                rfsgDevice = rfsgDevices[rfsgDeviceName];
            }
            else
            {

                try
                {
                    rfsgDevice = new niRFSG(rfsgDeviceName, true, false);
                }
                catch (Exception e)
                {
                    throw new InvalidDataException("Caught exception when attempting to instantiate an rfsg device named " + rfsgDeviceName + ". Maybe a device by this name does not exist? Exception message: " + e.Message);
                }
                rfsgDevices.Add(rfsgDeviceName, rfsgDevice);
                rfsgDeviceInitiated.Add(rfsgDevice, false);
            }

            if (deviceSettings.MasterTimebaseSource != null && deviceSettings.MasterTimebaseSource != "")
            {
                rfsgDevice.ConfigureRefClock(deviceSettings.MasterTimebaseSource, 10000000);
            }
        }