这边文章的目的是给予那些在PCB使用Genesis2000程序脚本开发的人员提供.net平台下的开发方法。
目前genesis脚本的开发的语言主要为cshell,perl和tcl,相对于学过c#的人需要学习成本,我打听过用C#开发脚本的接口的价格最少都需要1000块钱,本着开源的思想我吧这几天研究的成果公布发表给大家!
1.genesis脚本的运行机制(这里拿cshell来说),(以我的电脑来举例子)首先程序要运行c:genesise100allscr_start.csh,然后运行c:genesissyshooksscript_start.csh,最后再运行脚本;
详细看附件
2.不管怎么样子的脚本都是基于命令行的,如windows上的cmd;
知道了这两个条件下面我们开始编写genesis辅助类
using System; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; public class Genesis { public string prefix, lmc, msg; public string READANS, COMANS, PAUSANS, MOUSEANS; public int STATUS=0; public System.IO.StreamReader conv; public System.IO.StreamReader @in; public Genesis() { //exe程序发送指令需要以这个字符串开头,genesis才会识别 this.prefix = "@%#%@"; this.blank(); return; } public virtual void blank() { this.STATUS = 0; this.READANS = ""; this.COMANS = ""; this.PAUSANS = ""; this.MOUSEANS = ""; return; } /// <summary> /// 执行指令 /// </summary> /// <param name="cmd"></param> /// <param name="arg"></param> /// <returns></returns> public virtual int sendCmd(string cmd, string arg) { this.blank(); this.lmc = this.prefix + cmd + " " + arg + " "; Console.Write(this.lmc); return 0; } /// <summary> /// 执行genesis2000 line mode command动作 /// </summary> /// <param name="arg">指令</param> /// <returns></returns> public virtual int COM(string arg) { this.sendCmd("COM", arg); try { int.TryParse(Console.ReadLine(),out STATUS); this.COMANS = Console.ReadLine(); this.READANS = this.COMANS; } catch (IOException e) { Console.WriteLine("IO Error: " + e.Message); } return this.STATUS; } /// <summary> /// 用于暂停当前运行程序,等待用户做其它动作后继续执行程序或无条件退出程序。 /// </summary> /// <param name="msg"></param> /// <returns></returns> public virtual int PAUSE(string msg) { this.sendCmd("PAUSE", msg); try { int.TryParse(Console.ReadLine(), out this.STATUS); this.READANS = Console.ReadLine(); this.PAUSANS = Console.ReadLine(); } catch (IOException e) { Console.WriteLine("IO Error: " + e.Message); } return this.STATUS; } /// <summary> /// 设置活动工作界面 /// </summary> /// <param name="arg">指令</param> /// <returns></returns> public virtual int AUX(string arg) { this.sendCmd("AUX", msg); try { //this.STATUS = this.in.readLine(); this.STATUS = int.Parse(Console.ReadLine()); this.COMANS = Console.ReadLine(); } catch (IOException e) { Console.WriteLine("IO Error: " + e.Message); } return this.STATUS; } /// <summary> /// 用于获取鼠标点击位置坐标。 /// </summary> /// <param name="msg"></param> /// <param name="mode"></param> /// <returns></returns> public virtual int MOUSE(string msg, string mode) { this.sendCmd("MOUSE " + mode, msg); try { int.TryParse(Console.ReadLine(),out STATUS); this.READANS = Console.ReadLine(); this.MOUSEANS = Console.ReadLine(); } catch (IOException e) { Console.WriteLine("IO Error: " + e.Message); } return this.STATUS; } /// <summary> /// 指令的主要目的是当我们有些程序需要用超级用户才能执行的时候,我们用SU_ON打开超级用户,然后执行程序。 /// </summary> /// <returns></returns> public virtual int SU_ON() { this.sendCmd("SU_ON", ""); return 0; } /// <summary> /// 为退出由SU_ON打开的超级用户模式 /// </summary> /// <returns></returns> public virtual int SU_OFF() { this.sendCmd("SU_OFF", ""); return 0; } /// <summary> /// VON主要用于取得VOF的结果,然后执行其它的一些指令 /// </summary> /// <returns></returns> public virtual int VON() { this.sendCmd("VON", ""); return 0; } /// <summary> /// 该指令主要用于设置执行有可能出现错误的动作,并利用status得到结果,并经常结合VON使用 /// </summary> /// <returns></returns> public virtual int VOF() { this.sendCmd("VOF", ""); return 0; } }
有了这个类我们的开发就可以开始了,打开vs,新建一个控制台程序
添加一个Form
在program类里面的main函数里面添加如下的代码
Application.Run(new Form1());
在form里面添加一个按钮来测试代码
双击开始按钮写点击事件的代码
private void button1_Click(object sender, EventArgs e) { string dbname = "genesis"; string jobname = textBox1.Text; Console.WriteLine("Instantiated the Genesis Object..."); string msg = "Welcome to the Java test Script...apparently its working..."; Console.WriteLine(msg); gen.PAUSE(msg); gen.COM("create_entity,job=,is_fw=no,type=job,name=" + jobname + ",db=" + dbname + ",fw_type=form"); gen.COM("clipb_open_job,job=" + jobname + ",update_clipboard=view_job"); gen.COM("open_job,job=" + jobname); gen.COM("open_entity,job=" + jobname + ",type=matrix,name=matrix,iconic=no"); gen.COM("matrix_add_step,job=" + jobname + ",matrix=matrix,step=test,col=1"); gen.COM("matrix_add_layer,job=" + jobname + ",matrix=matrix,layer=lay1,row=1,context=board,type=signal,polarity=positive"); gen.COM("matrix_add_layer,job=" + jobname + ",matrix=matrix,layer=lay2,row=2,context=board,type=signal,polarity=positive"); string msg2 = "Now we'll open the newly created step..."; Console.WriteLine(msg2); gen.PAUSE(msg2); gen.COM("open_entity,job=" + jobname + ",type=step,name=test,iconic=no"); string group = gen.COMANS; gen.PAUSE("Group number is " + group); gen.COM("units,type=inch"); gen.COM("display_layer,name=lay1,display=yes,number=1"); gen.COM("work_layer,name=lay1"); gen.COM("display_layer,name=lay2,display=yes,number=2"); gen.COM("profile_rect,x1=0,y1=0,x2=5,y2=5"); gen.COM("zoom_home"); gen.COM("add_line,attributes=no,xs=0.6239601378,ys=0.5049917323,xe=4.6505824803,ye=4.5865225394,symbol=r40,polarity=positive"); gen.COM("work_layer,name=lay2"); gen.COM("add_line,attributes=no,xs=0.5049917323,ys=4.4675541339,xe=4.4584027559,ye=0.4409318898,symbol=r40,polarity=positive"); gen.MOUSE("Click a point", "p"); Console.WriteLine("Mouseans : " + gen.MOUSEANS); Console.WriteLine("Checking return of Genesis object..."); Console.WriteLine("genStatus : " + Convert.ToString(gen.STATUS)); Console.WriteLine("genComans : " + gen.COMANS); string msg3 = "Now we'll clean up..."; Console.WriteLine(msg3); gen.PAUSE(msg3); gen.COM("check_inout,mode=in,type=job,job=" + jobname); gen.COM("close_job,job=" + jobname); gen.COM("close_form,job=" + jobname); gen.COM("close_flow,job=" + jobname); gen.COM("delete_entity,job=,type=job,name=" + jobname); Console.WriteLine("genStatus : " + Convert.ToString(gen.STATUS)); Console.WriteLine("genComans : " + gen.COMANS); string msg4 = "Thats it..."; Console.WriteLine(msg4); gen.PAUSE(msg4); Application.Exit(); }
genesis和程序之间的通讯都是通过Console类来实现的
现在程序写好了,但在测试程序之前我们需要把src_start.csh文件修改一下让它支持直接实行EXE文件
#!/bin/csh # # Mike J. Hopkins # Genesis 2000 scr_start.csh # revision 1.4.1 # # This version of the scr_start.csh script includes # support for the Python programming language, # as well as Java and binary execuables... # # if($?GENESIS_DIR)then set _genesis_root=$GENESIS_DIR else set _genesis_root=/genesis endif if($?GENESIS_EDIR)then set _genesis_edir=$GENESIS_EDIR else set _genesis_edir=e$GENESIS_VER endif if($_genesis_edir =~ /* || $_genesis_edir =~ ?:*)then set path=($_genesis_edir/all $path) else set path=($_genesis_root/$_genesis_edir/all $path) endif set STATUS=0 set PROG=$1 if(! -e $PROG)then set PROG_STATUS=1 goto end endif # define aliases set DIR_PREFIX='@%#%@' alias VON 'echo "${DIR_PREFIX}VON";' alias VOF 'echo "${DIR_PREFIX}VOF";' alias SU_ON 'echo "${DIR_PREFIX}SU_ON";' alias SU_OFF 'echo "${DIR_PREFIX}SU_OFF";' alias PAUSE 'echo "${DIR_PREFIX}PAUSE !:*"; \ set STATUS=$<; set READANS=$<; set PAUSANS=$<; \ if ($PAUSANS != "OK") exit' alias MOUSE 'echo "${DIR_PREFIX}MOUSE !:*"; \ set STATUS=$<; set READANS=$<; set MOUSEANS="$<"' alias COM 'echo "${DIR_PREFIX}COM !:*"; \ set STATUS=$<; set READANS="$<"; set COMANS=($READANS)' alias AUX 'echo "${DIR_PREFIX}AUX !:*"; \ set STATUS=$<; set READANS="$<"; set COMANS=($READANS)' set argv = ($2) #executing hook script if(-e $_genesis_root/sys/hooks/script_start.csh)then source $_genesis_root/sys/hooks/script_start.csh endif # check first line of program set _HEAD=`head -1 $PROG` set _EXT=`echo $PROG:e` if("$_HEAD" =~ *perl*)then echo "Executing Perl Program $PROG $argv" perl $PROG $argv set PROG_STATUS=$status else if("$_HEAD" =~ *python*)then echo "Executing Python Program $PROG $argv" python $PROG $argv set PROG_STATUS=$status else if("$_HEAD" =~ *wish*)then setenv TCSHONLYSTARTEXES 1 echo "Executing TCL Program $PROG $argv" $_genesis_root/sys/hooks/wish_start.tcl $PROG $argv set PROG_STATUS=$status else if ("$_EXT" =~ [Cc][Ll][Aa][Ss][Ss]) then set JPATH = `echo $PROG:h` set JPROG = `echo $PROG:t` set JCLASS = `echo $JPROG:r` setenv CLASSPATH $JPATH echo "Set CLASSPATH to: $CLASSPATH" echo "Executing JavaClass $JCLASS $argv" echo "..." java $JCLASS $argv set PROG_STATUS=$status else if ("$_EXT" =~ [Ee][Xx][Ee]) then echo "Executing Compiled Program $PROG $argv" $PROG $argv set PROG_STATUS=$status else echo "Executing C Shell Program $PROG" source $PROG set PROG_STATUS=$status endif end: exit($PROG_STATUS)
改好保存下面可以打开genesis运行脚本了
在文本框里面输入想要新建的工作名称点击开始按钮运行