



//判断浏览器
function myBrowser() {
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
    var isIE = userAgent.indexOf("compatible") > -1
        && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
    var isEdge = userAgent.indexOf("Edge") > -1; //判断是否IE的Edge浏览器
    var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器
    var isSafari = userAgent.indexOf("Safari") > -1
        && userAgent.indexOf("Chrome") == -1; //判断是否Safari浏览器
    var isChrome = userAgent.indexOf("Chrome") > -1
        && userAgent.indexOf("Safari") > -1; //判断Chrome浏览器
    return userAgent;
    if (isIE) {
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var fIEVersion = parseFloat(RegExp["$1"]);
        if (fIEVersion == 7) {
            return "IE7";
        } else if (fIEVersion == 8) {
            return "IE8";
        } else if (fIEVersion == 9) {
            return "IE9";
        } else if (fIEVersion == 10) {
            return "IE10";
        } else if (fIEVersion == 11) {
            return "IE11";
        } else {
            return "0";
        }//IE版本过低
        return "IE";
    }
    if (isOpera) {
        return "Opera";
    }
    if (isEdge) {
        return "Edge";
    }
    if (isFF) {
        return "FF";
    }
    if (isSafari) {
        return "Safari";
    }
    if (isChrome) {
        return "Chrome";
    }
}



//图表显示封装
function Interface(PortSum) {

    var userAgent = myBrowser().indexOf("WOW64");

    if(userAgent >= 0){
        if(PortSum != parseInt(JsObj.getSerialObj())) {
            JsObj.setSerialObj(PortSum); //初始串口对象
        }
        JsObj.setTimes(JSON.stringify({}));
    }

    //定时器初始化
    this.setTime = function (funs) {
        let temp = "{";
        for(let i=0; i<funs.length; i++){
            temp += "\"Time" + i + "_Name\":\"" + funs[i][0] + "\",";
            temp += "\"Time" + i + "_Delay\":\"" + funs[i][1] + "\",";
        }
        temp += "}";
        return JsObj.setTimes(temp);
    }

    this.setTimeDelay = function(fun, delay){
        return  JsObj.setTimeDelay(fun, delay);
    }
    this.setTimePause = function (fun, flag) {
        return JsObj.setTimePause(fun, flag);
    }

    //退出软件
    this.exit_windows = function(){
        return  JsObj.exit_windows();
    }
    //获得当前所有串口号
    this.getSerialFind = function(){
       return JsObj.getSerialFind();
    }
    //获得当前所有串口号
    this.getSerialInfo = function(){
       return  JsObj.getSerialInfo();
    }
    //获取当前已有对象数量
    this.getSerialObj = function(){
        return JsObj.getSerialObj();
    }
    //设置对象数量
    this.setSerialObj = function(sum){
        return  JsObj.setSerialObj(sum);
    }
    //判断串口是否已经打开
    this.getSerialIsOpen = function(index){
        return  JsObj.getSerialIsOpen(index);
    }
    //设置串口
    this.setSerialOpen = function(index, PortName, BaudRate, Parity, StopBits, DataBits){
        return JsObj.setSerialOpen(index, PortName, BaudRate, Parity, StopBits, DataBits);
    }
    //关闭串口
    this.setSerialClose = function(index){
        return JsObj.setSerialClose(index);
    }

    this.getFreeTime = function (index) {
        return  parseInt(JsObj.getFreeTime(index));
    }
    // 发送串口数据
    // delay1：发送数据前延时时间， delay2：发送数据后延时时间，overDelay：串口忙碌时等待空闲时间
    this.setSerialSend = function(index, cmd, funName, delay1, delay2, overDelay){
        // while (this.getFreeTime(index) < overDelay);
        return JsObj.setSerialSend(index, cmd + "\r\n", funName, delay1, delay2, overDelay, "string");
    }
    //发送串口数据并检查应答情况
    this.getSerialComm = function(port, cmd, funName, MinTime, MaxTime){
        // while (this.getFreeTime(index) < MaxTime);
        return JsObj.getSerialComm(port, cmd + "\r\n", funName, MinTime, MaxTime, "string");
    }
    this.setIni = function(section, key, val){
        return JsObj.setIni(section, key, val);
    }
    this.getIni = function(section, key, def_val){
        return JsObj.getIni(section, key, def_val);
    }
    //保存文件到本地
    this.saveFile = function(str, name){
        return JsObj.saveFile(str, name);
    }
    //读取文件到本地
    this.readFile = function(){
        return JsObj.readFile();
    }
    //消息提示
    this.messageBox = function(str){
        return  JsObj.messageBox(str);
    }
    this.sleep = function(time) {
        var startTime = new Date().getTime() + parseInt(time, 10);
        while(new Date().getTime() < startTime) {}
    };




}