增加上位机
This commit is contained in:
parent
f6c3034d93
commit
284f30c9f2
2
K74B串口上位机/.gitignore
vendored
Normal file
2
K74B串口上位机/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/dist
|
||||||
|
/.build
|
30
K74B串口上位机/default.aproj
Normal file
30
K74B串口上位机/default.aproj
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<project ver="10" name="串口上位机" libEmbed="true" icon="..." ui="win" output="串口上位机.exe" CompanyName="单位名称" FileDescription="串口上位机" LegalCopyright="Copyright (C) 作者 2022" ProductName="串口上位机" InternalName="串口上位机" FileVersion="0.0.0.02" ProductVersion="0.0.0.02" publishDir="/dist/" dstrip="false">
|
||||||
|
<file name="main.aardio" path="main.aardio" comment="main.aardio"/>
|
||||||
|
<folder name="资源文件" path="res" embed="true" local="false" ignored="false">
|
||||||
|
<folder name="img" path="res\img" comment="res\img" local="false" embed="true" ignored="false">
|
||||||
|
<file name="坐垫上升.png" path="res\img\坐垫上升.png" comment="res\img\坐垫上升.png"/>
|
||||||
|
<file name="坐垫下降.png" path="res\img\坐垫下降.png" comment="res\img\坐垫下降.png"/>
|
||||||
|
<file name="头枕上升.png" path="res\img\头枕上升.png" comment="res\img\头枕上升.png"/>
|
||||||
|
<file name="头枕下降.png" path="res\img\头枕下降.png" comment="res\img\头枕下降.png"/>
|
||||||
|
<file name="座椅加热0.png" path="res\img\座椅加热0.png" comment="res\img\座椅加热0.png"/>
|
||||||
|
<file name="座椅加热1.png" path="res\img\座椅加热1.png" comment="res\img\座椅加热1.png"/>
|
||||||
|
<file name="座椅加热2.png" path="res\img\座椅加热2.png" comment="res\img\座椅加热2.png"/>
|
||||||
|
<file name="座椅加热3.png" path="res\img\座椅加热3.png" comment="res\img\座椅加热3.png"/>
|
||||||
|
<file name="座椅复位.png" path="res\img\座椅复位.png" comment="res\img\座椅复位.png"/>
|
||||||
|
<file name="座椅按摩0.png" path="res\img\座椅按摩0.png" comment="res\img\座椅按摩0.png"/>
|
||||||
|
<file name="座椅按摩1.png" path="res\img\座椅按摩1.png" comment="res\img\座椅按摩1.png"/>
|
||||||
|
<file name="座椅通风0.png" path="res\img\座椅通风0.png" comment="res\img\座椅通风0.png"/>
|
||||||
|
<file name="座椅通风1.png" path="res\img\座椅通风1.png" comment="res\img\座椅通风1.png"/>
|
||||||
|
<file name="座椅通风2.png" path="res\img\座椅通风2.png" comment="res\img\座椅通风2.png"/>
|
||||||
|
<file name="座椅通风3.png" path="res\img\座椅通风3.png" comment="res\img\座椅通风3.png"/>
|
||||||
|
<file name="滑轨前移.png" path="res\img\滑轨前移.png" comment="res\img\滑轨前移.png"/>
|
||||||
|
<file name="滑轨后移.png" path="res\img\滑轨后移.png" comment="res\img\滑轨后移.png"/>
|
||||||
|
<file name="腿托升起.png" path="res\img\腿托升起.png" comment="res\img\腿托升起.png"/>
|
||||||
|
<file name="腿托降下.png" path="res\img\腿托降下.png" comment="res\img\腿托降下.png"/>
|
||||||
|
<file name="靠背前移.png" path="res\img\靠背前移.png" comment="res\img\靠背前移.png"/>
|
||||||
|
<file name="靠背后移.png" path="res\img\靠背后移.png" comment="res\img\靠背后移.png"/>
|
||||||
|
</folder>
|
||||||
|
</folder>
|
||||||
|
<folder name="窗体文件" path="dlg" comment="目录" embed="true"/>
|
||||||
|
</project>
|
20
K74B串口上位机/lib/config.aardio
Normal file
20
K74B串口上位机/lib/config.aardio
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
//config 配置文件
|
||||||
|
import fsys.config;
|
||||||
|
config = fsys.config("/config/");
|
||||||
|
//config = fsys.config( io.appData("/软件作者/应用程序名/") );
|
||||||
|
|
||||||
|
//不需要序列化的配置名字前请添加下划线
|
||||||
|
namespace config {
|
||||||
|
__appName = "应用程序名";
|
||||||
|
__appVersion = "1.0.0.01";
|
||||||
|
__appDescription = "这是一个测试程序";
|
||||||
|
__website = "http://www.aardio.com/";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**intellisense(config)
|
||||||
|
__appName = 应用程序名
|
||||||
|
__appVersion = 应用程序内部版本号
|
||||||
|
__appDescription = 程序说明
|
||||||
|
__website = 官方网站
|
||||||
|
? = 配置文件名,\n读写配置并序列化为一个表对象,\n表的成员值可以是支持序列化的普通变量,支持table对象\n配置文件在首次使用时自动加载,退出程序时自动保存\n!fsys_table.
|
||||||
|
end intellisense**/
|
276
K74B串口上位机/main.aardio
Normal file
276
K74B串口上位机/main.aardio
Normal file
@ -0,0 +1,276 @@
|
|||||||
|
import fonts.fontAwesome;
|
||||||
|
import win.dlg.message;
|
||||||
|
import win.ui;
|
||||||
|
/*DSG{{*/
|
||||||
|
mainForm = win.form(text="串口上位机";right=885;bottom=591;border="dialog frame";max=false)
|
||||||
|
mainForm.add(
|
||||||
|
btnClear={cls="button";text="清空";left=760;top=555;right=875;bottom=582;hide=1;z=14};
|
||||||
|
btnFresh={cls="button";text="刷新";left=41;top=47;right=138;bottom=101;font=LOGFONT(h=-20);z=3};
|
||||||
|
btnOpen={cls="button";text="打开";left=346;top=47;right=442;bottom=101;font=LOGFONT(h=-20);z=4};
|
||||||
|
btnfan0={cls="button";text="通风关";left=15;top=414;right=124;bottom=473;font=LOGFONT(h=-20);z=6};
|
||||||
|
btnfan1={cls="button";text="通风低";left=133;top=414;right=242;bottom=473;font=LOGFONT(h=-20);z=7};
|
||||||
|
btnfan2={cls="button";text="通风中";left=251;top=414;right=360;bottom=473;font=LOGFONT(h=-20);z=8};
|
||||||
|
btnfan3={cls="button";text="通风高";left=369;top=414;right=478;bottom=473;font=LOGFONT(h=-20);z=9};
|
||||||
|
btnheat0={cls="button";text="加热关";left=15;top=486;right=124;bottom=545;font=LOGFONT(h=-20);z=10};
|
||||||
|
btnheat1={cls="button";text="加热低";left=133;top=486;right=242;bottom=545;font=LOGFONT(h=-20);z=11};
|
||||||
|
btnheat2={cls="button";text="加热中";left=252;top=486;right=361;bottom=545;font=LOGFONT(h=-20);z=12};
|
||||||
|
btnheat3={cls="button";text="加热高";left=371;top=486;right=480;bottom=545;font=LOGFONT(h=-20);z=13};
|
||||||
|
combobox={cls="combobox";left=154;top=61;right=332;bottom=87;edge=1;font=LOGFONT(h=-20);items={};mode="dropdown";z=1};
|
||||||
|
edRx1={cls="edit";left=565;top=8;right=867;bottom=50;disabled=1;edge=1;font=LOGFONT(h=-18);multiline=1;readonly=1;z=17};
|
||||||
|
edRx2={cls="edit";left=565;top=55;right=867;bottom=94;disabled=1;edge=1;font=LOGFONT(h=-18);multiline=1;readonly=1;z=20};
|
||||||
|
editRx={cls="edit";left=491;top=414;right=874;bottom=546;edge=1;hide=1;multiline=1;readonly=1;vscroll=1;z=5};
|
||||||
|
lbComPort={cls="static";text="串口信息";left=40;top=4;right=413;bottom=40;transparent=1;z=2};
|
||||||
|
plus={cls="plus";left=73;top=115;right=809;bottom=384;background="\res\img\image1.png";z=21};
|
||||||
|
stFw={cls="static";text='\uF05D';left=627;top=224;right=693;bottom=272;align="center";center=1;color=49152;font=LOGFONT(h=-56;name='FontAwesome');transparent=1;z=34};
|
||||||
|
stHgh={cls="static";text='\uF05D';left=380;top=174;right=446;bottom=222;align="center";center=1;color=49152;font=LOGFONT(h=-56;name='FontAwesome');transparent=1;z=25};
|
||||||
|
stHgq={cls="static";text='\uF05D';left=252;top=178;right=318;bottom=226;align="center";center=1;color=49152;font=LOGFONT(h=-56;name='FontAwesome');transparent=1;z=24};
|
||||||
|
stJr={cls="static";text='\uF05D';left=155;top=271;right=221;bottom=319;align="center";center=1;color=49152;font=LOGFONT(h=-56;name='FontAwesome');transparent=1;z=22};
|
||||||
|
stKbh={cls="static";text='\uF05D';left=471;top=280;right=537;bottom=328;align="center";center=1;color=49152;font=LOGFONT(h=-56;name='FontAwesome');transparent=1;z=29};
|
||||||
|
stKbq={cls="static";text='\uF05D';left=473;top=169;right=539;bottom=217;align="center";center=1;color=49152;font=LOGFONT(h=-56;name='FontAwesome');transparent=1;z=28};
|
||||||
|
stTf={cls="static";text='\uF05D';left=161;top=175;right=227;bottom=223;align="center";center=1;color=49152;font=LOGFONT(h=-56;name='FontAwesome');transparent=1;z=23};
|
||||||
|
stTth={cls="static";text='\uF05D';left=377;top=276;right=443;bottom=324;align="center";center=1;color=49152;font=LOGFONT(h=-56;name='FontAwesome');transparent=1;z=27};
|
||||||
|
stTtq={cls="static";text='\uF05D';left=250;top=272;right=316;bottom=320;align="center";center=1;color=49152;font=LOGFONT(h=-56;name='FontAwesome');transparent=1;z=26};
|
||||||
|
stTzj={cls="static";text='\uF05D';left=688;top=220;right=754;bottom=268;align="center";center=1;color=49152;font=LOGFONT(h=-56;name='FontAwesome');transparent=1;z=33};
|
||||||
|
stTzs={cls="static";text='\uF05D';left=566;top=219;right=632;bottom=267;align="center";center=1;color=49152;font=LOGFONT(h=-56;name='FontAwesome');transparent=1;z=32};
|
||||||
|
stZyj={cls="static";text='\uF05D';left=629;top=280;right=695;bottom=328;align="center";center=1;color=49152;font=LOGFONT(h=-56;name='FontAwesome');transparent=1;z=31};
|
||||||
|
stZys={cls="static";text='\uF05D';left=627;top=168;right=693;bottom=216;align="center";center=1;color=49152;font=LOGFONT(h=-56;name='FontAwesome');transparent=1;z=30};
|
||||||
|
static={cls="static";text="V0.1 20231211";left=16;top=563;right=134;bottom=582;font=LOGFONT(h=-16);notify=1;transparent=1;z=15};
|
||||||
|
static2={cls="static";text="0x06";left=512;top=19;right=562;bottom=42;align="right";center=1;font=LOGFONT(h=-16);transparent=1;z=18};
|
||||||
|
static3={cls="static";text="0x08";left=513;top=63;right=563;bottom=86;align="right";center=1;font=LOGFONT(h=-16);transparent=1;z=19};
|
||||||
|
static4={cls="static";left=183;top=347;right=382;bottom=376;center=1;font=LOGFONT(h=-20);transparent=1;z=16}
|
||||||
|
)
|
||||||
|
/*}}*/
|
||||||
|
|
||||||
|
import sys.comPort;
|
||||||
|
import console;
|
||||||
|
import sio;
|
||||||
|
import win.timer;
|
||||||
|
|
||||||
|
|
||||||
|
var sioPort;
|
||||||
|
//串口列表
|
||||||
|
FreshHw = function(){
|
||||||
|
comPorts = sys.comPort.list();
|
||||||
|
mainForm.combobox.items = comPorts;
|
||||||
|
mainForm.combobox.selIndex = sys.comPort.find("CP210x")[["index"]] or 1;
|
||||||
|
if(#comPorts == 0){
|
||||||
|
mainForm.lbComPort.text = "没有找到硬件"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FreshHw();
|
||||||
|
|
||||||
|
|
||||||
|
//获取串口信息
|
||||||
|
mainForm.combobox.oncommand = function(id,event){
|
||||||
|
var item = comPorts[mainForm.combobox.selIndex]
|
||||||
|
if(item){
|
||||||
|
mainForm.lbComPort.text = item.friendlyName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mainForm.btnFresh.oncommand = function(id,event){
|
||||||
|
FreshHw();
|
||||||
|
mainForm.combobox.oncommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var data = {};
|
||||||
|
|
||||||
|
key_tf = 0;
|
||||||
|
key_jr = 0;
|
||||||
|
key_tzs = 0;
|
||||||
|
key_tzj = 0;
|
||||||
|
key_kbq = 0;
|
||||||
|
key_kbh = 0;
|
||||||
|
key_hgq = 0;
|
||||||
|
key_hgh = 0;
|
||||||
|
key_zys = 0;
|
||||||
|
key_zyj = 0;
|
||||||
|
key_tts = 0;
|
||||||
|
key_ttj = 0;
|
||||||
|
key_fw = 0;
|
||||||
|
display = function(){
|
||||||
|
mainForm.stJr.show(key_jr)
|
||||||
|
mainForm.stTf.show(key_tf)
|
||||||
|
mainForm.stTzs.show(key_tzs)
|
||||||
|
mainForm.stTzj.show(key_tzj)
|
||||||
|
mainForm.stKbq.show(key_kbq)
|
||||||
|
mainForm.stKbh.show(key_kbh)
|
||||||
|
mainForm.stHgq.show(key_hgq)
|
||||||
|
mainForm.stHgh.show(key_hgh)
|
||||||
|
mainForm.stZys.show(key_zys)
|
||||||
|
mainForm.stZyj.show(key_zyj)
|
||||||
|
mainForm.stTtq.show(key_tts)
|
||||||
|
mainForm.stTth.show(key_ttj)
|
||||||
|
mainForm.stFw.show(key_fw)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
DataPrecess = function(str){
|
||||||
|
data = string.split(str,' ');
|
||||||
|
if(data[13] == "03"){
|
||||||
|
//mainForm.editRx.print("从机未响应");
|
||||||
|
}
|
||||||
|
select(data[3]) {//id
|
||||||
|
case "06" {
|
||||||
|
mainForm.edRx1.text = string.slice(str,10,14);
|
||||||
|
var key = tonumber(data[4],16);
|
||||||
|
key_tf = (key>>1)&0x01;
|
||||||
|
key_jr = key&0x01;
|
||||||
|
}
|
||||||
|
case "08" {
|
||||||
|
mainForm.edRx2.text = string.slice(str,10,32);
|
||||||
|
var key1 = tonumber(data[4],16);
|
||||||
|
var key2 = tonumber(data[5],16);
|
||||||
|
var key3 = tonumber(data[6],16);
|
||||||
|
key_tzs = (key1&0x20)?1:0;
|
||||||
|
key_tzj = (key1&0x10)?1:0;
|
||||||
|
key_kbq = (key1&0x08)?1:0;
|
||||||
|
key_kbh = (key1&0x04)?1:0;
|
||||||
|
key_hgq = (key1&0x01)?1:0;
|
||||||
|
key_hgh = (key1&0x02)?1:0;
|
||||||
|
key_zys = (key2&0x10)?1:0;
|
||||||
|
key_zyj = (key2&0x20)?1:0;
|
||||||
|
key_tts = (key2&0x02)?1:0;
|
||||||
|
key_ttj = (key2&0x01)?1:0;
|
||||||
|
key_fw = (key3&0x10)?1:0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Sch_count = 0;
|
||||||
|
LIN_Sch_Ctrl = function(){
|
||||||
|
select(Sch_count) {
|
||||||
|
case 0 {
|
||||||
|
TxMsg("02 02 00 "++ TX_str ++" 33 44 55 66 77 88 D7 02")
|
||||||
|
Sch_count = 1;
|
||||||
|
}
|
||||||
|
case 1 {
|
||||||
|
TxMsg("02 00 06 11 22 33 44 55 66 77 88 D7 02")
|
||||||
|
Sch_count = 2;
|
||||||
|
}
|
||||||
|
case 2 {
|
||||||
|
TxMsg("02 00 08 11 22 33 44 55 66 77 88 D7 02")
|
||||||
|
Sch_count = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Sch_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var datastr = "";
|
||||||
|
|
||||||
|
var timer = win.timer(mainForm,10);
|
||||||
|
timer.onTimer = function(hwnd,msg,id,tick){
|
||||||
|
LIN_Sch_Ctrl();
|
||||||
|
display();
|
||||||
|
//mainForm.editRx.print("test");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mainForm.btnOpen.oncommand = function(id,event){
|
||||||
|
if(sioPort){
|
||||||
|
sioPort.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
var err;
|
||||||
|
sioPort,err = sio.port(mainForm.combobox.selText);
|
||||||
|
if(!sioPort){
|
||||||
|
return mainForm.msgErr(err,300);
|
||||||
|
}
|
||||||
|
sioPort.ioctl(9600,8,1,"none");
|
||||||
|
//串口接收到数据触发回调
|
||||||
|
sioPort.termCntIrq(1,function(port){
|
||||||
|
var ret = sioPort.readHex()
|
||||||
|
var num = tonumber(ret,16,2);
|
||||||
|
datastr = "";
|
||||||
|
if(ret != null){
|
||||||
|
datastr += ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataPrecess(string.trim(datastr));
|
||||||
|
|
||||||
|
} )
|
||||||
|
|
||||||
|
mainForm.msgOk("已打开端口",200);
|
||||||
|
timer.enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
mainForm.onDestroy = function(){
|
||||||
|
if(sioPort){
|
||||||
|
sioPort.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TxMsg = function(str){
|
||||||
|
if(sioPort == null){
|
||||||
|
//mainForm.msgErr("端口未打开",300);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//mainForm.editRx.print(tostring(time.now()) + " Tx: " + string.upper(str));
|
||||||
|
sioPort.writeHex(str);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tf_state = 0;
|
||||||
|
jr_state = 0;
|
||||||
|
mainForm.btnfan0.oncommand = function(id,event){
|
||||||
|
tf_state = 0;
|
||||||
|
jr_state = 0;
|
||||||
|
msg_tx();
|
||||||
|
}
|
||||||
|
mainForm.btnfan1.oncommand = function(id,event){
|
||||||
|
tf_state = 1;
|
||||||
|
jr_state = 0;
|
||||||
|
msg_tx();
|
||||||
|
}
|
||||||
|
mainForm.btnfan2.oncommand = function(id,event){
|
||||||
|
tf_state = 2;
|
||||||
|
jr_state = 0;
|
||||||
|
msg_tx();
|
||||||
|
}
|
||||||
|
mainForm.btnfan3.oncommand = function(id,event){
|
||||||
|
tf_state = 3;
|
||||||
|
jr_state = 0;
|
||||||
|
msg_tx();
|
||||||
|
}
|
||||||
|
|
||||||
|
mainForm.btnheat0.oncommand = function(id,event){
|
||||||
|
tf_state = 0;
|
||||||
|
jr_state = 0;
|
||||||
|
msg_tx();
|
||||||
|
}
|
||||||
|
mainForm.btnheat1.oncommand = function(id,event){
|
||||||
|
tf_state = 0;
|
||||||
|
jr_state = 1;
|
||||||
|
msg_tx();
|
||||||
|
}
|
||||||
|
mainForm.btnheat2.oncommand = function(id,event){
|
||||||
|
tf_state = 0;
|
||||||
|
jr_state = 2;
|
||||||
|
msg_tx();
|
||||||
|
}
|
||||||
|
mainForm.btnheat3.oncommand = function(id,event){
|
||||||
|
tf_state = 0;
|
||||||
|
jr_state = 3;
|
||||||
|
msg_tx();
|
||||||
|
}
|
||||||
|
TX_str = "00 FC"
|
||||||
|
msg_tx = function(){
|
||||||
|
var data = (tf_state<<2) | (jr_state);
|
||||||
|
var str = tostring(data,16);
|
||||||
|
str = string.right(str,1);
|
||||||
|
TX_str = str ++ "0 FC"
|
||||||
|
//mainForm.editRx.print(TX_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mainForm.btnClear.oncommand = function(id,event){
|
||||||
|
mainForm.editRx.text = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mainForm.combobox.oncommand();
|
||||||
|
display();
|
||||||
|
mainForm.show();
|
||||||
|
return win.loopMessage();
|
BIN
K74B串口上位机/res/img/image1.png
Normal file
BIN
K74B串口上位机/res/img/image1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 116 KiB |
Loading…
x
Reference in New Issue
Block a user