zhengxb 发表于 2018-11-28 14:17:28

_MATRIX原型继承方法使用说明

本帖最后由 zhengxb 于 2018-12-21 08:13 编辑

1.28.2更新
1._MOVE方法增加this.type属性,默认为0应用为现有的程序,设置为1时应用于现有版本的安卓程序,只是显示隐藏按钮的方法有影响
2._MOVE方法增加this.getPos方法或取松手时的坐标值 var as = btnSourceMove.getPos(); sendLog("Pos",as+":"+as);as为数组;



/********************************************************************************************************************


1.设置矩阵按钮输入输出切换
2.设置移动按钮拖拉信号切换
3.按钮与拖拉切换状态同步




*********************************************************************************************************************
**********************************************以下为矩阵方法参数说明*************************************************
*********************************************************************************************************************
*********************************************************************************************************************
//四种方法定义矩阵设备,MOD为根据模版生成的COM或NET口
var dev_Matrix = new _MATRIX('MOD',9600,N,8,1);
var dev_Matrix = new _MATRIX('MOD',9600,N,8,1,fnMoveStatus,fnGetData);
var dev_Matrix = new _MATRIX('MOD');
var dev_Matrix = new _MATRIX('MOD',fnMoveStatus,fnGetData);
//fnGetData为数据返方法
//矩阵初使化,设置输入的Name,路数,输出Name,路数)   
dev_Matrix.setInit('AV_IN_',16,'AV_OUT_',16);
输入按钮Name以AV_IN_为命名为AV_IN_1-AV_IN_16,输入按钮Name以AV_OUT_命名为AV_OUT_1至AV_OUT_16
function setMoveStatus(vInput,vOutput)
{
    btnSourceMove.setStatus(vInput,vOutput); //拖动界面状态设置
}
//数据回调函数
function matrixReceive(vData)
{
      sendLog("matrixReceive:",vData);

}
matrixReceive为前面定义的返回数据回调方法,vData为返回的数据,根据数据执行所需要的控制。


设置信号切换(输入,输出)
dev_Matrix.setSwitch(1,1)
延时设置信号切换(秒,输入,输出)
dev_Matrix.delaySwitch(1,2,3)
设置信号输入(输入)
dev_Matrix.setIn(1)
设置信号输出(输出)并切换矩阵
dev_Matrix.setOut(1)
设置矩阵控制命令格式,默认从数据库读取,也可以在程序中设置
dev_Matrix.command = "_IN_B_OUT_.";
程序会自动将_IN_替换为输入,将_OUT_替换为输出,如下格式2进3出为2B3.


端口发码:
dev_Matrix.setBaud(9600,N,8,1);
//发送代码(代码)
dev_Matrix.sendCodeString('code string')
//延时发送代码(秒,代码)
dev_Matrix.delayCodeString(1,'code string')
//发送代码(数据代码名称)
dev_Matrix.sendCodeName('code name')
//延时发送代码(秒,数据代码名称)
dev_Matrix.delayCodeName(1,'code name')
端口发码的主要目的是使用dev_Volume代替原有的sendCodeString(COM1,xxxxx)增加程序的可读性。



原型修改:
如果对于_MATRIX原型方法,需要修改或者需要增加,可使用如下方法:
修改方法:
delete dev_Matrix.setSwitch;
_MATRIX.prototype.setSwitch = function(sourcein,sourceout)
{
      this.input = sourcein;
      this.output = sourceout;
      this.mstatus=this.input;
      sendCodeString(this.port,this.input+"sss"+this.output);
      //sendCodeString(this.port,this.getMatrixString(this.input,this.output));
      this.setStatus();
      this.fnMoveStatus(sourcein,sourceout);
      
}
在查看原型方法时存在,信号切换是调用数据库设置好的命令,可以删除原来的方法并重新构造,修改里面的相关参数,如上所示。
注:删除原型方法会使用所有调用原型的方法都改变,如果一个项目存在两台矩阵,都同时调用_MATRIX两个方法都会跟着改变。
如果一台需要改变,另一台不需要,则可使用直接增加方法2的方式,如下所示:

增加方法:
_MATRIX.prototype.setSwitch2 = function(sourcein,sourceout)
{
      this.input = sourcein;
      this.output = sourceout;
      this.mstatus=this.input;
      sendCodeString(this.port,this.input+"sss"+this.output);
      //sendCodeString(this.port,this.getMatrixString(this.input,this.output));
      this.setStatus();
      this.fnMoveStatus(sourcein,sourceout);
      
}




*********************************************************************************************************************
******************************************以下为移动按钮方法参数说明*************************************************
*********************************************************************************************************************


//移动按钮定义及初始化,设置对应按钮Name及路数
var btnSourceMove = new _MOVE();
//移动按钮初始化(信号源按钮Name,信号源显示文字Name,信号源路数,显示屏范围Name,显示屏显示图标Name,显示屏显示文字Name,显示屏数量)
btnSourceMove.setInit('btnSource','txtSource',10,'lcdScope','lcdImage','lcdText','lcdTip',6);
//隐藏信号源1按钮(按钮Name1);
btnSourceMove.setSourceHide(1);
//显示信号源1按钮(按钮Name1);
btnSourceMove.setSourceShow(1);
//隐藏LCD1按钮(按钮Name1);
btnSourceMove.setLcdHide(1);
//显示LCD1按钮(按钮Name1);
btnSourceMove.setLcdShow(1);
//信号源恢复原位;
btnSourceMove.setPosinit();


//拖放命令,用于按钮的Button_Release,
function setSourceMove(vInput)
{
    var vOutput = btnSourceMove.getLcd(vInput); //vInput为输入源,获取输出窗口对应输出路数
    dev_Matrix.setSwitch(vInput,vOutput);   //执行矩阵信号的输入对应输出切换
}
*******************************************************************************************************************/

