// mdi_1View.cpp : implementation of the Cmdi_1View class
//
#include "stdafx.h"
#include "mdi_1.h"
#include "mdi_1Doc.h"
#include "mdi_1View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Cmdi_1View
IMPLEMENT_DYNCREATE(Cmdi_1View, CView)
BEGIN_MESSAGE_MAP(Cmdi_1View, CView)
ON_WM_CREATE()
ON_BN_CLICKED(50002, &Cmdi_1View::OnOpen)
ON_BN_CLICKED(50003, &Cmdi_1View::OnClose)
ON_BN_CLICKED(50004, &Cmdi_1View::OnPutch)
ON_BN_CLICKED(50005, &Cmdi_1View::OnPattern)
ON_BN_CLICKED(50006, &Cmdi_1View::OnStop)
ON_BN_CLICKED(50007, &Cmdi_1View::OnClear)
END_MESSAGE_MAP()
// Cmdi_1View construction/destruction
Cmdi_1View::Cmdi_1View()
{
// TODO: add construction code here
port.com_num = 0;
port.data_rx = 0x00;
port.data_tx = '0';
port.rx_thd = NULL;
port.tx_thd = NULL;
}
Cmdi_1View::~Cmdi_1View()
{
if (port.com_num != 0)
{
scom_close(port.com_num);
}
if (port.rx_thd != NULL)
{
if (port.rx_thd->m_hThread != NULL)
{
TerminateThread(port.rx_thd->m_hThread, 0);
}
}
if (port.tx_thd != NULL)
{
if (port.tx_thd->m_hThread != NULL)
{
TerminateThread(port.tx_thd->m_hThread, 0);
}
}
}
BOOL Cmdi_1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
// Cmdi_1View drawing
void Cmdi_1View::OnDraw(CDC* /*pDC*/)
{
Cmdi_1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: add draw code for native data here
}
// Cmdi_1View diagnostics
#ifdef _DEBUG
void Cmdi_1View::AssertValid() const
{
CView::AssertValid();
}
void Cmdi_1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
Cmdi_1Doc* Cmdi_1View::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(Cmdi_1Doc)));
return (Cmdi_1Doc*)m_pDocument;
}
#endif //_DEBUG
// Cmdi_1View message handlers
UINT Cmdi_1View::rx_thd(LPVOID lparam)
{
Cmdi_1View* pchld_view = (Cmdi_1View *)lparam;
SNXCOM* pport = (SNXCOM *)&pchld_view->port;
CEdit* pedit = (CEdit *)&pchld_view->m_receive;
// int ret;
CString str1;
CString str2;
char data[50];
int len;
while (1)
{
memset(&data[0], 0x00, sizeof(char) * 50);
len = scom_read(pport->com_num, &data[0], 40);
if (len > 0)
{
//TRACE2("data:%S, len:%d\n", data, len);
if (pedit->GetWindowTextLength() >= 270)
{
pedit->SetWindowText(_T(""));
str2.Format(_T("%S"), data);
}
else
{
pedit->GetWindowText(str1);
str2.Format(_T("%s%S"), str1, data);
}
pedit->SetWindowText(str2);
}
/*
ret = scom_getch(pport->com_num, &pport->data_rx);
if (ret == SCOM_OK)
{
//TRACE2("data:%c, len:%d\n", pport->data_rx, pedit->GetWindowTextLength());
if (pedit->GetWindowTextLength() >= 270)
{
pedit->SetWindowText(_T(""));
str2.Format(_T("%c"), pport->data_rx);
}
else
{
pedit->GetWindowText(str1);
str2.Format(_T("%s%c"), str1, pport->data_rx);
}
pedit->SetWindowText(str2);
}
*/
}
return 0;
}
UINT Cmdi_1View::tx_thd(LPVOID lparam)
{
Cmdi_1View* pchld_view = (Cmdi_1View *)lparam;
SNXCOM* pport = (SNXCOM *)&pchld_view->port;
int ret;
pport->data_tx = '0';
while (1)
{
ret = scom_putch(pport->com_num, pport->data_tx);
pport->data_tx++;
if (pport->data_tx > '9')
{
pport->data_tx = '0';
}
}
return 0;
}
int Cmdi_1View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_comnum.Create(WS_CHILD | WS_VISIBLE | WS_BORDER, CRect(10, 5, 70, 25), this, 50001);
m_open.Create(_T("open"), WS_CHILD | WS_VISIBLE, CRect(10, 30, 70, 50), this, 50002);
m_close.Create(_T("close"), WS_CHILD | WS_VISIBLE, CRect(10, 55, 70, 75), this, 50003);
m_transfer.Create(_T("putch"), WS_CHILD | WS_VISIBLE, CRect(10, 80, 70, 100), this, 50004);
m_pattern.Create(_T("pattern"), WS_CHILD | WS_VISIBLE, CRect(10, 105, 70, 125), this, 50005);
m_stop.Create(_T("stop"), WS_CHILD | WS_VISIBLE, CRect(10, 130, 70, 150), this, 50006);
m_clear.Create(_T("clear"), WS_CHILD | WS_VISIBLE, CRect(10, 155, 70, 175), this, 50007);
m_receive.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE, CRect(80, 10, 330, 165), this, 50000);
m_comnum.SetWindowText(_T("0"));
m_close.EnableWindow(FALSE);
m_transfer.EnableWindow(FALSE);
m_pattern.EnableWindow(FALSE);
m_stop.EnableWindow(FALSE);
m_clear.EnableWindow(FALSE);
m_receive.EnableWindow(FALSE);
return 0;
}
void Cmdi_1View::OnOpen(void)
{
int ret;
int com_len = 0;
CString str;
com_len = m_comnum.LineLength(-1);
if (com_len <= 0)
{
::AfxMessageBox(_T("com num invalid"), MB_OK | MB_ICONSTOP, 0);
return;
}
m_comnum.GetWindowTextW(str);
port.com_num = _ttoi(str.GetBuffer(0));
if ((port.com_num <= 0) || (port.com_num > 255))
{
::AfxMessageBox(_T("com num invalid"), MB_OK | MB_ICONSTOP, 0);
return;
}
ret = scom_open(port.com_num);
if (ret != SCOM_OK)
{
::AfxMessageBox(_T("open failed"), MB_OK | MB_ICONSTOP, 0);
return;
}
ret = scom_flush(port.com_num, 2);
if (ret != SCOM_OK)
{
::AfxMessageBox(_T("flush failed"), MB_OK | MB_ICONSTOP, 0);
return;
}
ret = scom_set_flowctrl(port.com_num, F_RTSCTS);
if (ret != SCOM_OK)
{
::AfxMessageBox(_T("set flowctrl failed"), MB_OK | MB_ICONSTOP, 0);
return;
}
/*
ret = scom_add_rx_count_isr(port.com_num, &Cmdi_1View::rx_callback, 1);
if (ret != SCOM_OK)
{
::AfxMessageBox(_T("reg rx isr failed"), MB_OK | MB_ICONSTOP, 0);
return;
}
*/
m_receive.SetWindowTextW(_T(""));
port.rx_thd = AfxBeginThread(rx_thd, (LPVOID)this);
if (port.rx_thd == NULL)
{
scom_close(port.com_num);
::AfxMessageBox(_T("rx thread failed"), MB_OK | MB_ICONSTOP, 0);
return;
}
port.tx_thd = AfxBeginThread(tx_thd, (LPVOID)this);
if (port.tx_thd == NULL)
{
scom_close(port.com_num);
::AfxMessageBox(_T("tx thread failed"), MB_OK | MB_ICONSTOP, 0);
return;
}
port.tx_thd->SuspendThread();
port.data_tx = '0';
m_comnum.EnableWindow(FALSE);
m_open.EnableWindow(FALSE);
m_close.EnableWindow(TRUE);
m_transfer.EnableWindow(TRUE);
m_pattern.EnableWindow(TRUE);
m_stop.EnableWindow(FALSE);
m_clear.EnableWindow(TRUE);
m_receive.EnableWindow(TRUE);
}
void Cmdi_1View::OnClose(void)
{
int ret;
if (port.rx_thd != NULL)
{
if (port.rx_thd->m_hThread != NULL)
{
TerminateThread(port.rx_thd->m_hThread, 0);
}
}
port.rx_thd = NULL;
if (port.tx_thd != NULL)
{
if (port.tx_thd->m_hThread != NULL)
{
TerminateThread(port.tx_thd->m_hThread, 0);
}
}
port.tx_thd = NULL;
ret = scom_close(port.com_num);
if (ret != SCOM_OK)
{
::AfxMessageBox(_T("close failed"), MB_OK | MB_ICONSTOP, 0);
return;
}
port.com_num = 0;
m_receive.SetWindowTextW(_T(""));
m_comnum.EnableWindow(TRUE);
m_open.EnableWindow(TRUE);
m_close.EnableWindow(FALSE);
m_transfer.EnableWindow(FALSE);
m_pattern.EnableWindow(FALSE);
m_stop.EnableWindow(FALSE);
m_clear.EnableWindow(FALSE);
m_receive.EnableWindow(FALSE);
}
void Cmdi_1View::OnPutch(void)
{
int ret;
ret = scom_putch(port.com_num, port.data_tx);
if (ret != SCOM_OK)
{
::AfxMessageBox(_T("putch fail"), MB_OK | MB_ICONSTOP, 0);
return;
}
port.data_tx++;
if (port.data_tx > '9')
{
port.data_tx = '0';
}
}
void Cmdi_1View::OnPattern(void)
{
port.tx_thd->ResumeThread();
m_comnum.EnableWindow(FALSE);
m_open.EnableWindow(FALSE);
m_close.EnableWindow(FALSE);
m_transfer.EnableWindow(FALSE);
m_pattern.EnableWindow(FALSE);
m_stop.EnableWindow(TRUE);
m_clear.Enable
mdi_1.rar_open
版权申诉
89 浏览量
2022-09-22
22:15:49
上传
评论
收藏 53KB RAR 举报
刘良运
- 粉丝: 66
- 资源: 1万+
最新资源
- 基于tensorflow多特征融合的微表情识别python源码.zip
- 基于yolov8实现人脸检测的python源码+运行说明.zip
- Micron Memory DDR3 SDRAM 全系列AD集成库(原理图库+PCB封装库).IntLib
- 基于tensorflow多特征融合的微表情识别python源码+详细使用说明.zip
- TensorRT部署DETR项目工程C++源码.zip
- Word文字处理软件练习题及答案.doc
- Word普通信纸信纸格式可打印.doc
- TensorRT部署DETR项目工程python源码.zip
- WPSexcel如何做柏拉图.doc
- 基于protel99se设计的PCB封装库PROTEL PCB封装库器件库常用芯片接插件电子元器件封装(1260个).lib
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