コード例 #1
0
        public WinspecInterfaceServer()
        {
            // Build the TCP/IP Server and connect the event handlers
            server                  = new TcpServer();
            server.OnConnect       += this.OnConnect_Handler;
            server.OnDataAvailable += this.OnDataAvailable_Handler;
            server.OnError         += this.OnError_Handler;

            // Setup the Winspec interface
            doc  = null;            //Initialize the current doc to null;
            app  = new Winx32App(); // Will either launch or connect to the current Winspec instance
            exp  = new ExpSetup();
            spec = new SpectroObjMgr();
        }
コード例 #2
0
        private void process_command(ref string full_command, TcpServerConnection connection)
        {
            OnLog(new LogEventArgs("Processing Command: " + full_command));

            string[] command_elements = full_command.Split(' ');

            switch (command_elements[0].ToLower())
            {
            case "acquire":
                if (is_acquiring())
                {
                    send_response("err already acquiring\n", connection);
                }
                else
                {
                    try
                    {
                        start_acquisition();
                        send_response("ok\n", connection);
                    }
                    catch (Exception e)
                    {
                        OnLog(new LogEventArgs("Error starting acquisition: " + e.ToString()));
                        send_response("err " + e.Message + "\n", connection);
                    }
                }
                break;

            case "status":
                try
                {
                    if (is_acquiring())
                    {
                        send_response("ok 1\n", connection);
                    }
                    else
                    {
                        send_response("ok 0\n", connection);
                    }
                    break;
                }
                catch (Exception e)
                {
                    OnLog(new LogEventArgs("Error getting status: " + e.ToString()));
                    send_response("err " + e.Message + "\n", connection);
                }
                break;


            case "get_data":
                if (is_acquiring())
                {
                    send_response("err acquiring\n", connection);
                    break;
                }
                else if (doc == null)
                {
                    send_response("err no data available\n", connection);
                    break;
                }
                else
                {
                    send_current_data(connection);
                }
                break;

            case "set_acq_time":
                try
                {
                    object obj = Convert.ToDouble(command_elements[1]);
                    exp.SetParam(EXP_CMD.EXP_EXPOSURE, ref obj);
                    send_response("ok\n", connection);
                }
                catch (Exception e)
                {
                    OnLog(new LogEventArgs("Error setting acquisition time\n"));
                    send_response("err " + e.Message + "\n", connection);
                }
                break;

            case "get_acq_time":
                try
                {
                    short  res;
                    double acq_time_out = (double)exp.GetParam(EXP_CMD.EXP_EXPOSURE, out res);
                    OnLog(new LogEventArgs(string.Format("result = {0}", res)));
                    send_response(String.Format("ok {0}\n", acq_time_out), connection);
                }
                catch (Exception e)
                {
                    OnLog(new LogEventArgs("Error fetching acquisition time\n"));
                    send_response("err " + e.Message + "\n", connection);
                }
                break;

            case "set_grating":
                try
                {
                    object grating  = Convert.ToInt32(command_elements[1]);
                    object position = Convert.ToDouble(command_elements[2]);
                    spec.Current.SetParam(SPT_CMD.SPT_NEW_GRATING, ref grating);
                    spec.Current.SetParam(SPT_CMD.SPT_NEW_POSITION, ref position);
                    spec.Current.Move();
                    send_response("ok\n", connection);
                }
                catch (Exception e)
                {
                    OnLog(new LogEventArgs("Error setting grating\n"));
                    send_response("err " + e.Message + "\n", connection);
                }
                break;

            case "get_grating":
                try
                {
                    object grating  = new object();
                    object position = new object();
                    spec.Current.GetParam(SPT_CMD.SPT_INST_CUR_GRAT_NUM, 0, out grating);
                    spec.Current.GetParam(SPT_CMD.SPT_INST_CUR_GRAT_POS, 0, out position);
                    send_response(string.Format("ok {0} {1}\n", grating, position), connection);
                }
                catch (Exception e)
                {
                    OnLog(new LogEventArgs("Error fetching grating\n"));
                    send_response("err " + e.Message + "\n", connection);
                }
                break;

            case "reinitialize":
                try
                {
                    // Setup the Winspec interface
                    doc  = null;            //Initialize the current doc to null;
                    app  = new Winx32App(); // Will either launch or connect to the current Winspec instance
                    exp  = new ExpSetup();
                    spec = new SpectroObjMgr();
                    send_response(string.Format("ok\n"), connection);
                }
                catch (Exception e)
                {
                    OnLog(new LogEventArgs("Error reinitialzing winspec automation objects\n"));
                    send_response("err " + e.Message + "\n", connection);
                }
                break;
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: wcyjames/stackbot
 public Form1()
 {
     InitializeComponent();
     app = new WINX32Lib.Winx32App();
 }