JavaScript一種直譯式腳本語(yǔ)言,是一種動(dòng)態(tài)類型、弱類型、基于原型的語(yǔ)言,內(nèi)置支持類型。它的解釋器被稱為JavaScript引擎,為瀏覽器的一部分,廣泛用于客戶端的腳本語(yǔ)言,最早是在HTML(標(biāo)準(zhǔn)通用標(biāo)記語(yǔ)言下的一個(gè)應(yīng)用)網(wǎng)頁(yè)上使用,用來(lái)給HTML網(wǎng)頁(yè)增加動(dòng)態(tài)功能。
本文介紹有關(guān)JavaScript獲取電子秤串口數(shù)據(jù)的編程代碼。
有關(guān)JavaScript獲取電子秤串口數(shù)據(jù)的完整代碼
//創(chuàng)建MSComm對(duì)象
functionuf_GetSerPortData()
{
try
{
MSComm1=newActiveXObject(“MSCOMMLib.MSComm.1”);
if((typeof(MSComm1)==“undefined”)||(MSComm1==null))
{
alert(“創(chuàng)建MSComm1對(duì)象失??!”);
}
else
{
//綁定事件
fn();
}
}
catch(err)
{
alert(err.description);
}
}
varfn=function(){
functionMSComm1::OnComm(){
MSComm1_OnComm();
}
}
//事件響應(yīng)
functionMSComm1_OnComm()
{
switch(MSComm1.CommEvent)
{
case1:{window.alert(“SendOK!”);break;}//發(fā)送事件
case2:{Receive();break;}//接收事件
default:alert(“EventRaised!”+MSComm1.CommEvent);;
}
}
functionOperatePort()
{
if(MSComm1.PortOpen==true)
{
try{MSComm1.PortOpen=false;
SKButton1.value=“打開串口”;
}catch(ex)
{alert(ex.message);}
}
else{
try{MSComm1.PortOpen=true;
MSComm1.InBufferCount=0;
SKButton1.value=“關(guān)閉串口”;
}catch(ex)
{alert(ex.message);}
}
}
評(píng)論