var PORT_LIST = [
|
// {"baudrate":9600,"databits":8,"no":1,"parity":0,"pollTime":1000,"stopbits":1,"timeout":1000,"vld":0},
|
// {"baudrate":9600,"databits":8,"no":2,"parity":1,"pollTime":1000,"stopbits":1,"timeout":1000,"vld":0},
|
// {"baudrate":9600,"databits":8,"no":3,"parity":0,"pollTime":1000,"stopbits":1,"timeout":1000,"vld":0},
|
// {"baudrate":9600,"databits":8,"no":4,"parity":0,"pollTime":1000,"stopbits":1,"timeout":1000,"vld":0},
|
// {"baudrate":9600,"databits":8,"no":5,"parity":0,"pollTime":1000,"stopbits":1,"timeout":1000,"vld":0},
|
// {"baudrate":9600,"databits":8,"no":6,"parity":0,"pollTime":1000,"stopbits":1,"timeout":1000,"vld":0},
|
// {"baudrate":9600,"databits":8,"no":7,"parity":0,"pollTime":1000,"stopbits":1,"timeout":1000,"vld":0},
|
// {"baudrate":9600,"databits":8,"no":8,"parity":0,"pollTime":1000,"stopbits":1,"timeout":1000,"vld":0},
|
];
|
(function () {
|
//默认查询
|
query();
|
// renderTable();
|
}).call(this);
|
|
|
//执行保存
|
function save() {
|
var dataList = new Array();
|
var obj = {};
|
var checked = true;
|
for (var i = 1; i <= PORT_LIST.length; i++) {
|
var cur = PORT_LIST[i-1];
|
obj.no = $("#no-" + cur.no).val();
|
obj.baudrate = $("#baudrate-" + cur.no).val();
|
obj.parity = $("#parity-" + cur.no).val();
|
obj.databits = $("#databits-" + cur.no).val();
|
obj.stopbits = $("#stopbits-" + cur.no).val();
|
obj.timeout = $("#timeout-" + cur.no).val();
|
obj.pollTime = $("#pollTime-" + cur.no).val();
|
checked = $("#vld-" + cur.no).prop("checked");
|
if (checked) {
|
obj.vld = 0;
|
} else {
|
obj.vld = 1;
|
}
|
dataList.push(obj);
|
obj = {};
|
}
|
|
// console.log(dataList);
|
|
$.post("./cgi-bin/sys-port/save", JSON.stringify(dataList), function (data, status) {
|
if ("success" == status && data.code == "success") {
|
window.parent.parent.notify("数据保存成功!");
|
} else {
|
window.parent.parent.notify("数据保存出错,请重新操作!");
|
}
|
}, "json");
|
}
|
|
|
//执行查询
|
function query() {
|
$.get("./cgi-bin/sys-port/query", function (data, status) {
|
if ("success" == status) {
|
PORT_LIST = data;
|
renderTable();
|
} else {
|
window.parent.parent.notify("数据查询出错,请重新操作!!");
|
}
|
}, "json");
|
}
|
|
//渲染表格
|
function renderTable() {
|
$("#tbody-data").html('');
|
// console.log(list);
|
//赋值
|
var cur;
|
for (var i = 1; i <= PORT_LIST.length; i++) {
|
cur = PORT_LIST[i - 1];
|
renderTableItem(cur);
|
}
|
}
|
|
//渲染表格
|
function renderTableItem(data) {
|
|
var html = '';
|
html += '<tr>';
|
html += '<td>';
|
html += '<select id="no-'+data.no+'" class="f1" disabled>';
|
html += '<option value="'+data.no+'" selected>COM'+data.no+'</option>';
|
html += '</select>';
|
html += '</td>';
|
html += '<td>';
|
html += '<select id="baudrate-'+data.no+'" class="f1">';
|
html += '<option value="115200">115200</option>';
|
html += '<option value="57600">57600</option>';
|
html += '<option value="38400">38400</option>';
|
html += '<option value="19200">19200</option>';
|
html += '<option value="9600">9600</option>';
|
html += '<option value="4800">4800</option>';
|
html += '<option value="2400">2400</option>';
|
html += '</select>';
|
html += '</td>';
|
html += '<td>';
|
html += '<select id="parity-'+data.no+'" class="f1">';
|
html += '<option value="0">不校验</option>';
|
html += '<option value="1">奇校验</option>';
|
html += '<option value="2">偶校验</option>';
|
html += '</select>';
|
html += '</td>';
|
html += '<td>';
|
html += '<select id="databits-'+data.no+'" class="f1">';
|
html += '<option value="5">5</option>';
|
html += '<option value="6">6</option>';
|
html += '<option value="7">7</option>';
|
html += '<option value="8">8</option>';
|
html += '</select>';
|
html += '</td>';
|
html += '<td>';
|
html += '<select id="stopbits-'+data.no+'" class="f1">';
|
html += '<option value="1">1</option>';
|
html += '<option value="2">2</option>';
|
html += '</select>';
|
html += '</td>';
|
html += '<td>';
|
html += '<input id="timeout-'+data.no+'" class="f1" value="500">ms';
|
html += '</td>';
|
html += '<td>';
|
html += '<input id="pollTime-'+data.no+'" class="f1" value="1000">ms';
|
html += '</td>';
|
html += '<td>';
|
html += '<input id="vld-'+data.no+'" class="f2" type="checkbox" checked>';
|
html += '</td>';
|
html += '</tr>';
|
|
$("#tbody-data").append(html);
|
|
$("#no-"+data.no).val(data.no);
|
$("#baudrate-"+data.no).val(data.baudrate);
|
$("#parity-"+data.no).val(data.parity);
|
$("#databits-"+data.no).val(data.databits);
|
$("#stopbits-"+data.no).val(data.stopbits);
|
$("#timeout-"+data.no).val(data.timeout);
|
$("#pollTime-"+data.no).val(data.pollTime);
|
// $("#vld-"+data.on).val(data.vld);
|
if (0 == data.vld || "0" == data.vld) {
|
$("#vld-" + data.no).attr("checked", true);
|
} else {
|
$("#vld-" + data.no).attr("checked", false);
|
}
|
|
}
|
|