RemoteControlServer

RemoteControlServer
This script allows operation of Qtegra in slave-mode. This makes it possible to control Qtegra from other software (Labview, MassSpec, Pychron) running on your localhost or over a LAN. The RemoteControlServer can listen for either TCP or UDP (recommended) messages. It will respond with OK for Set... commands, for Get... commands or an error.

code format="csharp" // RegisterAssembly: DefinitionsCore.dll // RegisterAssembly: BasicHardware.dll // RegisterAssembly: PluginManager.dll // RegisterAssembly: HardwareClient.dll // RegisterSystemAssembly: System.dll // RegisterAssembly: SpectrumLibrary.dll // RegisterSystemAssembly: System.Xml.dll // RegisterAssembly: Util.dll

/* Copyright 2011 Jake Ross Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at   http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

__version__=003 using System.IO; using System.Text; using System.Net; using System.Net.Sockets; using System.Collections.Generic; using System.ComponentModel; using System.Globalization;

using Thermo.Imhotep.BasicHardware; using Thermo.Imhotep.Definitions.Core; using Thermo.Imhotep.SpectrumLibrary; using Thermo.Imhotep.Util;

class RemoteControl {

public static void Main {       Instrument= ArgusMC; GetTuningSettings; PrepareEnvironment;

//setup data recording InitializeDataRecord;

if (use_udp) {           UDPServeForever; }       else {            TCPServeForever; }

}   //====================================================================================================================================    //    //    Commands are case sensitive and in CamelCase //   Commands: //       GetTuningSettingsList #return a comma separated string //       SetTuningSettings //       GetData returns tagged data e.g. H2:aaa,L1:bbb,CDD:ccc //       SetIntegrationTime ****currently not enabled**** //        BlankBeam if true set y-symmetry to -50 else return to previous value

//===========Cup/SubCup Configurations============================== //        GetCupConfigurationList //       GetSubCupConfigurationList //       GetActiveCupConfiguration //       GetActiveSubCupConfiguration //        GetSubCupParameters returns list of Deflection voltages and the Ion Counter supply voltage //       SetSubCupConfiguration

//===========Ion Counter============================================ //     ActivateIonCounter //     DeactivateIonCounter

//===========Ion Pump Valve========================================= //     Open  #open the Ion pump to the mass spec //       Close #closes the Ion pump to the mass spec //       GetValveState #returns True for open false for close

//===========Magnet================================================= //       GetMagnetDAC //       SetMagnetDAC #0-10V

//===========Source================================================= //       GetHighVoltage or GetHV //       SetHighVoltage or SetHV  //     GetTrapVoltage //     SetTrapVoltage //     GetElectronEnergy //     SetElectronEnergy //     GetYSymmetry //     SetYSymmetry //     GetZSymmetry //     SetZSymmetry //     GetZFocus //     SetZFocus //     GetIonRepeller //     SetIonRepeller //     GetExtractionLens //     SetExtractionLens

//==========Detectors=============================================== //     GetDeflection //     SetDeflection , //     GetIonCounterVoltage //     SetIonCounterVoltage //==================================================================   //        Error Responses: //           Error: Invalid Command   - the command is poorly formated or does not exist. //           Error: could not set to     //====================================================================================================================================

private static string ParseAndExecuteCommand (string cmd) {

}

private static bool PrepareEnvironment {

}

public static void InitializeDataRecord {

}

public static void Dispose {

}

//====================================================================================================================================   //Qtegra Methods //====================================================================================================================================   public static void SetIonCounterState(bool state) {

}

public static string GetValveState(string hwname) {

}

public static string SetParameter(string hwname, int val) {

}   public static string SetParameter(string hwname, double val) {   }

public static string SetIntegrationTime(double t)   {

}   public static void ScanDataAvailable(object sender, EventArgs e)    {

}

private static bool RunMonitorScan (double? mass) {

}

private static string GetTuningSettings {

}

private static bool SetTuningSettings(string name) {

}

private static string GetSubCupParameters {

}

//-   //     // Get all cup configurations names from the system. //    // A list of cup configuration names. //-   private static List GetCupConfigurations {

}

//-   //     // Get all sub cup configurations names from a cup cupconfiguration. //    //  // A list of sub cup configuration names. //-   private static List GetSubCupConfigurations (string cupConfigurationName) {

}

//-   //     // Activate a cup configuration and sub cup configuration. //    // The cup configuration name. // The sub cup configuration name. // A nullable mass value. If has a value then use the mass for the monitor scan; otherwise use the master cup mass for the monitor scan. // True if successfull; otherwise false. //-   private static bool ActivateCupConfiguration (string cupConfigurationName, string subCupConfigurationName) {

}   //====================================================================================================================================    //Server Methods //====================================================================================================================================   private static void TCPServeForever {

}   private static void UDPServeForever {

}   private static void UDPListen {

}   private static void TCPListen {

}

private static void TCPHandle (TcpClient tcpClient) {

}

//====================================================================================================================================   //Network Methods //====================================================================================================================================   private static void TCPWrite (NetworkStream stream, string cmd) {

}

private static string TCPRead (NetworkStream stream) {

} }

code