 var printparamsJsonArray  = [];
	function	OpenPort(printname){
	printparamsJsonArray.push({"OpenPort" : printname});
	PTK_ClearBuffer();
	}

	function	ClosePort(){
	printparamsJsonArray.push({"ClosePort" : ""});
	} // 关闭使用 OpenPort函数打开的通讯端口

	function OpenUSBPort(xxxx){
	printparamsJsonArray.push({"OpenUSBPort" :xxxx });
	}

	function CloseUSBPort(){
	printparamsJsonArray.push({"CloseUSBPort" : ""});
	}

	function PTK_GetErrState(){
	printparamsJsonArray.push({"PTK_GetErrState" : ""});
	}

	function PTK_GetInfo(){
	printparamsJsonArray.push({"PTK_GetInfo" : ""});
	}
	
	function SetPCComPort(BaudRate,HandShake){
	printparamsJsonArray.push({"SetPCComPort" : BaudRate+","+HandShake});
	}

	function PTK_ClearBuffer(){
	printparamsJsonArray.push({"PTK_ClearBuffer" : ""});
	} // 清除打印机缓冲内存的容

	function PTK_SetDarkness(id){
	printparamsJsonArray.push({"PTK_SetDarkness" : id});
	} // 设置打印头发热温度
  
  
	function PTK_SetPrintSpeed(px){
	printparamsJsonArray.push({"PTK_SetPrintSpeed" : px});
	} // 设置打印速度

	function PTK_SetLabelHeight(lheight,gapH,gapOffset,bFlag){
	printparamsJsonArray.push({"PTK_SetLabelHeight" :lheight+","+gapH+","+gapOffset+","+bFlag });
	}// 设置标签的高度和定位间隙 \黑线 \穿孔的高度。

	function PTK_SetLabelWidth(lwidth){
	printparamsJsonArray.push({"PTK_SetLabelWidth" :lwidth});
	} // 设置标签的宽度。

	function PTK_SetDirection(direct){
	printparamsJsonArray.push({"PTK_SetDirection" :direct });
	}

	function PTK_SetCoordinateOrigin(px,py){
	printparamsJsonArray.push({"PTK_SetCoordinateOrigin" : px+","+py});
	}

	function PTK_PrintLabel(Number,cpnumber){
	printparamsJsonArray.push({"PTK_PrintLabel" : Number+","+cpnumber});
	} // 命令打印机执行工作

	function PTK_DrawText(px,py,pdirec,pFont,pHorizontal,pVertical,ptext,pstr){
	printparamsJsonArray.push({"PTK_DrawText" :px+","+py+","+pdirec+","+pFont+","+pHorizontal+","+pVertical+","+ptext+","+pstr });
	} // 打印一行文本字

	function PTK_DrawTextEx(px,py,pdirec,pFont,pHorizontal,pVertical,ptext,pstr,varible){
	printparamsJsonArray.push({"PTK_DrawTextEx" :px+","+py+","+pdirec+","+pFont+","+pHorizontal+","+pVertical+","+ptext+","+pstr+","+varible});
	} // 打印一行文本文字，内容可以是常量、序列号变或组合符串。

	function PTK_DrawTextTrueTypeW(x,y,FHeight,FWidth,FType,Fspin,FWeight,FItalic,FUnline,FStrikeOut,id_name,data){
	printparamsJsonArray.push({"PTK_DrawTextTrueTypeW" :x+","+y+","+FHeight+","+FWidth+","+FType+","+Fspin+","+FWeight+","+FItalic+","+FUnline+","+FStrikeOut+","+id_name+","+data });
	} // 打印一行TrueTypeFont文字，并且宽度和高可以微调

	function PTK_DrawBarcode(px,py,pdirec,pCode,pHorizontal,pVertical,pbright,ptext,pstr){
	printparamsJsonArray.push({"PTK_DrawBarcode" :px+","+py+","+pdirec+","+pCode+","+pHorizontal+","+pVertical+","+pbright+","+ptext+","+pstr });
	} // 打印一个条码。

	function PTK_DrawBarcodeEx(px,py,pdirec,pCode,NarrowWidth,pHorizontal,pVertical,pbright,ptext,pstr,Varible){
	printparamsJsonArray.push({"PTK_DrawBarcodeEx" : px+","+py+","+pdirec+","+pCode+","+NarrowWidth+","+pHorizontal+","+pVertical+","+pbright+","+ptext+","+pstr+","+Varible});
	} // 打印一个条码。

	function PTK_DrawBar2D_DATAMATRIX(x,y,w,h,o,m,pstr){
	printparamsJsonArray.push({"PTK_DrawBar2D_DATAMATRIX" : x+","+y+","+w+","+h+","+o+","+m+","+pstr});
	} // 打印DataMatrix二维条码

	function PTK_DrawBar2D_QR(x,y,w,v,o,r,m,g,s,pstr){
	printparamsJsonArray.push({"PTK_DrawBar2D_QR" : x+","+y+","+w+","+v+","+o+","+r+","+m+","+g+","+s+","+pstr});
	} // 打印一个 QR 条码

	function PTK_DrawBar2D_QREx(x,y,o,r,g,s,v,id_name,pstr){
	printparamsJsonArray.push({"PTK_DrawBar2D_QREx" : x+","+y+","+o+","+r+","+g+","+s+","+v+","+id_name+","+pstr});
	} // 打印一个 QR

	function PTK_DrawBar2D_MaxiCode(x,y,m,u,pstr){
	printparamsJsonArray.push({"PTK_DrawBar2D_MaxiCode" : x+","+y+","+m+","+u+","+pstr});
	}

	function PTK_DrawBar2D_Pdf417(x,y,w,v,s,c,px,py,r,l,t,o,pstr){
	printparamsJsonArray.push({"PTK_DrawBar2D_Pdf417" :x+","+y+","+w+","+v+","+s+","+c+","+px+","+py+","+r+","+l+","+t+","+o+","+pstr});
	} // 打印一个

	function PTK_DrawBar2D_HANXIN(x,y,w,v,o,r,m,g,s,pstr){
	printparamsJsonArray.push({"PTK_DrawBar2D_HANXIN" : x+","+y+","+w+","+v+","+o+","+r+","+m+","+g+","+s+","+pstr});
	} // 打印一个汉信码二维条码

	function PTK_PcxGraphicsList(){
	printparamsJsonArray.push({"PTK_PcxGraphicsList" : ""});
	}

	function PTK_PcxGraphicsDel(pid){
	printparamsJsonArray.push({"PTK_PcxGraphicsDel" : pid});
	} // 删除存储在 打印机 RAM或 FLASH存储器里的一个或所有图形

	function PTK_PcxGraphicsDownload(pcxname,pcxpath){
	printparamsJsonArray.push({"PTK_PcxGraphicsDownload" : pcxname+","+pcxpath});
	} // 存储一个 PCX格式的图形到打印机

	function PTK_DrawPcxGraphics(px,py,gname){
	printparamsJsonArray.push({"PTK_DrawPcxGraphics" : px+","+py+","+gname});
	} // 打印指定的图形

	function PTK_PrintPCX(px,py,filename){
	printparamsJsonArray.push({"PTK_PrintPCX" :px+","+py+","+filename });
	}// 函数是打印一个 函数是打印一个 PCXPCXPCX格式的图形。

	function PTK_BmpGraphicsDownload(pcxname,pcxpath,iDire){
	printparamsJsonArray.push({"PTK_BmpGraphicsDownload" :pcxname+","+pcxpath+","+iDire});
	}

	function PTK_BinGraphicsList(){
	printparamsJsonArray.push({"PTK_BinGraphicsList" : ""});
	}

	function PTK_BinGraphicsDel(pid){
	printparamsJsonArray.push({"PTK_BinGraphicsDel" : pid});
	}
	//byte[] Gdata
	function PTK_BinGraphicsDownload(name,pbyte,pH,Gdata){
	printparamsJsonArray.push({"PTK_BinGraphicsDownload" : name+","+pbyte+","+pH+","+Gdata});
	}

	function PTK_RecallBinGraphics(px,py,name){
	printparamsJsonArray.push({"PTK_RecallBinGraphics" : px+","+py+","+name});
	}
	//byte[] Gdata
	function PTK_DrawBinGraphics(px,py,pbyte,pH,Gdata){
	printparamsJsonArray.push({"PTK_DrawBinGraphics" : px+","+py+","+pbyte+","+pH+","+Gdata});
	}

	function PTK_DrawRectangle(px,py,thickness,pEx,pEy){
	printparamsJsonArray.push({"PTK_DrawRectangle" : px+","+py+","+thickness+","+pEx+","+pEy});
	} // 画矩形

	function PTK_DrawLineXor(px,py,pbyte,pH){
	printparamsJsonArray.push({"PTK_DrawLineXor" : px+","+py+","+pbyte+","+pH});
	}

	function PTK_DrawLineOr(px,py,pLength,pH){
	printparamsJsonArray.push({"PTK_DrawLineOr" : px+","+py+","+pLength+","+pH});
	} // 画直线 (两直线相交处作”或”处理 )。

	function PTK_DrawDiagonal(px,py,thickness,pEx,pEy){
	printparamsJsonArray.push({"PTK_DrawDiagonal" : px+","+py+","+thickness+","+pEx+","+pEy});
	}

	function PTK_DrawWhiteLine(px,py,plength,pH){
	printparamsJsonArray.push({"PTK_DrawWhiteLine" : px+","+py+","+plength+","+pH});
	}

	function PTK_SoftFontList(){
	printparamsJsonArray.push({"PTK_SoftFontList" : "" });
	}

	function PTK_SoftFontDel(pid){
	printparamsJsonArray.push({"PTK_SoftFontDel" : pid});
	}

	function PTK_FormList(){
	printparamsJsonArray.push({"PTK_FormList" : ""});
	}

	function PTK_FormDel(pid){
	printparamsJsonArray.push({"PTK_FormDel" : pid});
	} // 删除存储在打印机里的一个或所有表格

	function PTK_FormDownload(pid){
	printparamsJsonArray.push({"PTK_FormDownload" : pid});
	} // 存储一个表格到打印机； 此命令与 此命令与 PTK_FormEnd 函数配对使用。

	function PTK_FormEnd(){
	printparamsJsonArray.push({"PTK_FormEnd" : ""});
	} // 结束存储表格 (Form)，此函数与 PTK_FormDownload配对使用

	function PTK_ExecForm(pid){
	printparamsJsonArray.push({"PTK_ExecForm" : pid});
	} // 运行指定的表格

	function PTK_DefineCounter(id,maxNum,ptext,pstr,pMsg){
	printparamsJsonArray.push({"PTK_DefineCounter" : id+","+maxNum+","+ptext+","+pstr+","+pMsg});
	} // 定义一个序列号变量

	function PTK_DefineCounter(id,maxNum,ptext,pstr,pMsg){
	printparamsJsonArray.push({"PTK_DefineCounter" : id+","+maxNum+","+ptext+","+pstr+","+pMsg});
	}

	function PTK_DefineVariable(pid,pmax,porder,pmsg){
	printparamsJsonArray.push({"PTK_DefineVariable" : pid+","+pmax+","+porder+","+pmsg});
	}

	function PTK_Download(){
	printparamsJsonArray.push({"PTK_Download" : ""});
	} // 下载变量或系列号变量

	function PTK_DownloadInitVar(pstr){
	printparamsJsonArray.push({"PTK_DownloadInitVar" : pstr});
	} // 初始化变量或系列号变量

	function PTK_PrintLabelAuto(Number,cpnumber){
	printparamsJsonArray.push({"PTK_PrintLabelAuto" : Number+","+cpnumber});
	}

	function PTK_SendFile(FilePath){
	printparamsJsonArray.push({"PTK_SendFile" : FilePath});
	}

	function PTK_GetUSBID(USBDeviceSerial){
	printparamsJsonArray.push({"PTK_GetUSBID" : USBDeviceSerial});
	}

	function PTK_DisableBackFeed(){
	printparamsJsonArray.push({"PTK_DisableBackFeed" : ""});
	}

	function PTK_EnableBackFeed(distance){
	printparamsJsonArray.push({"PTK_EnableBackFeed" : distance});
	}

	function PTK_PrintConfiguration(){
	printparamsJsonArray.push({"PTK_PrintConfiguration" : ""});
	}

	function PTK_SetPrinterState(state){
	printparamsJsonArray.push({"PTK_SetPrinterState" : state});
	}

	function PTK_DisableErrorReport(){
	printparamsJsonArray.push({"PTK_DisableErrorReport" : ""});
	}

	function PTK_EnableErrorReport(){
	printparamsJsonArray.push({"PTK_EnableErrorReport" : ""});
	}

	function PTK_EnableFLASH(){
	printparamsJsonArray.push({"PTK_EnableFLASH" : ""});
	}

	function PTK_DisableFLASH(){
	printparamsJsonArray.push({"PTK_DisableFLASH" : ""});
	}

	function PTK_FeedMedia(){
	printparamsJsonArray.push({"PTK_FeedMedia" : ""});
	}

	function PTK_MediaDetect(){
	printparamsJsonArray.push({"PTK_MediaDetect" : ""});
	}

	function PTK_CutPage(page){
	printparamsJsonArray.push({"PTK_CutPage" : page});
	}

	function PTK_CutPageEx(page){
	printparamsJsonArray.push({"PTK_CutPageEx" : page});
	}

	function PTK_FeedBack(){
	printparamsJsonArray.push({"PTK_FeedBack" : ""});
	}

	function PTK_Reset(){
	printparamsJsonArray.push({"PTK_Reset" : ""});
	}

	function PTK_ErrorReport(wPort,rPort,BaudRate,HandShake,TimeOut){
	printparamsJsonArray.push({"PTK_ErrorReport" : wPort+","+rPort+","+BaudRate+","+HandShake+","+TimeOut});
	}

	function PTK_ErrorReportUSB(USBport){
	printparamsJsonArray.push({"PTK_ErrorReportUSB" : USBport});
	} // 发送错误查询指令到打印机并且指定USB端口接收和分析打印机当前错误代码。

	function PTK_RWRFIDLabel(nRWMode,nWForm,nStartBlock,nWDataNum,nWArea,pstr){
	printparamsJsonArray.push({"PTK_RWRFIDLabel" : nRWMode+","+nWForm+","+nStartBlock+","+nWDataNum+","+nWArea+","+pstr});
	} // 读写RFID标签。

	function PTK_SetRFIDLabelRetryCount(nRetryCount){
	printparamsJsonArray.push({"PTK_SetRFIDLabelRetryCount" : nRetryCount});
	}

	function PTK_SetRFLabelPWAndLockRFLabel(nOperationMode,OperationnArea,pstr){
	printparamsJsonArray.push({"PTK_SetRFLabelPWAndLockRFLabel" : nOperationMode+","+OperationnArea+","+pstr});
	}// 设置RFID标签密码和锁定RFID标签

	function PTK_SetRFID(nReservationParameters,nReadWriteLocation,ReadWriteArea,nMaxErrNum,nErrProcessingMethod){
	printparamsJsonArray.push({"PTK_SetRFID" : nReservationParameters+","+nReadWriteLocation+","+ReadWriteArea+","+nMaxErrNum+","+nErrProcessingMethod});
	}

	function PTK_SetFontGap(gap){
	printparamsJsonArray.push({"PTK_SetFontGap" : gap});
	}

	function PTK_SetBarCodeFontName(Name,FontW,FontH){
	printparamsJsonArray.push({"PTK_SetBarCodeFontName" : Name+","+FontW+","+FontH});
	}

	function PTK_RenameDownloadFont(StoreType,Fontname,DownloadFontName){
	printparamsJsonArray.push({"PTK_RenameDownloadFont" : StoreType+","+Fontname+","+DownloadFontName});
	}

	function PTK_SetCharSets(BitValue,CharSets,CountryCode){
	printparamsJsonArray.push({"PTK_SetCharSets" : BitValue+","+CharSets+","+CountryCode});
	}
	
