no message
This commit is contained in:
parent
c4a1a02db5
commit
fef52d423f
@ -47,7 +47,7 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
mMonitor->GetRootNode()->GetChildNode(0)->AddChildNode(node);
|
||||
|
||||
if (mUartForm.find(p->name) == mUartForm.end()) {
|
||||
auto form = new UartForm(p->name, p->baurate,
|
||||
auto form = new UartForm(this->m_hWnd,p->name, p->baurate,
|
||||
p->data_bits, p->stop_bits, p->verify, p->flow_control);
|
||||
form->SetChildLayoutXML(L"basic/uart_form.xml");
|
||||
form->SetVisible(false);
|
||||
|
@ -52,7 +52,6 @@ void MainThread::Init()
|
||||
ui::GlobalManager::Startup(L"resources\\", ui::CreateControlCallback(), false);
|
||||
#endif
|
||||
|
||||
|
||||
auto dpiManager = ui::DpiManager::GetInstance();
|
||||
// 创建一个默认带有阴影的居中窗口
|
||||
BasicForm* window = new BasicForm();
|
||||
|
@ -1,22 +1,24 @@
|
||||
#include "uart_process.h"
|
||||
|
||||
|
||||
UartForm::UartForm(std::wstring name,
|
||||
uint32_t baurate,
|
||||
uint8_t data_bits, uint8_t stop_bits,
|
||||
uint8_t verify, uint8_t flow_control)
|
||||
{
|
||||
m_name = name;
|
||||
m_baurate = baurate;
|
||||
m_data_bits = data_bits;
|
||||
m_stop_bits = stop_bits;
|
||||
m_verify = verify;
|
||||
m_flow_contro = flow_control;
|
||||
#define WM_ADD_UART_RECVDATA (WM_USER + 4)
|
||||
|
||||
wstring string2wstring(string str)
|
||||
{
|
||||
wstring result;
|
||||
//获取缓冲区大小,并申请空间,缓冲区大小按字符计算
|
||||
int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), NULL, 0);
|
||||
TCHAR* buffer = new TCHAR[len + 1];
|
||||
//多字节编码转换成宽字节编码
|
||||
MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), buffer, len);
|
||||
buffer[len] = '\0'; //添加字符串结尾
|
||||
//删除缓冲区并返回值
|
||||
result.append(buffer);
|
||||
delete[] buffer;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std:: string wstring2string(std::wstring wstr)
|
||||
std::string wstring2string(std::wstring wstr)
|
||||
{
|
||||
std::string result;
|
||||
//获取缓冲区大小,并申请空间,缓冲区大小事按字节计算的
|
||||
@ -31,6 +33,45 @@ std:: string wstring2string(std::wstring wstr)
|
||||
return result;
|
||||
}
|
||||
|
||||
UartForm::UartForm(HWND hwnd,std::wstring name,
|
||||
uint32_t baurate,
|
||||
uint8_t data_bits, uint8_t stop_bits,
|
||||
uint8_t verify, uint8_t flow_control):
|
||||
m_thread_recv(nullptr)
|
||||
{
|
||||
m_hwnd = hwnd;
|
||||
m_name = name;
|
||||
m_baurate = baurate;
|
||||
m_data_bits = data_bits;
|
||||
m_stop_bits = stop_bits;
|
||||
m_verify = verify;
|
||||
m_flow_contro = flow_control;
|
||||
|
||||
m_runing = true;
|
||||
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 += wstring(L"123");
|
||||
this->UpdateRecvEdit();
|
||||
::PostMessage(m_hwnd, WM_ADD_UART_RECVDATA, 0, 0);
|
||||
this->Invalidate();
|
||||
}
|
||||
else {
|
||||
Sleep(30);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
void UartForm::Init()
|
||||
{
|
||||
ui::ChildBox::Init();
|
||||
@ -42,11 +83,12 @@ void UartForm::Init()
|
||||
m_data_bits,m_stop_bits);
|
||||
mRightSide->SetText(std::wstring(p));
|
||||
|
||||
auto mEditSend = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_send_edit"));
|
||||
mEditSend = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_send_edit"));
|
||||
mEditRecv = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_recv_eidt"));
|
||||
mEditRecv->SetReadOnly(true);
|
||||
auto mBtnSend = static_cast<ui::Button*>(FindSubControl(L"btn_send_data"));
|
||||
if (mBtnSend != nullptr) {
|
||||
mBtnSend->AttachClick([this, mEditSend](ui::EventArgs*) {
|
||||
|
||||
mBtnSend->AttachClick([this](ui::EventArgs*) {
|
||||
UINT PortNum = 0;
|
||||
for (int i = 3; m_name[i] != '\0'; i++) //转换为数字
|
||||
{
|
||||
@ -56,10 +98,24 @@ void UartForm::Init()
|
||||
auto x = mEditSend->GetText();
|
||||
auto tmp = wstring2string(x);
|
||||
wprintf(L"%s\r\n", x.c_str());
|
||||
printf("%s\r\n", tmp.c_str());
|
||||
SerialPort::WritePort(PortNum, tmp.c_str(), tmp.size());
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void UartForm::UpdateRecvEdit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UartForm::HandleMessage(ui::EventArgs& msg)
|
||||
{
|
||||
printf("0x%x \r\n", msg.Type);
|
||||
if (msg.Type == WM_ADD_UART_RECVDATA) {
|
||||
printf("hello world\r\n");
|
||||
this->mEditRecv->SetText(L"123");
|
||||
}
|
||||
this->mEditRecv->SetText(this->m_show_recv.c_str());
|
||||
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
class UartForm : public ui::ChildBox
|
||||
{
|
||||
public:
|
||||
UartForm(std::wstring name, uint32_t baurate,
|
||||
UartForm(HWND hwnd,std::wstring name, uint32_t baurate,
|
||||
uint8_t data_bits,
|
||||
uint8_t stop_bits,
|
||||
uint8_t verify,
|
||||
@ -26,11 +26,22 @@ public:
|
||||
/// 重写父类方法,提供个性化功能,请参考父类声明
|
||||
virtual void Init() override;
|
||||
|
||||
void UpdateRecvEdit();
|
||||
std::wstring m_name;
|
||||
uint32_t m_baurate;
|
||||
uint8_t m_data_bits;
|
||||
uint8_t m_stop_bits;
|
||||
uint8_t m_verify;
|
||||
uint8_t m_flow_contro;
|
||||
bool m_runing;
|
||||
std::thread * m_thread_recv;
|
||||
wstring m_show_recv;
|
||||
|
||||
ui::RichEdit* mEditSend;
|
||||
ui::RichEdit* mEditRecv;
|
||||
HWND m_hwnd;
|
||||
private:
|
||||
virtual void HandleMessage(ui::EventArgs& msg);
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user