/// <summary>
 /// Sends command request to the device
 /// </summary>
 /// <param name="RequestString">Command, to be sent to the device</param>
 /// <returns></returns>
 public bool SendCommandRequest(string RequestString)
 {
     try
     {
         GPIB_KEITHLEY_2602A_Device.Write(RequestString);
         return(true);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
         return(false);
     }
 }
            //Overriding basical device functionality

            /// <summary>
            /// Initializes the device
            /// </summary>
            /// <returns>Returns true, if initialization succeed</returns>
            public bool InitDevice()
            {
                try
                {
                    GPIB_KEITHLEY_2602A_Adderss = new NationalInstruments.NI4882.Address(_primaryAddress, _secondaryAddress);
                    GPIB_KEITHLEY_2602A_Device  = new NationalInstruments.NI4882.Device(_boardNumber, GPIB_KEITHLEY_2602A_Adderss);

                    GPIB_KEITHLEY_2602A_Device.Clear();

                    GPIB_KEITHLEY_2602A_Device.Write("beeper.enable = 1 ");

                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        public override bool outputGPIBGroup(GPIBGroup gpibGroup, SettingsData settings)
        {
            lock (remoteLockObj)
            {
                try
                {
                    messageLog(this, new MessageEvent("Received an output gpib group request."));

                    if (gpibGroup == null)
                    {
                        messageLog(this, new MessageEvent("Received a null object, unable to comply."));
                        displayError();
                        return false;
                    }

                    if (!stopAndCleanupTasks())
                        return false;

                    if (!setSettings(settings))
                        return false;

                    foreach (int channelID in usedGpibChannels.Keys)
                    {
                        if (gpibGroup.channelEnabled(channelID))
                        {
                            HardwareChannel hc = usedGpibChannels[channelID];
                            GPIBGroupChannelData channelData = gpibGroup.ChannelDatas[channelID];
                            if (channelData.DataType == GPIBGroupChannelData.GpibChannelDataType.raw_string)
                            {
                                NationalInstruments.NI4882.Device gpibDevice = new NationalInstruments.NI4882.Device(hc.gpibBoardNumber(), niAddress(hc.GpibAddress));
                                gpibDevice.Write(
                                    GpibTask.AddNewlineCharacters(channelData.RawString));
                                messageLog(this, new MessageEvent("Wrote GPIB data : " + channelData.RawString));
                            }
                            else if (channelData.DataType == GPIBGroupChannelData.GpibChannelDataType.string_param_string)
                            {
                                NationalInstruments.NI4882.Device gpibDevice = new NationalInstruments.NI4882.Device(hc.gpibBoardNumber(), niAddress(hc.GpibAddress));
                                if (channelData.StringParameterStrings != null)
                                {
                                    foreach (StringParameterString sps in channelData.StringParameterStrings)
                                    {
                                        gpibDevice.Write(
                                            GpibTask.AddNewlineCharacters(sps.ToString()));
                                        messageLog(this, new MessageEvent("Wrote GPIB data : " + sps.ToString()));
                                    }
                                }
                            }
                            else
                            {
                                messageLog(this, new MessageEvent("Skipping channel " + channelID + ", unsupported data type for an Output Now request: " + channelData.DataType.ToString()));
                                displayError();
                            }
                        }
                    }
                    return true;
                }
                catch (Exception e)
                {
                    messageLog(this, new MessageEvent("Caught exception when attempting to output gpib group: " + e.Message + e.StackTrace));
                    displayError();
                    return false;
                }
            }
        }
Ejemplo n.º 4
0
        public bool runTick(uint elasped_ms)
        {
            if (isDone)
            {
                return(false);
            }

            /* try
             * {*/

            long elaspedTime = DataStructures.Timing.Shared.MillisecondsToTicks(elasped_ms);

            if (currentCommand >= commandBuffer.Count)
            {
                disposeDevice();
                if (this.Done != null)
                {
                    this.Done(this, new NationalInstruments.DAQmx.TaskDoneEventArgs(null));
                }
                isDone = true;
                return(false);
            }
            while (elaspedTime >= commandBuffer[currentCommand].commandTime)
            {
                device.Write(commandBuffer[currentCommand].command);

                AtticusServer.server.messageLog(this, new MessageEvent("Wrote GPIB command " + commandBuffer[currentCommand].command, 1, MessageEvent.MessageTypes.Log, MessageEvent.MessageCategories.GPIB));

                currentCommand++;
                if (currentCommand >= commandBuffer.Count)
                {
                    break;
                }

                if (currentCommand >= commandBuffer.Count)     // we've run out of new commands, so disable the timer.
                {
                    disposeDevice();
                    if (this.Done != null)
                    {
                        this.Done(this, new NationalInstruments.DAQmx.TaskDoneEventArgs(null));
                    }
                    isDone = true;
                    return(false);
                }
            }


            //}

            /*catch (Exception e)
             * {
             *  if (e is ThreadAbortException)
             *  {
             *      disposeDevice();
             *      if (this.Done != null)
             *      {
             *          this.Done(this, new NationalInstruments.DAQmx.TaskDoneEventArgs(null));
             *      }
             *  }
             *  else
             *  {
             *      AtticusServer.server.messageLog(this, new MessageEvent("Caught an exception while running GPIB task for GPIB channel " + logicalChannelID + ": " + e.Message + e.StackTrace));
             *      AtticusServer.server.messageLog(this, new MessageEvent("Aborting GPIB task."));
             *      MainServerForm.instance.DisplayError = true;
             *      disposeDevice();
             *      if (this.Done != null)
             *      {
             *          this.Done(this, new NationalInstruments.DAQmx.TaskDoneEventArgs(e));
             *      }
             *  }
             * }*/
            return(true);
        }
            //Overriding basical device functionality
            /// <summary>
            /// Initializes the device
            /// </summary>
            /// <returns>Returns true, if initialization succeed</returns>
            public bool InitDevice()
            {
                try
                {
                    GPIB_KEITHLEY_2602A_Adderss = new NationalInstruments.NI4882.Address(_primaryAddress, _secondaryAddress);
                    GPIB_KEITHLEY_2602A_Device = new NationalInstruments.NI4882.Device(_boardNumber, GPIB_KEITHLEY_2602A_Adderss);

                    GPIB_KEITHLEY_2602A_Device.Clear();

                    GPIB_KEITHLEY_2602A_Device.Write("beeper.enable = 1 ");

                    return true;
                }
                catch
                {
                    return false;
                }
            }