附 _MATRIX与_MOVE原型方法,已封装在system.dat文件中,可直接调用。




function _MATRIX(vPort,vB,vN,vD,vS,fnMoveStatus,fnGetData)
{
      this.modPrj = _SUBPROJECT_;
      this.callButton = function(btnName)
      {
                CallObject(this.modPrj,btnName);
      }
      this.fnMoveStatus;
      
      if(arguments.length>=2 && arguments.length<6)
      {
                this.fnMoveStatus= vB;
      }
      else if(arguments.length>=6)
      {
                this.fnMoveStatus= fnMoveStatus;
      }
      
      this.moveable = true;
      this.input= 0;
      this.output = 0;
      this.properties = {};
      this.inputmax = 16;
      this.outputmax = 16;
      this.btninputname = "AV_IN_";
      this.btnoutputname = "AV_IN_";         
      this.imageinputon = new Array()
      this.imageinputoff = new Array()
      this.imageoutputon = new Array()
      this.imageoutputoff = new Array()
      this.imageon= "ImageOnStates.png";
      this.imageoff = "ImageOffStates.png";
      
      for (var i=1;i<=this.inputmax;i++)
      {
                if(FindGUIObject(this.btninputname+i)!=null)
                {
                        this.imageinputon=getImageOn(this.btninputname+i)
                        this.imageinputoff=getImage(this.btninputname+i);
                }
                else
                {
                        this.imageinputon = this.imageon;
                        this.imageinputoff = this.imageoff;
                }
      }
      for (var i=1;i<=this.outputmax;i++)
      {
                if(FindGUIObject(this.btnoutputname+i)!=null)
                {
                        this.imageoutputon=getImageOn(this.btnoutputname+i)
                        this.imageoutputoff=getImage(this.btnoutputname+i)
                }
                else
                {
                        this.imageoutputon = this.imageon;
                        this.imageoutputoff = this.imageoff;
                }
      }
      this.setInit = function(vinid,vinmax,voutid,voutmax)
      {
                this.btninputname = vinid;
                this.btnoutputname = voutid;
            this.inputmax = vinmax;
            this.outputmax = voutmax;
                for (var i=1;i<=this.inputmax;i++)
                {
                        if(FindGUIObject(this.btninputname+i)!=null)
                        {
                              this.imageinputon=getImageOn(this.btninputname+i)
                              this.imageinputoff=getImage(this.btninputname+i);
                        }
                        else
                        {
                              this.imageinputon = this.imageon;
                              this.imageinputoff = this.imageoff;
                        }
                }
                for (var i=1;i<=this.outputmax;i++)
                {
                        if(FindGUIObject(this.btnoutputname+i)!=null)
                        {
                              this.imageoutputon=getImageOn(this.btnoutputname+i)
                              this.imageoutputoff=getImage(this.btnoutputname+i)
                        }
                        else
                        {
                              this.imageoutputon = this.imageon;
                              this.imageoutputoff = this.imageoff;
                        }
                }
      }
      this.mstatus = {};
      this.command = GetControlCode("MATRIXCOMMAND");
      this.commandin10 = GetControlCode("MATRIXCOMMANDIN>9");
      this.commandout10 = GetControlCode("MATRIXCOMMANDOUT>9");
      this.commandall10 = GetControlCode("MATRIXCOMMANDALL>9");
      if(this.commandin10.length<9)
      {
                this.commandin10 = this.command
      }
      if(this.commandout10.length<9)
      {
                this.commandout10 = this.command
      }
      if(this.commandall10.length<9)
      {
                this.commandall10 = this.command
      }
      this.port = vPort
      if(vPort.indexOf('MOD')!=-1)
      {
                this.port = GetCurrentIOName();
      }
      if(this.port.indexOf('COM')!=-1)
      {
                if(arguments.length>=5)
                {
                        setComBaud(this.port,vB,vN,vD,vS);
                }
      }
      this.setBaud = function(vsB,vsN,vsD,vsS)
      {
                setComBaud(this.port,vsB,vsN,vsD,vsS)
      }
      this.sendCodeString = function(vString)
      {
                sendCodeString(this.port,vString);
      }
      this.delayCodeString = function(vSec,vString)
      {
                delayCodeString(vSec,this.port,vString);
      }
      this.sendCodeName = function(vString)
      {
                sendCodeName(this.port,vString);
      }
      this.delayCodeName = function(vSec,vString)
      {
                delayCodeName(vSec,this.port,vString);
      }
      this.setIn = function(sourcein)
      {
                this.input = sourcein;
                this.setStatus();
      }
      this.setOut = function(sourceout)
      {
                this.output = sourceout;
                this.setSwitch(this.input,this.output)
      }
      this.setSwitch = function(sourcein,sourceout)
      {
                this.input = sourcein;
                this.output = sourceout;
                this.mstatus=this.input;
                sendCodeString(this.port,this.getMatrixString(this.input,this.output));
                this.setStatus();
                this.fnMoveStatus(sourcein,sourceout);
               
      }
      this.delaySwitch = function(vsec,sourcein,sourceout)
      {
                this.input = sourcein;
                this.output = sourceout;
                this.mstatus=this.input;
                delayCodeString(vsec,this.port,this.getMatrixString(this.input,this.output));
                this.setStatus();
                this.fnMoveStatus(sourcein,sourceout);
               
      }
      this.getMatrixString= function(vsetinput,vsetoutput)
      {
                var vStr = "";
                if(vsetinput<10)
                {
                        if(vsetoutput<10)
                        {
                              vStr = this.command;
                        }
                        else
                        {
                              vStr = this.commandout10;
                        }
                        
                }
                else
                {
                        if(vsetoutput<10)
                        {
                              vStr = this.commandin10;
                        }
                        else
                        {
                              vStr = this.commandall10;
                        }
                }
               
                vStr=vStr.replace(/_IN_/, vsetinput);
                vStr=vStr.replace(/_OUT_/, vsetoutput);
                return vStr
               
      }
      this.setStatus = function()
      {
                for (var i=1;i<=this.inputmax;i++)
                {
                        if(FindGUIObject(this.btninputname+i)!=null)
                        {
                              this.properties={"ImagePic" : "images\\"+this.imageinputoff};
                        }
                }
                if(FindGUIObject(this.btninputname+this.input)!=null)
                {
                        this.properties = {"ImagePic" : "images\\"+this.imageinputon};
                }
                for (var i=1;i<=this.outputmax;i++)
                {
                        if(FindGUIObject(this.btnoutputname+i)!=null)
                        {
                              this.properties = {"ImagePic" : "images\\"+this.imageoutputoff};
                        }
               
                }
                for (var i=1;i<=this.outputmax;i++)
                {
                        
                        if(this.mstatus==this.input)
                        {
                              if(FindGUIObject(this.btnoutputname+i)!=null)
                              {
                                        this.properties = {"ImagePic" : "images\\"+this.imageoutputon};
                              
                              }
                        }
                }
                BatchChangeProperty(this.properties);
      }
      this.getRev = function(vData)
      {
                vN(vData);
      }
      this.getRev7 = function(vData)
      {
                fnGetData(vData);
      }
      if(arguments.length==3)
      {
                setStringReceive(this.port,this.getRev);
               
      }
      if(arguments.length==7)
      {
                setStringReceive(this.port,this.getRev7);
               
      }
      
      
}



