JS脚本产生虚拟数据

//产生随机数函数
function randomNum(minNum,maxNum){ 
    switch(arguments.length){ 
        case 1: 
            return parseInt(Math.random()*minNum+1,10); 
        break; 
        case 2: 
            return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10); 
        break; 
            default: 
                return 0; 
            break; 
    } 
}

var sNodeIdArr1 =new Array();//电流
var sNodeIdArr2 =new Array();//电压
var sNodeIdArr3 =new Array();//焊接速度
var sNodeIdArr4 =new Array();//焊弧状态
var sNodeIdArr5 =new Array();//设备状态


for (var i=0;i<63;i++){ 
 sNodeIdArr1[i]="ns=128;s=EQ_00"+(i+1)+".Current.PV";//电流
 sNodeIdArr2[i]="ns=128;s=EQ_00"+(i+1)+".Voltage.PV";//电压
 sNodeIdArr3[i]="ns=128;s=EQ_00"+(i+1)+".WireSpeed.PV";//焊接速度
 sNodeIdArr4[i]="ns=128;s=EQ_00"+(i+1)+".WeldDetect.PV";//焊弧状态
 sNodeIdArr5[i]="ns=128;s=EQ_00"+(i+1)+".State.PV";//设备状态
     }
var retVal1 = GetMulItemValue(sNodeIdArr1,0);//电流
var retVal2 = GetMulItemValue(sNodeIdArr2,0);//电压
var retVal3 = GetMulItemValue(sNodeIdArr3,0);//焊接速度
var retVal4 = GetMulItemValue(sNodeIdArr4,0);//焊弧状态
var retVal5 = GetMulItemValue(sNodeIdArr5,0);//设备状态


WriteDataToFile ("D:\\sNodeIdArr1.txt",sNodeIdArr1+"\r\n");
WriteDataToFile ("D:\\retVal1.txt",retVal1+"\r\n");


 for (var j=0;j<63;j++){
  var k=j*1;
  var run_id=k*3+1;

  var run5=retVal5[run_id];//设备状态
  
  var Current;//电流
  var Voltage;//电压
  var WireSpeed;//焊接速度
  var WeldDetect;//焊弧状态
  
  if(run5==1){
      Current=randomNum(294,310);
	  Voltage=randomNum(25,29);
	  WireSpeed=randomNum(7,10);
	  WeldDetect=1;
   }
   else {
      Current=0;
	  Voltage=0;
	  WireSpeed=0;
	  WeldDetect=0;
      }
var Current_node="ns=128;s=EQ_00"+(j+1)+".Current.PV";
var Voltage_node="ns=128;s=EQ_00"+(j+1)+".Voltage.PV";
var WireSpeed_node="ns=128;s=EQ_00"+(j+1)+".WireSpeed.PV";
var WeldDetect_node="ns=128;s=EQ_00"+(j+1)+".WeldDetect.PV";

WriteDataToFile ("D:\\Current.txt",Current_node+":"+Current+"\r\n");

SetOneItemValue(Current_node,Current);
SetOneItemValue(Voltage_node,Voltage);
SetOneItemValue(WireSpeed_node,WireSpeed);
SetOneItemValue(WeldDetect_node,WeldDetect);
 }
WriteDataToFile ("D:\\Current.txt","循环完成"+"\r\n");

你可能感兴趣的:(JS,SCADA)