var url = "http://127.0.0.1:888/postek/print";
  function PRINT(){
        	var data = {};
        	data.reqParam = "2";
        	data.lang = "zh";
          	data.printparams = JSON.stringify( printparamsJsonArray);
            
        	$.ajax({
        		type: "POST",
        		url: url,
        		data:data,
        		dataType:"json",
        		async:false,
                timeout:5000, // in milliseconds
                success:function(result){
            		//var retdata = JSON.parse (result);
            		if (result.retval == '0') {
            			alert("发送成功！");
                    } else {
                    	alert("发送失败，返回结果："+result.msg);
                    }
            	  },
            	 error:function(request, status, err) { 
        		 alert("请求失败，请重试");
       		   }
        	});
        	
        	printparamsJsonArray=[];
    }
    
    function getPrinterList(){
        var data = {};
    	data.printname = $("#printname").val();
    	data.reqParam = "0";
    	data.lang = "zh";
        
    	$.ajax({
    		type: "POST",
    		url: url,
    		data:data,
    		dataType:"json",
            timeout:5000, // in milliseconds
            success:function(result){
        		if(result == null || result.length == 0){
        			alert("获取打印机失败，请刷新页面重试");
                    
        		}else{
       				
        		/*	for(var i in result){
        				 $("#printname").append("<option value='"+result[i].printName+"'>"+result[i].printName+"</option>"); 
        			}*/
        			return result;
        		}
        	  },
        	 error:function() { 
	  			alert("获取打印机失败，请刷新页面重试");
    	  }
    	});
    }