コード例 #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 SpectroObjMgrClass();
        }
コード例 #2
0
        private void process_command(ref string full_command, TcpServerConnection connection)
        {
            string[] command_elements = full_command.Split(' ');

            switch (command_elements[0].ToLower())
            {
            case "acquire":
                if (is_acquiring())
                {
                    send_response("err already acquiring\n", connection);
                }
                else
                {
                    start_acquisition();
                }
                send_response("ok\n", connection);
                break;

            case "status":
                if (is_acquiring())
                {
                    send_response("1\n", connection);
                }
                else
                {
                    send_response("0\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)
                {
                    Console.WriteLine("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);
                    send_response(String.Format("ok {0}\n", acq_time_out), connection);
                }
                catch (Exception e)
                {
                    Console.WriteLine("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)
                {
                    Console.WriteLine("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)
                {
                    Console.WriteLine("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 SpectroObjMgrClass();
                    send_response(string.Format("ok\n", grating, position), connection);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error reinitialzing winspec automation objects\n");
                    send_response("err " + e.Message + "\n", connection);
                }
                break;
            }
        }