From e911a8a799a0200056d48c5b2bc32fa51848ac8a Mon Sep 17 00:00:00 2001
From: zcy <290198252@qq.com>
Date: Mon, 27 Mar 2023 22:47:17 +0800
Subject: [PATCH] no message
---
bin/resources/themes/default/basic/basic.xml | 2 +-
.../themes/default/richlist/item.xml | 2 +-
.../themes/default/virtualbox/main.xml | 161 ++++++++++--------
examples/proto_debuger/modbus_form.cpp | 131 ++++++--------
examples/proto_debuger/proto_debuger.vcxproj | 4 +-
examples/richlist/richlist.vcxproj | 2 +-
6 files changed, 146 insertions(+), 156 deletions(-)
diff --git a/bin/resources/themes/default/basic/basic.xml b/bin/resources/themes/default/basic/basic.xml
index e035af39..0ecbb7da 100644
--- a/bin/resources/themes/default/basic/basic.xml
+++ b/bin/resources/themes/default/basic/basic.xml
@@ -12,7 +12,7 @@
-
+
diff --git a/bin/resources/themes/default/richlist/item.xml b/bin/resources/themes/default/richlist/item.xml
index bcee60d5..2fb0af60 100644
--- a/bin/resources/themes/default/richlist/item.xml
+++ b/bin/resources/themes/default/richlist/item.xml
@@ -1,5 +1,5 @@
-
+
diff --git a/bin/resources/themes/default/virtualbox/main.xml b/bin/resources/themes/default/virtualbox/main.xml
index 17170e12..92c4c28b 100644
--- a/bin/resources/themes/default/virtualbox/main.xml
+++ b/bin/resources/themes/default/virtualbox/main.xml
@@ -1,75 +1,88 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/proto_debuger/modbus_form.cpp b/examples/proto_debuger/modbus_form.cpp
index 3e6edec4..fc5c3abe 100644
--- a/examples/proto_debuger/modbus_form.cpp
+++ b/examples/proto_debuger/modbus_form.cpp
@@ -65,6 +65,7 @@ void ModbusMasterForm::Init() {
m_rich_edit_3 = dynamic_cast(FindSubControl(L"read_batch_cnt"));
auto mBtnSend = static_cast(FindSubControl(L"btn_send_modbus"));
+ auto mBtnSend2 = static_cast(FindSubControl(L"btn_send_modbus_batch"));
if (NULL != mBtnSend)
{
@@ -86,9 +87,7 @@ void ModbusMasterForm::Init() {
ptr->tv_usec = 0;
modbus_set_response_timeout(mModbus, ptr);
uint16_t dest[32];
- if (m_rich_edit_1) {
-
- }
+
uint16_t addr = 0;
if (m_rich_edit_1) {
int i = 0;
@@ -109,96 +108,72 @@ void ModbusMasterForm::Init() {
m_list->Add(element);
}
}
-
-
std::string str;
-
modbus_flush(mModbus);
modbus_close(mModbus);
}
return false;
-
});
}
-
-
m_list = dynamic_cast(FindSubControl(L"list"));
+ if (nullptr != mBtnSend2) {
+ mBtnSend2->AttachClick([this](ui::EventArgs* arg) {
+ uint16_t addr = 0;
+ uint16_t cnt = 0;
- /*
- ui::ListBox* list = dynamic_cast(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(FindSubControl(L"uart_send_edit"));
- mEditLua->SetReturnMsgWantCtrl(true);
-
- mEditLua->SetText(string2wstring(mLuaScript));
- mEditRecv->SetReadOnly(true);
- mEditRecv->SetRich(false);
- mEditRecv->SetAttribute(L"autovscroll", L"true");
- mEditRecv->SetAttribute(L"multiline", L"true");
- mEditRecv->SetReturnMsgWantCtrl(true);
- mEditRecv->SetNeedReturnMsg(true);
- mEditRecv->SetWordWrap(true);
-
- auto mBtnSend = static_cast(FindSubControl(L"btn_send_data"));
- if (mBtnSend != nullptr) {
- mBtnSend->AttachClick([this](ui::EventArgs*) {
- UINT PortNum = 0;
- for (int i = 3; m_name[i] != '\0'; i++) //תΪ
- {
- PortNum = PortNum * 10 + (m_name[i] - '0');
+ if (m_rich_edit_2) {
+ int i = 0;
+ nbase::StringToInt(m_rich_edit_2->GetText(), &i);
+ addr = uint16_t(i);
+ }
+ if (m_rich_edit_3) {
+ int i = 0;
+ nbase::StringToInt(m_rich_edit_3->GetText(), &i);
+ cnt = uint16_t(i);
}
- auto x = mEditSend->GetText();
- auto tmp = wstring2string(x);
- wprintf(L"%s\r\n", x.c_str());
- SerialPort::WritePort(PortNum, tmp.c_str(), tmp.size());
- return true;
- });
- }
- auto mBtnSaveLua = static_cast(FindSubControl(L"btn_save_lua"));
- if (nullptr != mBtnSaveLua) {
- mBtnSaveLua->AttachClick([this](ui::EventArgs*) {
- std::cout << "luaű\r\n";
- std::string lua = wstring2string(mEditLua->GetText());
- if (0 == this->mLua->UpdateScript(lua)) {
- this->mLuaScript = lua;
- mLuaFileEdit = std::ofstream(MODBUS_LUA_SCRIPT, std::ios::out | std::ios::trunc);
- mLuaFileEdit.write(lua.c_str(), lua.size());
- mLuaFileEdit.flush();
- mLuaFileEdit.close();
- }
- else {
- MessageBox(0, L"luaű", L"", 0);
- return true;
- }
- std::cout << lua.c_str() << "\r\n";
- return true;
- });
- }
+ wprintf(L"com is %s m_name", m_name.c_str());
+ printf("open ptr is %s %d %d %d ", wstring2string(m_name).c_str(), m_baurate, m_data_bits, m_stop_bits);
+ mModbus = modbus_new_rtu(wstring2string(wstring(L"\\\\.\\") + m_name).c_str(),
+ m_baurate, 'N', m_data_bits, m_stop_bits);
+
+ if (mModbus != nullptr) {
+ modbus_set_slave(mModbus, 9);
+ modbus_set_debug(mModbus, true);
+ int ret = modbus_connect(mModbus);
+ if (ret < 0) {
+ printf("modbus_connect err %d\r\n", ret);
+ }
+ timeval* ptr = new timeval;
+ ptr->tv_sec = 1;
+ ptr->tv_usec = 0;
+ modbus_set_response_timeout(mModbus, ptr);
+ uint16_t dest[32];
+
+ ret = modbus_read_registers(mModbus, addr, cnt, dest);
+ if (ret < 0) {
+ printf("read %d timeout %d ", ret);
+ }
+ else {
+ m_list->RemoveAll();
+ 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->Add(element);
+ }
+ }
+ std::string str;
+ modbus_flush(mModbus);
+ modbus_close(mModbus);
+ }
- auto mBtnClose = static_cast(FindSubControl(L"btn_close_uart"));
- if (mBtnClose != nullptr) {
- mBtnClose->AttachClick([this](ui::EventArgs*) {
- wstring* name = new wstring(this->GetName());
- ::PostMessage(this->GetWindow()->GetHWND(),
- WM_ADD_UART_CLOSE, (WPARAM)name, 0);
return true;
- });
+ });
}
- */
}
void ModbusMasterForm::UpdateRecvEdit()
diff --git a/examples/proto_debuger/proto_debuger.vcxproj b/examples/proto_debuger/proto_debuger.vcxproj
index a112b8e2..17acb360 100644
--- a/examples/proto_debuger/proto_debuger.vcxproj
+++ b/examples/proto_debuger/proto_debuger.vcxproj
@@ -81,7 +81,7 @@
true
- $(VC_IncludePath);$(WindowsSDK_IncludePath);..\..\;$(ProjectDir)third\include\libevent\include;$(ProjectDir);$(ProjectDir)third\include\lua;$(ProjectDir)third\include\;D:\include
+ $(VC_IncludePath);$(WindowsSDK_IncludePath);..\..\;$(ProjectDir)third\include\libevent\include;$(ProjectDir);$(ProjectDir)third\include\lua;$(ProjectDir)third\include\;D:\include;D:\project\c++\nim_duilib\examples\proto_debuger\third\include
$(ReferencePath)
$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(ProjectDir)third\lib
@@ -168,6 +168,7 @@
+
@@ -193,6 +194,7 @@
+
diff --git a/examples/richlist/richlist.vcxproj b/examples/richlist/richlist.vcxproj
index 74e4d66b..2dbdb722 100644
--- a/examples/richlist/richlist.vcxproj
+++ b/examples/richlist/richlist.vcxproj
@@ -42,7 +42,7 @@
Application
true
- v120_xp
+ v142
Unicode