增加上位机代码
This commit is contained in:
parent
7c0ce22434
commit
abce486b2b
2
标定上位机/.gitignore
vendored
Normal file
2
标定上位机/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/dist
|
||||
/.build
|
8
标定上位机/default.aproj
Normal file
8
标定上位机/default.aproj
Normal file
@ -0,0 +1,8 @@
|
||||
<?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"/>
|
||||
</folder>
|
||||
<folder name="窗体文件" path="dlg" comment="目录" embed="true"/>
|
||||
</project>
|
20
标定上位机/lib/config.aardio
Normal file
20
标定上位机/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**/
|
171
标定上位机/main.aardio
Normal file
171
标定上位机/main.aardio
Normal file
@ -0,0 +1,171 @@
|
||||
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;z=6};
|
||||
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};
|
||||
button={cls="button";text='\u2460 设定原点';left=123;top=269;right=294;bottom=315;font=LOGFONT(h=-18);z=12};
|
||||
button2={cls="button";text='\u2461 记录当前位置';left=406;top=131;right=594;bottom=191;font=LOGFONT(h=-18);z=15};
|
||||
combobox={cls="combobox";left=154;top=61;right=332;bottom=87;edge=1;font=LOGFONT(h=-20);items={};mode="dropdown";z=1};
|
||||
edNowloc={cls="edit";text="0";left=176;top=167;right=303;bottom=199;edge=1;multiline=1;z=11};
|
||||
edXdloc={cls="edit";text="0";left=176;top=208;right=303;bottom=240;edge=1;multiline=1;z=14};
|
||||
edit={cls="edit";left=496;top=35;right=870;bottom=60;disabled=1;edge=1;readonly=1;z=9};
|
||||
editRx={cls="edit";left=403;top=200;right=874;bottom=546;edge=1;font=LOGFONT(h=-20);multiline=1;readonly=1;vscroll=1;z=5};
|
||||
lbComPort={cls="static";text="串口信息";left=40;top=4;right=413;bottom=40;transparent=1;z=2};
|
||||
static={cls="static";text="V0.1 20231215";left=16;top=563;right=134;bottom=582;font=LOGFONT(h=-16);notify=1;transparent=1;z=7};
|
||||
static2={cls="static";text="当前位置";left=92;top=165;right=166;bottom=204;align="center";center=1;transparent=1;z=10};
|
||||
static3={cls="static";text="报文记录";left=494;top=4;right=587;bottom=36;center=1;transparent=1;z=8};
|
||||
static4={cls="static";text="相对位置";left=92;top=207;right=166;bottom=246;align="center";center=1;transparent=1;z=13}
|
||||
)
|
||||
/*}}*/
|
||||
|
||||
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 ProState = 0;
|
||||
var LastData = 0;
|
||||
var TimerCount = 0;
|
||||
var Datalen = 0;
|
||||
var data = {};
|
||||
var tempstr = "";
|
||||
var nowloc = 0;
|
||||
var zeroloc = 0x8000;
|
||||
var xdloc = 0;
|
||||
DataPrecess = function(str){
|
||||
data = string.split(str,' ');
|
||||
if(data[1] != "AA" || data[2] != "55"){//检测到帧头
|
||||
//tempstr += "帧头错误"
|
||||
return;
|
||||
}
|
||||
mainForm.edit.text = str;
|
||||
nowloc = ((tonumber(data[3],16)<<8) + tonumber(data[4],16));
|
||||
xdloc = zeroloc-nowloc;
|
||||
}
|
||||
display = function(){
|
||||
mainForm.edNowloc.text = nowloc;
|
||||
mainForm.edXdloc.text = xdloc;
|
||||
}
|
||||
|
||||
var datastr = "";
|
||||
|
||||
var timer = win.timer(mainForm,10);
|
||||
timer.onTimer = function(hwnd,msg,id,tick){
|
||||
display();
|
||||
if(ProState == 0){
|
||||
TimerCount = 0;
|
||||
return ;
|
||||
}
|
||||
TimerCount += 1;
|
||||
if(TimerCount > 3){
|
||||
ProState = 0;
|
||||
data = {};
|
||||
TimerCount = 0;
|
||||
DataPrecess(string.trim(datastr));
|
||||
//mainForm.editRx.print(tempstr);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mainForm.btnOpen.oncommand = function(id,event){
|
||||
if(sioPort){
|
||||
sioPort.close();
|
||||
}
|
||||
|
||||
var err;
|
||||
if(#mainForm.combobox.selText > 0){
|
||||
sioPort,err = sio.port(mainForm.combobox.selText);
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
if(!sioPort){
|
||||
return mainForm.msgErr(err,300);
|
||||
}
|
||||
sioPort.ioctl(115200,8,1,"none");
|
||||
//串口接收到数据触发回调
|
||||
sioPort.termCntIrq(1,function(port){
|
||||
var ret = sioPort.readHex()
|
||||
var num = tonumber(ret,16,2);
|
||||
if(ProState == 0){
|
||||
tempstr = tostring(time.now()) + " Rx:"
|
||||
datastr = "";
|
||||
}
|
||||
if(ret != null){
|
||||
tempstr += ret;
|
||||
datastr += ret;
|
||||
}
|
||||
|
||||
ProState = 1;
|
||||
TimerCount = 0;
|
||||
/*
|
||||
if(num != null){
|
||||
DataPrecess(num);
|
||||
}
|
||||
*/
|
||||
} )
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
mainForm.button.oncommand = function(id,event){
|
||||
zeroloc = nowloc;
|
||||
mainForm.editRx.print("设定位置 "++nowloc++" 为原点");
|
||||
}
|
||||
|
||||
mainForm.button2.oncommand = function(id,event){
|
||||
mainForm.editRx.print("记录当前位置:"++nowloc++",相对位置:"++xdloc);
|
||||
}
|
||||
|
||||
mainForm.combobox.oncommand();
|
||||
|
||||
mainForm.show();
|
||||
return win.loopMessage();
|
Loading…
x
Reference in New Issue
Block a user