function _MOVE()
{
      this.lcdin = new Array();
      this.source = new Array();
      this.lcd = new Array();
      this.sourcemax = 10;
      this.lcdmax = 6;
      this.sourcebuttonname = 'btnSource';
      this.sourcetextname = 'txtSource';
      this.lcdsocpename = 'lcdScope';
      this.lcdimagename = 'lcdImage';
      this.lcdtextname = 'lcdText';
      this.lcdtipname = 'lcdTip';
      this.type = 0;
      
      for (var i=1;i<= this.sourcemax ;i++)
      {
                this.source=new Object();
                this.source.btnname = this.sourcebuttonname+i;
                this.source.txtname = this.sourcetextname+i;               
                this.source.Visable = true
                this.source.X = getPosX(this.sourcebuttonname+i);
                this.source.Y = getPosY(this.sourcebuttonname+i);
                this.source.txtX = getPosX(this.sourcetextname+i);
                this.source.txtY = getPosY(this.sourcetextname+i);
                this.source.Text = getText(this.sourcetextname+i);
                this.source.Image = getImage(this.sourcebuttonname+i);
      }
      for (var i=1;i<= this.lcdmax ;i++)
      {
                this.lcd=new Object();
                this.lcd.scopename = this.lcdsocpename+i;
                this.lcd.imagename = this.lcdimagename+i;
                this.lcd.txtname = this.lcdtextname+i;
                this.lcd.tipname = this.lcdtipname+i;
                this.lcd.Visable = true
                this.lcd.X = getPosX(this.lcdsocpename+i);
                this.lcd.Y = getPosY(this.lcdsocpename+i);
                this.lcd.imageX = getPosX(this.lcdimagename+i);
                this.lcd.imageY = getPosY(this.lcdimagename+i);
                this.lcd.txtX = getPosX(this.lcdtextname+i);
                this.lcd.txtY = getPosY(this.lcdtextname+i);
                this.lcd.tipX = getPosX(this.lcdtipname+i);
                this.lcd.tipY = getPosY(this.lcdtipname+i);
                this.lcd.H = getHeight(this.lcdsocpename+i);
                this.lcd.W = getWidth(this.lcdsocpename+i);
      }
      this.setSourceHide = function(vIndex)
      {
                if(this.type==1){
                        setAllPos(this.source.btnname,-1024,this.source.Y);
                        setAllPos(this.source.txtname,-1024,this.source.txtY);
                }else{
                        setPos(this.source.btnname,-1024,this.source.Y);
                        setPos(this.source.txtname,-1024,this.source.txtY);
                }
               
                this.source.Visable = false;
      }
      this.setSourceShow = function(vIndex)
      {
                if(this.type==1){
                        setAllPos(this.source.btnname,this.source.X,this.source.Y);
                        setAllPos(this.source.txtname,this.source.txtX,this.source.txtY);
                }else{
                        setPos(this.source.btnname,this.source.X,this.source.Y);
                        setPos(this.source.txtname,this.source.txtX,this.source.txtY);
                }
               
                this.source.Visable = true;
      }
      this.setLcdHide = function(vIndex)
      {
                if(this.type==1){
                        setAllPos(this.lcd.scopename,-1024,this.lcd.Y);
                        setAllPos(this.lcd.imagename,-1024,this.lcd.imageY);
                        setAllPos(this.lcd.txtname,-1024,this.lcd.txtY);
                        setAllPos(this.lcd.tipname,-1024,this.lcd.tipY);
                }else{
                        setPos(this.lcd.scopename,-1024,this.lcd.Y);
                        setPos(this.lcd.imagename,-1024,this.lcd.imageY);
                        setPos(this.lcd.txtname,-1024,this.lcd.txtY);
                        setPos(this.lcd.tipname,-1024,this.lcd.tipY);
                }
               
                this.lcd.Visable = false;
      }
      this.setLcdShow = function(vIndex)
      {
                if(this.type==1){
                        setAllPos(this.lcd.scopename,this.lcd.X,this.lcd.Y);
                        setAllPos(this.lcd.imagename,this.lcd.imageX,this.lcd.imageY);
                        setAllPos(this.lcd.txtname,this.lcd.txtX,this.lcd.txtY);
                        setAllPos(this.lcd.tipname,this.lcd.tipX,this.lcd.tipY);
                }else{
                        setPos(this.lcd.scopename,this.lcd.X,this.lcd.Y);
                        setPos(this.lcd.imagename,this.lcd.imageX,this.lcd.imageY);
                        setPos(this.lcd.txtname,this.lcd.txtX,this.lcd.txtY);
                        setPos(this.lcd.tipname,this.lcd.tipX,this.lcd.tipY);
                }
               
                this.lcd.Visable = true;
      }
      this.setInit = function(vsbtnname,vstxtname,bsmax,vlcdname,vlcdimagename,vlcdtxtname,vlcdtipname,vlcdmax)
      {
            this.sourcemax = bsmax;
            this.lcdmax = vlcdmax;
            this.sourcebuttonname = vsbtnname;
            this.sourcetextname = vstxtname;
            this.lcdsocpename = vlcdname;
            this.lcdimagename = vlcdimagename;
            this.lcdtextname = vlcdtxtname;      
                this.lcdtipname = vlcdtipname;
                for (var i=1;i<= this.sourcemax ;i++)
                {
                        this.source=new Object();
                        this.source.btnname = this.sourcebuttonname+i;
                        this.source.txtname = this.sourcetextname+i;
                        this.source.Visable = true
                        this.source.X = getPosX(this.sourcebuttonname+i);
                        this.source.Y = getPosY(this.sourcebuttonname+i);
                        this.source.txtX = getPosX(this.sourcetextname+i);
                        this.source.txtY = getPosY(this.sourcetextname+i);
                        this.source.Text = getText(this.sourcetextname+i);
                        this.source.Image = getImage(this.sourcebuttonname+i);
                }
                for (var i=1;i<= this.lcdmax ;i++)
                {
                        this.lcd=new Object();
                        this.lcd.scopename = this.lcdsocpename+i;
                        this.lcd.imagename = this.lcdimagename+i;
                        this.lcd.txtname = this.lcdtextname+i;
                        this.lcd.tipname = this.lcdtipname+i;
                        this.lcd.Visable = true
                        this.lcd.X = getPosX(this.lcdsocpename+i);
                        this.lcd.Y = getPosY(this.lcdsocpename+i);
                        this.lcd.imageX = getPosX(this.lcdimagename+i);
                        this.lcd.imageY = getPosY(this.lcdimagename+i);
                        this.lcd.txtX = getPosX(this.lcdtextname+i);
                        this.lcd.txtY = getPosY(this.lcdtextname+i);
                        this.lcd.tipX = getPosX(this.lcdtipname+i);
                        this.lcd.tipY = getPosY(this.lcdtipname+i);
                        this.lcd.H = getHeight(this.lcdsocpename+i);
                        this.lcd.W = getWidth(this.lcdsocpename+i);
                }
      }
      this.setPosinit = function()
      {
               for (var i=1;i<=this.sourcemax;i++)
                {
                        if(this.source.Visable == true)
                        {
                              setButtonPox(this.sourcebuttonname+i,this.source.X,this.source.Y);
                        }
                        
                }
                for (var i=1;i<=this.lcdmax;i++)
                {
                        if(this.lcd.Visable == true)
                        {
                              
                              setButtonPox(this.lcdimagename+i,this.lcd.imageX,this.lcd.imageY);
                        }
                        
                }               
      }
      this.getLcd = function(vInput)
      {
                var as = ;
                as = eval(GetPropertyJSON(FindGUIObject(self), 'Pos'));
               
                for(var i=1;i<= this.lcdmax ;i++)
                {
                        if(parseInt(as)>this.lcd.X && parseInt(as)<this.lcd.X+this.lcd.W && parseInt(as)>this.lcd.Y && parseInt(as)<this.lcd.Y+this.lcd.H)
                        {
                                        setButtonText(this.lcdtextname+i,this.source.Text);
                                        setButtonImage(this.lcdimagename+i,this.source.Image);
                                        this.lcdin = vInput;
                                        this.setPosinit();   
                                        return i      
                        }
                }
                this.setPosinit();
                return 0
      }
      this.getPos = function()
      {
                var as = ;
                as = eval(GetPropertyJSON(FindGUIObject(self), 'Pos'));
                this.setPosinit();
                return as
      }
      
      this.setStatus = function(vInput,vOutput)
      {
                setButtonText(this.lcdtextname+vOutput,this.source.Text);
                setButtonImage(this.lcdimagename+vOutput,this.source.Image);
                this.lcdin = vInput;
      }
      
}
页: [1]
查看完整版本: _MATRIX原型继承方法使用说明