no message
This commit is contained in:
parent
17cff75119
commit
e0afe13a45
@ -4,7 +4,8 @@
|
|||||||
const std::wstring BasicForm::kClassName = L"Basic";
|
const std::wstring BasicForm::kClassName = L"Basic";
|
||||||
|
|
||||||
BasicForm::BasicForm():
|
BasicForm::BasicForm():
|
||||||
mMonitorNewSelect(nullptr)
|
mMonitorNewSelect(nullptr),
|
||||||
|
mRightShow(nullptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -31,12 +32,34 @@ std::wstring BasicForm::GetWindowClassName() const
|
|||||||
|
|
||||||
LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
|
if (uMsg == WM_ADD_UART_CLOSE) {
|
||||||
|
wprintf(L"close %s\r\n", ((wstring*)wParam)->c_str());
|
||||||
|
mRightShow->SetVisible(false);
|
||||||
|
mRightSide->SetAutoDestroy(true);
|
||||||
|
mUartForm[*(wstring*)(wParam)] = nullptr;
|
||||||
|
int cnt = mMonitor->GetRootNode()->GetChildNode(0)->GetChildNodeCount();
|
||||||
|
ui::TreeNode* p = nullptr;
|
||||||
|
for (int i = 0; i < cnt; i++) {
|
||||||
|
if (mMonitor->GetRootNode()->GetChildNode(0)->GetChildNode(i)->GetText() == *(wstring*)(wParam)) {
|
||||||
|
p = mMonitor->GetRootNode()->GetChildNode(0)->GetChildNode(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto comname = *(wstring*)(wParam);
|
||||||
|
|
||||||
|
mMonitor->GetRootNode()->GetChildNode(0)->RemoveChildNode(p);
|
||||||
|
|
||||||
|
UINT PortNum = 0;
|
||||||
|
for (int i = 3; comname[i] != L'\0'; i++) //ת»»ÎªÊý×Ö
|
||||||
|
{
|
||||||
|
PortNum = PortNum * 10 + (comname[i] - L'0');
|
||||||
|
}
|
||||||
|
SerialPort::ClosePort(PortNum);
|
||||||
|
}
|
||||||
if (uMsg == WM_ADD_UART_RECVDATA) {
|
if (uMsg == WM_ADD_UART_RECVDATA) {
|
||||||
printf("WM_ADD_UART_RECVDATA");
|
printf("WM_ADD_UART_RECVDATA");
|
||||||
this->Paint();
|
//this->Paint();
|
||||||
for (auto itr = mUartForm.begin(); itr != mUartForm.end(); itr++) {
|
|
||||||
itr->second->OnUpdateUart();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (uMsg == WM_USER_POS_CHANGED) {
|
if (uMsg == WM_USER_POS_CHANGED) {
|
||||||
|
|
||||||
@ -57,17 +80,32 @@ LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
auto form = new UartForm(this,p->name, p->baurate,
|
auto form = new UartForm(this,p->name, p->baurate,
|
||||||
p->data_bits, p->stop_bits, p->verify, p->flow_control);
|
p->data_bits, p->stop_bits, p->verify, p->flow_control);
|
||||||
form->SetChildLayoutXML(L"basic/uart_form.xml");
|
form->SetChildLayoutXML(L"basic/uart_form.xml");
|
||||||
|
form->SetName(p->name);
|
||||||
form->SetVisible(false);
|
form->SetVisible(false);
|
||||||
mUartForm[p->name] = form;
|
mUartForm[p->name] = form;
|
||||||
|
if (!mRightSide->Add(form))
|
||||||
|
printf("erroer 1");
|
||||||
}
|
}
|
||||||
node->AttachAllEvents([this](ui::EventArgs* ev){
|
node->AttachAllEvents([this](ui::EventArgs* ev){
|
||||||
if (ui::EventType::kEventSelect == ev->Type) {
|
if (ui::EventType::kEventSelect == ev->Type) {
|
||||||
mRightSide->RemoveAll();
|
|
||||||
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());
|
||||||
UartForm* p = mUartForm[dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText()];
|
UartForm* p = mUartForm[dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText()];
|
||||||
if (nullptr != p) {
|
if (p != nullptr) {
|
||||||
p->SetVisible(true);
|
p->SetAutoDestroy(true);
|
||||||
mRightSide->Add(mUartForm[dynamic_cast<ui::TreeNode*> (ev->pSender)->GetText()]);
|
if (mRightShow != nullptr) {
|
||||||
|
mRightShow->SetVisible(false);
|
||||||
|
p->SetVisible(true);
|
||||||
|
mRightShow = p;
|
||||||
|
mRightSide->SelectItem(p->GetName());
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
p->SetVisible(true);
|
||||||
|
|
||||||
|
mRightSide->SelectItem(p->GetName());
|
||||||
|
mRightShow = p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -55,5 +55,5 @@ private:
|
|||||||
ui::TabBox *mRightSide;
|
ui::TabBox *mRightSide;
|
||||||
ui::TreeView *mMonitor;
|
ui::TreeView *mMonitor;
|
||||||
std::map<std::wstring,UartForm*> mUartForm;
|
std::map<std::wstring,UartForm*> mUartForm;
|
||||||
|
ui::Control* mRightShow;
|
||||||
};
|
};
|
||||||
|
@ -144,14 +144,8 @@ int SerialPort::InitPort(UINT PortNo, UINT Baud, byte Parity, byte Data, byte St
|
|||||||
|
|
||||||
|
|
||||||
//int count = 0;
|
//int count = 0;
|
||||||
COMMTIMEOUTS ComTimeouts = { 10, 0, 0, 0, 0 };
|
COMMTIMEOUTS ComTimeouts = { 0, 0, 10, 0, 10 };
|
||||||
/*
|
|
||||||
ComTimeouts.ReadIntervalTimeout = 0;
|
|
||||||
ComTimeouts.ReadTotalTimeoutConstant = 0;
|
|
||||||
ComTimeouts.ReadTotalTimeoutMultiplier = 0;
|
|
||||||
ComTimeouts.WriteTotalTimeoutConstant = 0;
|
|
||||||
ComTimeouts.WriteTotalTimeoutMultiplier = 0;
|
|
||||||
*/
|
|
||||||
DCB S_dcb;
|
DCB S_dcb;
|
||||||
if (!SetCommTimeouts(H_Com, &ComTimeouts))//设置超时
|
if (!SetCommTimeouts(H_Com, &ComTimeouts))//设置超时
|
||||||
{
|
{
|
||||||
@ -174,7 +168,7 @@ int SerialPort::InitPort(UINT PortNo, UINT Baud, byte Parity, byte Data, byte St
|
|||||||
// return 0;
|
// return 0;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
S_dcb.fRtsControl = RTS_CONTROL_ENABLE; //允许Rts信号
|
S_dcb.fRtsControl = RTS_CONTROL_DISABLE; //允许Rts信号
|
||||||
if (!SetCommState(H_Com, &S_dcb)) //设置DCB
|
if (!SetCommState(H_Com, &S_dcb)) //设置DCB
|
||||||
{
|
{
|
||||||
int i = GetLastError();
|
int i = GetLastError();
|
||||||
@ -211,7 +205,6 @@ int SerialPort::ReadPort(UINT PortNo, char* P_recved, int length) //
|
|||||||
BOOL Result = TRUE;
|
BOOL Result = TRUE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Result = ReadFile(H_Com, P_recved, length, &Recn, NULL);
|
Result = ReadFile(H_Com, P_recved, length, &Recn, NULL);
|
||||||
if (Result == 0)
|
if (Result == 0)
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define WM_ADD_UART_RECVDATA (WM_USER + 4)
|
#define WM_ADD_UART_RECVDATA (WM_USER + 4)
|
||||||
|
#define WM_ADD_UART_CLOSE (WM_USER + 5)
|
||||||
|
|
||||||
typedef struct{
|
typedef struct{
|
||||||
wstring name;
|
wstring name;
|
||||||
|
@ -56,10 +56,13 @@ UartForm::UartForm(ui::Window* hwnd,std::wstring name,
|
|||||||
if (0 < SerialPort::ReadPort(PortNum, recv, 1024)) {
|
if (0 < SerialPort::ReadPort(PortNum, recv, 1024)) {
|
||||||
printf("recv data: %s", recv);
|
printf("recv data: %s", recv);
|
||||||
this->m_show_recv += string2wstring(recv);
|
this->m_show_recv += string2wstring(recv);
|
||||||
::PostMessage(this->GetWindow()->GetHWND(), WM_ADD_UART_RECVDATA, 0, 0);
|
if (this->mEditRecv != nullptr) {
|
||||||
|
this->mEditRecv->AppendText(string2wstring(recv), false);
|
||||||
|
::PostMessage(this->GetWindow()->GetHWND(), WM_ADD_UART_RECVDATA,0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Sleep(30);
|
Sleep(300);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -70,17 +73,14 @@ UartForm::UartForm(ui::Window* hwnd,std::wstring name,
|
|||||||
|
|
||||||
void UartForm::OnUpdateUart()
|
void UartForm::OnUpdateUart()
|
||||||
{
|
{
|
||||||
if(mEditRecv != nullptr)
|
//if(mEditRecv != nullptr)
|
||||||
this->mEditRecv->SetText(this->m_show_recv.c_str());
|
// this->mEditRecv->SetText(this->m_show_recv );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void UartForm::Init()
|
void UartForm::Init()
|
||||||
{
|
{
|
||||||
ui::ChildBox::Init();
|
ui::ChildBox::Init();
|
||||||
|
|
||||||
auto mRightSide = dynamic_cast<ui::Label*> (FindSubControl(L"uart_info_label"));
|
auto mRightSide = dynamic_cast<ui::Label*> (FindSubControl(L"uart_info_label"));
|
||||||
wchar_t p[100] = { 0 };
|
wchar_t p[100] = { 0 };
|
||||||
wsprintf(p,L"串口号: %s 波特率%d 数据位: %d 停止位: %d ",
|
wsprintf(p,L"串口号: %s 波特率%d 数据位: %d 停止位: %d ",
|
||||||
@ -91,6 +91,13 @@ void UartForm::Init()
|
|||||||
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 = dynamic_cast<ui::RichEdit*>(FindSubControl(L"uart_recv_eidt"));
|
||||||
mEditRecv->SetReadOnly(true);
|
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<ui::Button*>(FindSubControl(L"btn_send_data"));
|
auto mBtnSend = static_cast<ui::Button*>(FindSubControl(L"btn_send_data"));
|
||||||
if (mBtnSend != nullptr) {
|
if (mBtnSend != nullptr) {
|
||||||
mBtnSend->AttachClick([this](ui::EventArgs*) {
|
mBtnSend->AttachClick([this](ui::EventArgs*) {
|
||||||
@ -107,6 +114,17 @@ void UartForm::Init()
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
auto mBtnClose = static_cast<ui::Button*>(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 UartForm::UpdateRecvEdit()
|
void UartForm::UpdateRecvEdit()
|
||||||
@ -116,11 +134,10 @@ void UartForm::UpdateRecvEdit()
|
|||||||
|
|
||||||
void UartForm::HandleMessage(ui::EventArgs& msg)
|
void UartForm::HandleMessage(ui::EventArgs& msg)
|
||||||
{
|
{
|
||||||
printf("0x%x \r\n", msg.Type);
|
|
||||||
if (msg.Type == WM_ADD_UART_RECVDATA) {
|
if (msg.Type == WM_ADD_UART_RECVDATA) {
|
||||||
printf("hello world\r\n");
|
printf("hello world\r\n");
|
||||||
this->mEditRecv->SetText(L"123");
|
this->mEditRecv->SetText(L"123");
|
||||||
}
|
}
|
||||||
this->mEditRecv->SetText(this->m_show_recv.c_str());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user