Genesis2000用c#開發外掛

來源:互聯網
上載者:User

標籤:

先上官方的說明

gateway is a command line utility for sending messages and commands to Genesis processes. The gateway command works between all systems that are connected to the same gnd server (in a client-server mode).

This command allows you send messages or run commands or scripts on any genesis process currently running without having to interfere with the GUI on that station.

 

Running gateway does not require any additional licenses. The program itself is located in $GENESIS_DIR/exx/misc  where xx is the version number (eg. e72)

 

gateway may be called in one of the following modes:

 

gateway <address> <message>

Sends a message to an address

gateway ’WHO <address>’

Returns matching address

gateway ’PID <address>’

Returns process IDs of matching adress

gateway <address>

Opens an interactive session

 

  • <address> is formed as <user>@<computer>.<display name>, where <user> is the Genesis login name, <computer> is the name of the computer, and <display> is the name of the X Display that is displaying the “get” process.

 

  • As from v7.1, <address> can also be formed as <pid>@computer.display, where <pid> is the process id of the get process, <computer> is the name of the computer, and <display> is the name of the X Display that is displaying the “get” process. This can be important if there are two get’s running on the same computer/display

 

 

  • A star symbol (“*”) may be used for globbing any part of an address.

 

  • <message> may be any of the following:

 

WHO <address>

This message returns a space separated list of all addresses matching the <address>

 

PID <address>

This message returns a space separated list of the Process IDs of all addresses matching the <address>.

 

COM <genesis line mode command>

This message send a Genesis line mode command to all Genesis processes matching the specified address, unless the operator has specified, “DON’T accept messages” in the clipboard. This message returns zero if the command completed properly. Otherwise it returns a status code.

 

 

MSG <message text>

This will cause all Genesis processes matching the specified address to receive a message and display it to the operator, unless the operator has specified “DON’T accept messages” in the clipboard.

 

ERR <error code>

This returns the display string of the error code.

 

   COMANS

              This returns the COMANS of the last COM command

 

When working in an interactive session, any of the above messages may be sent.

 

A period “.” on a line by itself causes the gateway to exit. When you wish to close the session, the command must be used, since even if gateway has finished reading its standard input, it continues polling for more

messages.

Examples

 

# Print a list of all Genesis users

% gateway ’WHO *’

# Print a list of all the instances that “ben” is logged in on Genesis

% gateway ’WHO [email protected]*’

# Print the process IDs of all the instances of “ben” logged in on jupiter.

% gateway ’PID [email protected]’

# Open a job on a specific Genesis process.

% gateway [email protected] ’COM open_job,job=1745’

# An interactive session

% gateway [email protected]

COM open_job,job=1745

COM script_run,name=/my_scripts/run_analysis,params=pcb

.

 

 

Note   “get” may be run with the “-x” option and without a script. This puts Genesis into a mode where it will respond to gateway COM messages but will operate without a user interface.

 

Note     This feature first appeared in Genesis Version 6.0c.

 

In Genesis v7.1, Gateway recognizes addresses of the following form:

 

% gateway <pid>@computer.display

 

To open a session with a get process with pid 17777 use:

 

% gateway %[email protected]

 

(The % notation was chosen since a username could also be numeric.)

 

Also, in Genesis v7.1, the new command COMANS has been added. This command returns the COMANS of the last COM command. Here is a sample session:

 

% gateway [email protected]

COM open_job,job=0.01745

0

COM open_entity,job=0.01745,type=step,name=pcb

0

COM filter_area_start

0

COM filter_area_xy,x=1,y=1

0

COM filter_area_xy,x=0,y=0

0

COM filter_area_end

0

COMANS

7

 好吧這麼多英文我看著也頭疼,總之外掛需要用到gateway程式,c#程式就是通過process類進行輸入和輸出,如下代碼

using System;using System.Collections.Generic;using System.Diagnostics;using System.IO;using System.Linq;using System.Text;namespace WindowsFormsApplication4{   public class Genesis    {        //gateway的運行命令色這個樣子的 gateway <address> <message>        //address為genesis上的資料: 使用者名稱@機器名.機器名        //這裡我只取第一個使用者名稱為指令碼執行的地方        /// <summary>        /// 程式啟動並執行對應使用者地址        /// </summary>        private string address { get; set; }        /// <summary>        ///從系統內容變數擷取GENESIS的根目錄        /// </summary>        string GENESIS_DIR { get { return Environment.GetEnvironmentVariable("GENESIS_DIR");} }        /// <summary>        ///從系統內容變數擷取GENESIS的程式目錄        /// </summary>        string GENESIS_EDIR { get { return Environment.GetEnvironmentVariable("GENESIS_EDIR"); } }       /// <summary>       /// 發送指令給genesis       /// </summary>       /// <param name="cmdText"></param>       /// <returns></returns>       public Genesis()       {            //返回結果以的使用者以\r\n隔開要替換掉為,再分組           string s = SendCommand("\"WHO\"");            string[] users = s.Trim().Replace(‘ ‘,‘,‘).Split(‘,‘);           if (users.Count()>0)           {               address = users[users.Count()-1];           }       }       private string SendCommand(string cmdText)       {            Process p=new Process();            p.StartInfo.FileName = GENESIS_EDIR + @"\misc\gateway.exe";            //返回錯誤提示            p.StartInfo.RedirectStandardError = true;            //可以發送指令            p.StartInfo.RedirectStandardInput = true;            //可以用接受指令執行結果            p.StartInfo.RedirectStandardOutput = true;            //執行命令不顯示視窗            p.StartInfo.CreateNoWindow = true;            ///執行指令            p.StartInfo.Arguments = cmdText;           p.StartInfo.UseShellExecute = false;            //            p.Start();            //接收指令執行結果            StreamReader read = p.StandardOutput;           string s = read.ReadLine();            //結束進程            p.Close();            return s;       }       public string COM(string cmdText)       {           return SendCommand(string.Format(address+ " \"COM  {0}\"",cmdText));       }    }}

  核心的代碼就是sendcommand函數,由於genesis有多個特殊指令,這裡我唯寫了COM指令;還有擷取使用者地址的時候開啟系統的工作管理員看一下是否有多個gnd或gateway運行,如果存在多個gnd程式就會崩潰,gateway最好只留一個

接著隊代碼進行進行測試,建立一個winform程式,添加兩個 richTextBox一個用來輸入指令,一個接收傳回值

發送指令事件代碼

 private void button1_Click(object sender, EventArgs e)        {            Genesis gen=new Genesis();            //richTextBox2.AppendText(gen.COM("clipb_open_job,job=test,update_clipboard=view_job"));            richTextBox2.AppendText(gen.COM(  richTextBox1.Text));        }

  編譯好程式開啟genesis隊程式進行測試,發送指令前

發送指令後

程式測試完成並能接收到結果0;

Genesis2000用c#開發外掛

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.