完善modbus
This commit is contained in:
parent
663ec6f433
commit
3ef7dd2fb5
@ -34,7 +34,7 @@
|
|||||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||||
<UseOfMfc>false</UseOfMfc>
|
<UseOfMfc>false</UseOfMfc>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
<PlatformToolset>v120_xp</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<Window size="1280,1024" sizebox="2,2,2,2" caption="0,0,0,35" mininfo="800,600">
|
|
||||||
<VBox bkcolor="bk_wnd_darkcolor">
|
|
||||||
<!-- 标题栏 -->
|
|
||||||
<HBox width="stretch" height="40" bkcolor="bk_wnd_lightcolor">
|
|
||||||
<Control margin="60,0,0,0" />
|
|
||||||
<Label name="title" text="协议调试器" align="left" height="40" font="title"/>
|
|
||||||
<Control />
|
|
||||||
<Button class="btn_wnd_min" name="minbtn" margin="4,6,0,0"/>
|
|
||||||
<Box width="30" margin="4,6,0,0">
|
|
||||||
<Button class="btn_wnd_max" name="maxbtn"/>
|
|
||||||
<Button class="btn_wnd_restore" name="restorebtn" visible="false"/>
|
|
||||||
</Box>
|
|
||||||
<Button class="btn_wnd_close" name="closebtn" margin="4,6,8,0"/>
|
|
||||||
</HBox>
|
|
||||||
<!-- 侧边栏 -->
|
|
||||||
<HBox>
|
|
||||||
<Box width="150" height="stretch">
|
|
||||||
<VBox valign="top" halign="left" width="150" height="stretch" >
|
|
||||||
<Button class="btn_global_blue_80x30" width="100" name="add_new" margin="25,3,5,3" />
|
|
||||||
<TreeView class="list" name="tree" height="stretch" padding="0,3,5,3">
|
|
||||||
</TreeView>
|
|
||||||
</VBox>
|
|
||||||
</Box>
|
|
||||||
<!-- 主界面 -->
|
|
||||||
<TabBox name="tab_side" width="stretch" height="stretch">
|
|
||||||
</TabBox>
|
|
||||||
</HBox>
|
|
||||||
</VBox>
|
|
||||||
</Window>
|
|
@ -1,52 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<Window size="250,300" caption="0,0,0,35">
|
|
||||||
<VBox bkcolor="bk_wnd_darkcolor">
|
|
||||||
<!-- 标题栏 -->
|
|
||||||
<HBox width="stretch" height="35" bkcolor="bk_wnd_lightcolor">
|
|
||||||
<Label name="title" text="新建监听项" valign="center" margin="60,15,0,0" align="left" width="stretch" height="35" font="arial_14"/>
|
|
||||||
</HBox>
|
|
||||||
<HBox width="stretch" height="35" margin="10,10,10,10">
|
|
||||||
<Label name="title" text="类型:" valign="bottom" margin="30,0,0,0" width="70" height="30" font="arial_14"/>
|
|
||||||
<Combo class="list" name="combo_type" height="30" width="130" bkimage="file='../public/combo/normal.png' corner='5,5,30,5'"/>
|
|
||||||
<Control width="stretch"/>
|
|
||||||
</HBox>
|
|
||||||
<VBox bkcolor="bk_wnd_darkcolor" height="100" visible="false" name="uart_config">
|
|
||||||
<HBox width="stretch" height="35" margin="10,10,10,10">
|
|
||||||
<Label name="title" text="串口:" valign="bottom" margin="30,0,0,0" width="70" height="30" font="arial_14"/>
|
|
||||||
<Combo class="list" name="uart_type" height="30" width="110" bkimage="file='../public/combo/normal.png' corner='5,5,30,5'"/>
|
|
||||||
<Control width="stretch"/>
|
|
||||||
</HBox>
|
|
||||||
<HBox width="stretch" height="35" margin="10,10,10,10">
|
|
||||||
<Label name="title" text="波特率:" valign="bottom" margin="30,0,0,0" width="70" height="30" font="arial_14"/>
|
|
||||||
<Combo class="list" name="uart_baurate_select" height="30" width="110" bkimage="file='../public/combo/normal.png' corner='5,5,30,5'"/>
|
|
||||||
<Control width="stretch"/>
|
|
||||||
</HBox>
|
|
||||||
</VBox>
|
|
||||||
<VBox bkcolor="bk_wnd_darkcolor" height="100" visible="false" name="modbus_config_master">
|
|
||||||
<HBox width="stretch" height="35" margin="10,10,10,10">
|
|
||||||
<Label name="title" text="串口:" valign="bottom" margin="30,0,0,0" width="70" height="30" font="arial_14"/>
|
|
||||||
<Combo class="list" name="uart_type" height="30" width="110" bkimage="file='../public/combo/normal.png' corner='5,5,30,5'"/>
|
|
||||||
<Control width="stretch"/>
|
|
||||||
</HBox>
|
|
||||||
<HBox width="stretch" height="35" margin="10,10,10,10">
|
|
||||||
<Label name="title" text="波特率:" valign="bottom" margin="30,0,0,0" width="70" height="30" font="arial_14"/>
|
|
||||||
<Combo class="list" name="uart_baurate_select" height="30" width="110" bkimage="file='../public/combo/normal.png' corner='5,5,30,5'"/>
|
|
||||||
<Control width="stretch"/>
|
|
||||||
</HBox>
|
|
||||||
</VBox>
|
|
||||||
<VBox bkcolor="bk_wnd_darkcolor" height="90" visible="false" name="ip_config">
|
|
||||||
<HBox width="stretch" height="35" margin="10,0,0,0">
|
|
||||||
<Label name="title" text="ip: " valign="bottom" margin="30,0,0,0" width="70" height="30" font="arial_14"/>
|
|
||||||
<RichEdit class="simple input" width="90" name="ip_edit" height="30" margin="0,3" padding="6,6,6" />
|
|
||||||
<Control width="stretch"/>
|
|
||||||
</HBox>
|
|
||||||
<HBox width="stretch" height="35" margin="10,0,0,0">
|
|
||||||
<Label name="title_port" text="端口:" valign="bottom" margin="30,0,0,0" width="70" height="30" font="arial_14"/>
|
|
||||||
<RichEdit class="simple input" width="90" name="port_input" height="30" margin="0,3" padding="6,6,6" />
|
|
||||||
<Control width="stretch"/>
|
|
||||||
</HBox>
|
|
||||||
</VBox>
|
|
||||||
<Button class="btn_global_blue_80x30" name="open_button" width="100" margin="80,3,5,3" text="打开" />
|
|
||||||
<Button class="btn_global_blue_80x30" name="exit_button" width="100" margin="80,3,5,3" text="退出" />
|
|
||||||
</VBox>
|
|
||||||
</Window>
|
|
@ -1,33 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<ChildBox name="uart_form" width="stretch" height="stretch">
|
|
||||||
<VBox width="stretch" height="stretch">
|
|
||||||
<Label name="uart_info_label" text="当前串口: COM" margin="0,10,0,0" height="25" />
|
|
||||||
<HBox height="25" >
|
|
||||||
<Label text="数据接收:" margin="0,10,0,0" height="25" width="stretch"/>
|
|
||||||
<Label text="lua脚本:" margin="0,10,0,0" height="25" width="stretch"/>
|
|
||||||
</HBox>
|
|
||||||
<HBox>
|
|
||||||
<RichEdit class="simple input" width="stretch" name="uart_recv_eidt" height="stretch" margin="5,5,5,5" padding="6,6,6"
|
|
||||||
multiline="true" vscrollbar="true" hscrollbar="true" autovscroll="true" normaltextcolor="darkcolor" wantreturnmsg="true" rich="true" />
|
|
||||||
<RichEdit class="simple input" width="stretch"
|
|
||||||
name="lua_script" height="stretch"
|
|
||||||
margin="5,5,5,5" padding="6,6,6"
|
|
||||||
multiline="true" vscrollbar="true"
|
|
||||||
hscrollbar="true" autovscroll="true" normaltextcolor="darkcolor" wantreturnmsg="true" rich="true" />
|
|
||||||
</HBox>
|
|
||||||
<Label text="发送数据" height="25" />
|
|
||||||
<RichEdit class="simple input" width="stretch" name="uart_send_edit" height="30" margin="5,5,5,5" padding="6,6,6" />
|
|
||||||
<HBox height="40">
|
|
||||||
<Button class="btn_global_blue_80x30" name="btn_save_lua" width="100" text="保存lua脚本" bkcolor="lightcolor" margin="25,3,5,3" />
|
|
||||||
<Button class="btn_global_blue_80x30" name="btn_send_data" width="100" text="发送" bkcolor="lightcolor" margin="25,3,5,3" />
|
|
||||||
<CheckBox class="checkbox_font12" name="check_new_line" text="发送新行" margin="10,12,0,0" selected="true"/>
|
|
||||||
<CheckBox class="checkbox_font12" name="check_time_send" text="定时发送" margin="10,12,0,0" selected="true"/>
|
|
||||||
<CheckBox class="checkbox_font12" name="check_hex_send" text="hex显示" margin="10,12,0,0" selected="true"/>
|
|
||||||
<CheckBox class="checkbox_font12" name="check_hex_recv" text="hex接受" margin="10,12,0,0" selected="true"/>
|
|
||||||
<Button class="btn_global_blue_80x30" name="btn_close_uart" width="100" text="关闭" bkcolor="lightcolor" margin="25,3,5,3" />
|
|
||||||
|
|
||||||
</HBox>
|
|
||||||
</VBox>
|
|
||||||
</ChildBox>
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "cef_form.h"
|
#include "cef_form.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
const std::wstring CefForm::kClassName = L"CEF_Control_Example";
|
const std::wstring CefForm::kClassName = L"CEF_Control_Example";
|
||||||
|
|
||||||
@ -135,4 +136,8 @@ void CefForm::OnLoadEnd(int httpStatusCode)
|
|||||||
nim_comp::Toast::ShowToast(nbase::UTF8ToUTF16(params), 3000, GetHWND());
|
nim_comp::Toast::ShowToast(nbase::UTF8ToUTF16(params), 3000, GetHWND());
|
||||||
callback(false, R"({ "message": "Success." })");
|
callback(false, R"({ "message": "Success." })");
|
||||||
}));
|
}));
|
||||||
|
cef_control_->AttachUrlChange([this](const std::wstring& url) {
|
||||||
|
std::cout << "goto url";
|
||||||
|
return;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -573,6 +573,10 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
if (ui::EventType::kEventSelect == ev->Type) {
|
if (ui::EventType::kEventSelect == ev->Type) {
|
||||||
wprintf(L"%s\r\n", dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText().c_str());
|
wprintf(L"%s\r\n", dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText().c_str());
|
||||||
printf("GetCurSel %d\r\n", mRightSide->GetCurSel());
|
printf("GetCurSel %d\r\n", mRightSide->GetCurSel());
|
||||||
|
|
||||||
|
/*if (mRightSide->GetCurSel() < 0) {
|
||||||
|
return false;
|
||||||
|
}*/
|
||||||
ModbusMasterForm* p = mModbusMasterForm[dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText()];
|
ModbusMasterForm* p = mModbusMasterForm[dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText()];
|
||||||
if (p != nullptr) {
|
if (p != nullptr) {
|
||||||
p->SetAutoDestroy(true);
|
p->SetAutoDestroy(true);
|
||||||
@ -589,7 +593,7 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return WindowImplBase::HandleMessage(uMsg, wParam, lParam);
|
return WindowImplBase::HandleMessage(uMsg, wParam, lParam);
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
#include "modbus_form.h"
|
#include "modbus_form.h"
|
||||||
#include "lua_bind.h"
|
#include "lua_bind.h"
|
||||||
#include "msgdef.h"
|
#include "msgdef.h"
|
||||||
|
#include <item.h>
|
||||||
|
|
||||||
|
|
||||||
ModbusMasterForm::ModbusMasterForm(ui::Window* hwnd, std::wstring name,
|
ModbusMasterForm::ModbusMasterForm(ui::Window* hwnd, std::wstring name,
|
||||||
uint32_t baurate, UINT portnum,
|
uint32_t baurate, UINT portnum,
|
||||||
uint8_t data_bits, uint8_t stop_bits,
|
uint8_t data_bits, uint8_t stop_bits,
|
||||||
uint8_t verify, uint8_t flow_control) {
|
uint8_t verify, uint8_t flow_control)
|
||||||
|
:m_rich_edit_1(nullptr),
|
||||||
|
m_rich_edit_2(nullptr),
|
||||||
|
m_rich_edit_3(nullptr)
|
||||||
|
{
|
||||||
|
|
||||||
m_portnum = portnum;
|
m_portnum = portnum;
|
||||||
m_name = name;
|
m_name = name;
|
||||||
@ -34,30 +38,6 @@ ModbusMasterForm::ModbusMasterForm(ui::Window* hwnd, std::wstring name,
|
|||||||
std::cout << "lua script is " << lua_script << std::endl;
|
std::cout << "lua script is " << lua_script << std::endl;
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
m_thread_recv = new std::thread([this]() {
|
|
||||||
UINT PortNum = 0;
|
|
||||||
for (int i = 3; m_name[i] != '\0'; i++)
|
|
||||||
{
|
|
||||||
PortNum = PortNum * 10 + (m_name[i] - '0');
|
|
||||||
}
|
|
||||||
char recv[1024] = { 0 };
|
|
||||||
while (this->m_runing) {
|
|
||||||
if (0 < SerialPort::ReadPort(PortNum, recv, 1024)) {
|
|
||||||
printf("recv data: %s", recv);
|
|
||||||
this->m_show_recv += string2wstring(recv);
|
|
||||||
this->mLua->CallFuntion<std::string>("OnUartData", std::string(recv));
|
|
||||||
if (this->mEditRecv != nullptr) {
|
|
||||||
this->mEditRecv->AppendText(string2wstring(recv), false);
|
|
||||||
::PostMessage(this->GetWindow()->GetHWND(), WM_ADD_UART_RECVDATA, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Sleep(100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
if (nullptr != hwnd) {
|
if (nullptr != hwnd) {
|
||||||
// set window so we get getwindow by GetWindow funtion
|
// set window so we get getwindow by GetWindow funtion
|
||||||
this->SetWindow(hwnd, nullptr, false);
|
this->SetWindow(hwnd, nullptr, false);
|
||||||
@ -106,19 +86,58 @@ void ModbusMasterForm::Init() {
|
|||||||
ptr->tv_usec = 0;
|
ptr->tv_usec = 0;
|
||||||
modbus_set_response_timeout(mModbus, ptr);
|
modbus_set_response_timeout(mModbus, ptr);
|
||||||
uint16_t dest[32];
|
uint16_t dest[32];
|
||||||
ret = modbus_read_registers(mModbus, 0x31, 1, dest);
|
if (m_rich_edit_1) {
|
||||||
|
|
||||||
|
}
|
||||||
|
uint16_t addr = 0;
|
||||||
|
if (m_rich_edit_1) {
|
||||||
|
int i = 0;
|
||||||
|
nbase::StringToInt(m_rich_edit_1->GetText(),&i);
|
||||||
|
addr = uint16_t(i);
|
||||||
|
}
|
||||||
|
ret = modbus_read_registers(mModbus, addr, 1, dest);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
printf("read %d timeout %d ", ret);
|
printf("read %d timeout %d ", ret);
|
||||||
|
}else {
|
||||||
|
for (int i = 0; i < ret; i++) {
|
||||||
|
ui::ListContainerElement* element = new ui::ListContainerElement;
|
||||||
|
element->SetText(nbase::StringPrintf(L"µØÖ·%d: %d", addr + i,dest[i]));
|
||||||
|
element->SetClass(L"listitem");
|
||||||
|
element->SetFixedHeight(30);
|
||||||
|
element->SetFont(L"system_20");
|
||||||
|
m_list->RemoveAll();
|
||||||
|
m_list->Add(element);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string str;
|
||||||
|
|
||||||
modbus_flush(mModbus);
|
modbus_flush(mModbus);
|
||||||
modbus_close(mModbus);
|
modbus_close(mModbus);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
m_list = dynamic_cast<ui::ListBox*>(FindSubControl(L"list"));
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
ui::ListBox* list = dynamic_cast<ui::ListBox*>(FindSubControl(L"list"));
|
||||||
|
if (list != nullptr) {
|
||||||
|
for (auto i = 0; i < 30; i++)
|
||||||
|
{
|
||||||
|
std::cout << "123";
|
||||||
|
ui::ListContainerElement* element = new ui::ListContainerElement;
|
||||||
|
element->SetText(nbase::StringPrintf(L"ListElement %d", i));
|
||||||
|
element->SetClass(L"listitem");
|
||||||
|
element->SetFixedHeight(20);
|
||||||
|
list->Add(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
mEditSend = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_send_edit"));
|
mEditSend = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_send_edit"));
|
||||||
|
@ -56,6 +56,7 @@ public:
|
|||||||
ui::Button* m_button_1;
|
ui::Button* m_button_1;
|
||||||
ui::RichEdit* m_rich_edit_2;
|
ui::RichEdit* m_rich_edit_2;
|
||||||
ui::RichEdit* m_rich_edit_3;
|
ui::RichEdit* m_rich_edit_3;
|
||||||
|
ui::ListBox* m_list;
|
||||||
|
|
||||||
HWND m_hwnd;
|
HWND m_hwnd;
|
||||||
LuaDelegate* mLua;
|
LuaDelegate* mLua;
|
||||||
|
@ -274,7 +274,6 @@ void NewMonitorForm::InitWindow()
|
|||||||
}
|
}
|
||||||
this->Close();
|
this->Close();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (m_combo_type->GetText() == L"modbus salve") {
|
if (m_combo_type->GetText() == L"modbus salve") {
|
||||||
UINT PortNum = 0;
|
UINT PortNum = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user