上位机OK
This commit is contained in:
parent
1c27e6d539
commit
ae01cb1f6a
2
K86串口CAN上位机/.gitignore
vendored
Normal file
2
K86串口CAN上位机/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/dist
|
||||
/.build
|
10
K86串口CAN上位机/default.aproj
Normal file
10
K86串口CAN上位机/default.aproj
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project ver="10" name="K86上位机" libEmbed="true" icon="..." ui="win" output="K86上位机.exe" CompanyName="单位名称" FileDescription="K86上位机" LegalCopyright="Copyright (C) 作者 2022" ProductName="K86上位机" InternalName="K86上位机" FileVersion="0.0.0.6" ProductVersion="0.0.0.6" 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="image1.png" path="res\img\image1.png" comment="res\img\image1.png"/>
|
||||
</folder>
|
||||
</folder>
|
||||
<folder name="窗体文件" path="dlg" comment="目录" embed="true" local="false" ignored="false"/>
|
||||
</project>
|
20
K86串口CAN上位机/lib/config.aardio
Normal file
20
K86串口CAN上位机/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**/
|
233
K86串口CAN上位机/main.aardio
Normal file
233
K86串口CAN上位机/main.aardio
Normal file
@ -0,0 +1,233 @@
|
||||
import fonts.fontAwesome;
|
||||
import win.dlg.message;
|
||||
import win.ui;
|
||||
/*DSG{{*/
|
||||
mainForm = win.form(text="K86上位机";right=885;bottom=591;border="dialog frame";max=false)
|
||||
mainForm.add(
|
||||
btnClear={cls="button";text="清空";left=741;top=537;right=854;bottom=579;font=LOGFONT(h=-19);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};
|
||||
combobox={cls="combobox";left=154;top=61;right=332;bottom=87;edge=1;font=LOGFONT(h=-20);items={};mode="dropdown";z=1};
|
||||
editRx={cls="edit";left=526;top=25;right=854;bottom=523;bgcolor=16777215;edge=1;font=LOGFONT(h=-19);multiline=1;readonly=1;vscroll=1;z=5};
|
||||
lbComPort={cls="static";text="串口信息";left=40;top=4;right=413;bottom=40;transparent=1;z=2};
|
||||
plKey1={cls="plus";text="滑轨前";left=79;top=177;right=179;bottom=246;bgcolor=-5723992;font=LOGFONT(h=-16);z=8};
|
||||
plKey2={cls="plus";text="滑轨后";left=79;top=252;right=179;bottom=321;bgcolor=-5723992;font=LOGFONT(h=-16);z=9};
|
||||
plKey3={cls="plus";text="靠背前";left=268;top=177;right=368;bottom=246;bgcolor=-5723992;font=LOGFONT(h=-16);z=10};
|
||||
plKey4={cls="plus";text="靠背后";left=268;top=252;right=368;bottom=321;bgcolor=-5723992;font=LOGFONT(h=-16);z=11};
|
||||
plKey5={cls="plus";text="腿托升";left=79;top=361;right=179;bottom=430;bgcolor=-5723992;font=LOGFONT(h=-16);z=12};
|
||||
plKey6={cls="plus";text="腿托降";left=79;top=437;right=179;bottom=506;bgcolor=-5723992;font=LOGFONT(h=-16);z=13};
|
||||
plKey7={cls="plus";text="零重力开";left=268;top=361;right=368;bottom=430;bgcolor=-5723992;font=LOGFONT(h=-16);z=14};
|
||||
plKey8={cls="plus";text="零重力关";left=268;top=437;right=368;bottom=506;bgcolor=-5723992;font=LOGFONT(h=-16);z=15};
|
||||
static={cls="static";text="V1.0 20250215";left=16;top=563;right=134;bottom=582;font=LOGFONT(h=-16);notify=1;transparent=1;z=7}
|
||||
)
|
||||
/*}}*/
|
||||
|
||||
var keyColor = {0xFFA8A8A8,0xFF00FF00};
|
||||
|
||||
import sys.comPort;
|
||||
import console;
|
||||
import sio;
|
||||
import win.timer;
|
||||
|
||||
|
||||
var sioPort;
|
||||
|
||||
logPrint = function(str){
|
||||
mainForm.editRx.print(str);
|
||||
}
|
||||
|
||||
|
||||
//串口列表
|
||||
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 = {};
|
||||
var KeyDelay = {};
|
||||
for(i=1;8;1){
|
||||
KeyDelay[i] = 0;
|
||||
}
|
||||
|
||||
|
||||
display = function(){
|
||||
for(i=1;8;1){
|
||||
if(KeyDelay[i] > 0){
|
||||
KeyLedCtrl(i,1);
|
||||
KeyDelay[i]--;
|
||||
}
|
||||
else {
|
||||
KeyLedCtrl(i,0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
KeyLedCtrl = function(keyid,state){
|
||||
if(keyid > 0 && keyid < 9){
|
||||
mainForm["plKey"++keyid].background = keyColor[state + 1];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
DataPrecess = function(str){
|
||||
//logPrint(string.left(str,35));
|
||||
if(#str != 59){
|
||||
return ;
|
||||
}
|
||||
if(string.cmpMatch(string.left(str,14),"01 01 02 00 00" )){
|
||||
datastr = string.slice(str,36,59);
|
||||
logPrint(datastr);
|
||||
data = string.split(datastr,' ');
|
||||
|
||||
keydata = tonumber(data[2],16);
|
||||
//logPrint(data[2]);
|
||||
|
||||
for(i=0;7;1){
|
||||
if(keydata & (1<<i)){
|
||||
KeyDelay[i+1] = 5;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
logPrint(string.left(str,14));
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(data[13] == "03"){
|
||||
//mainForm.editRx.print("从机未响应");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
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,100);
|
||||
timer.onTimer = function(hwnd,msg,id,tick){
|
||||
//LIN_Sch_Ctrl();
|
||||
display();
|
||||
//mainForm.editRx.print("test");
|
||||
|
||||
}
|
||||
|
||||
CanDevInit = function(){
|
||||
TxMsg("06 01");
|
||||
sleep(50);
|
||||
|
||||
TxMsg("03 01 F4 01 00 00 12 00 00 05 00");
|
||||
sleep(50);
|
||||
|
||||
TxMsg("03 05");
|
||||
sleep(50);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
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(115200,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;
|
||||
}
|
||||
|
||||
|
||||
TX_str = "00 FC"
|
||||
msg_tx = function(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
mainForm.btnClear.oncommand = function(id,event){
|
||||
mainForm.editRx.text = ""
|
||||
}
|
||||
|
||||
|
||||
mainForm.combobox.oncommand();
|
||||
display();
|
||||
mainForm.show();
|
||||
//mainForm.plKey3.background = 0xFF00FF00;
|
||||
return win.loopMessage();
|
0
K86串口CAN上位机/res/img/.gitkeep
Normal file
0
K86串口CAN上位机/res/img/.gitkeep
Normal file
Loading…
x
Reference in New Issue
Block a user