a
This commit is contained in:
@@ -0,0 +1,841 @@
|
||||
// D:\zm\GeomativeV2.5logging\cpp\logging\CDialogLoggingTestMainWnd.cpp : 实现文件
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "GeoMative.h"
|
||||
#include "logging\CDialogLoggingTestMainWnd.h"
|
||||
#include "logging\CDialogLoggingWnd.h"
|
||||
#include "logging\CDialogLoggingCreateTaskWnd.h"
|
||||
#include "logging\CDialogLoggingSelectComPortWnd.h"
|
||||
#include "logging\CDialogLoggingParameterSetting.h"
|
||||
//#include "afxdialogex.h"
|
||||
|
||||
extern CRITICAL_SECTION g_ScanTabSection;
|
||||
extern BYTE BBCCalculate(const char *pData, int iSize, BYTE ucOrgRes);
|
||||
// CDialogLoggingTestMainWnd 对话框
|
||||
|
||||
IMPLEMENT_DYNAMIC(CDialogLoggingTestMainWnd, CDialog)
|
||||
extern void SplitterString(CStringArray &szArray, const CString& szSource, const CString& szSplitter);
|
||||
CDialogLoggingTestMainWnd::CDialogLoggingTestMainWnd(CWnd* pParent /*=NULL*/)
|
||||
: CDialog(CDialogLoggingTestMainWnd::IDD, pParent)
|
||||
{
|
||||
m_iSeriNo = 1;
|
||||
m_bIsOpenFile = FALSE;
|
||||
m_isDownloadParamSetting = FALSE;
|
||||
m_isRecvData = FALSE;
|
||||
}
|
||||
|
||||
CDialogLoggingTestMainWnd::~CDialogLoggingTestMainWnd()
|
||||
{
|
||||
m_bIsOpenFile = FALSE;
|
||||
}
|
||||
|
||||
void CDialogLoggingTestMainWnd::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CDialogLoggingTestMainWnd, CDialog)
|
||||
ON_WM_PAINT()
|
||||
ON_COMMAND(IDM_MENU_FILE_OPEN, OnMenuFileOpen)
|
||||
ON_COMMAND(IDM_MENU_FILE_CLOSE, OnMenuFileClose)
|
||||
ON_COMMAND(IDM_MENU_FILE_SAVE, OnMenuFileSave)
|
||||
ON_COMMAND(IDM_MENU_FILE_SAVE_AS, OnMenuFileSaveAs)
|
||||
ON_COMMAND(IDM_MENU_EXIT, OnMenuExit)
|
||||
ON_COMMAND(IDM_MENU_COM_SETTING, OnMenuComSetting)
|
||||
ON_COMMAND(IDM_MENU_CREATE_TASK, OnMenuCreateTask)
|
||||
ON_COMMAND(IDM_MENU_MEASURE_PARAM_SETTING, OnMenuMeasureParamSetting)
|
||||
ON_COMMAND(IDM_MENU_START_LOGGING, OnMenuStartLogging)
|
||||
ON_COMMAND(IDM_MENU_PAUSE_LOGGING, OnMenuPauseLogging)
|
||||
ON_COMMAND(IDM_MENU_CONTINUE_LOGGING, OnMenuContinueLogging)
|
||||
ON_COMMAND(IDM_MENU_END_LOGGING, OnMenuEndLogging)
|
||||
ON_WM_VSCROLL()
|
||||
ON_WM_DESTROY()
|
||||
ON_WM_MOUSEWHEEL()
|
||||
ON_MESSAGE(WM_MSG_LOGGING_MEASURING_POINT_DATA, &CDialogLoggingTestMainWnd::OnMsgLoggingMeasuringPointData)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
// CDialogLoggingTestMainWnd 消息处理程序
|
||||
BOOL CDialogLoggingTestMainWnd::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
m_Menu.LoadMenuA(IDR_MENU_LOGGING_TEST);
|
||||
SetMenu(&m_Menu);
|
||||
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
SetWindowText(_T("Logging测试"));
|
||||
}
|
||||
|
||||
RECT rcWnd;
|
||||
rcWnd.left = rcWnd.top = 0;
|
||||
rcWnd.right = GetSystemMetrics(SM_CXSCREEN);
|
||||
rcWnd.bottom = GetSystemMetrics(SM_CYSCREEN);
|
||||
MoveWindow(&rcWnd, TRUE);
|
||||
GetClientRect(&m_rcClientWnd);
|
||||
GetDlgItem(IDC_STATIC_DRAW_BORADING)->MoveWindow(&m_rcClientWnd);
|
||||
CDialogLoggingWnd::GetInstance()->Create(IDD_DIALOG_LOGGING_WND, GetDlgItem(IDC_STATIC_DRAW_BORADING));
|
||||
CDialogLoggingWnd::GetInstance()->MoveWindow(&m_rcClientWnd);
|
||||
CDialogLoggingWnd::GetInstance()->SetColumnNameVisible(FALSE);
|
||||
CDialogLoggingWnd::GetInstance()->ShowWindow(TRUE);
|
||||
|
||||
//不需要滚动条
|
||||
SetScrollRange(SB_VERT, 0, 0, TRUE);
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// 异常: OCX 属性页应返回 FALSE
|
||||
}
|
||||
|
||||
void CDialogLoggingTestMainWnd::OnPaint()
|
||||
{
|
||||
CPaintDC dc(this); // device context for painting
|
||||
// TODO: 在此处添加消息处理程序代码
|
||||
// 不为绘图消息调用 CDialogEx::OnPaint()
|
||||
CRect rcWnd;
|
||||
GetClientRect(&rcWnd);
|
||||
dc.FillSolidRect(rcWnd, RGB(255, 255, 255));
|
||||
}
|
||||
|
||||
void CDialogLoggingTestMainWnd::OnMenuFileOpen()
|
||||
{
|
||||
// TODO: Add your command handler code here
|
||||
if (m_bIsOpenFile)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("已经存在打开的文件"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("An open file already exists"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
float fWellDepth = 0;
|
||||
CFileDialog cfd(TRUE, _T(".xml"), _T("*.xml"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("xml Files(*.xml)|*.txt||"), NULL);
|
||||
if (IDOK == cfd.DoModal())
|
||||
{
|
||||
m_bIsOpenFile = TRUE;
|
||||
CString strFileName = cfd.GetPathName();
|
||||
if (strFileName.IsEmpty())
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("无效文件名"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Invalid file name"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
//初始化画布大小
|
||||
CMarkup makeUp;
|
||||
bool bRes = makeUp.Load(strFileName);
|
||||
if (!bRes)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("解析xml文件失败"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Failed to parse the XML file"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
|
||||
float fWellInitDepth, fWellEndDepth;
|
||||
makeUp.FindElem(_T("measure"));
|
||||
|
||||
makeUp.FindChildElem(_T("initial_depth"));
|
||||
fWellInitDepth = atof(makeUp.GetChildData());
|
||||
makeUp.FindChildElem(_T("WellEndDepth"));
|
||||
fWellEndDepth = atof(makeUp.GetChildData());
|
||||
|
||||
//修改绘制矩形框的高度
|
||||
float fWellDepth = fWellEndDepth - fWellInitDepth;
|
||||
if (fWellDepth > 0)
|
||||
{
|
||||
RECT rcDraw;
|
||||
rcDraw = m_rcClientWnd;
|
||||
rcDraw.bottom = CDialogLoggingWnd::GetInstance()->GetStartDrawDataHeight() + fWellDepth*DEPTH_SCALE_DISTANCE*EACH_SCALE_PIXEL_POINT_VALUE*ONE_DECIMETER_TO_HEIGHT;
|
||||
GetDlgItem(IDC_STATIC_DRAW_BORADING)->MoveWindow(&rcDraw);
|
||||
|
||||
SCROLLINFO si;
|
||||
si.cbSize = sizeof(SCROLLINFO);
|
||||
si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
|
||||
si.nPos = 0;
|
||||
si.nMin = 0;
|
||||
float fSub = (CDialogLoggingWnd::GetInstance()->GetStartDrawDataHeight() + fWellDepth*DEPTH_SCALE_DISTANCE*ONE_DECIMETER_TO_HEIGHT) / (m_rcClientWnd.bottom - m_rcClientWnd.top);
|
||||
si.nMax = (m_rcClientWnd.bottom - m_rcClientWnd.top)*fSub+DRAW_BOARDING_TO_BOTTOM_DISTANCE;
|
||||
si.nPage = m_rcClientWnd.bottom - m_rcClientWnd.top;
|
||||
SetScrollInfo(SB_VERT, &si, TRUE);
|
||||
RedrawWindow();
|
||||
|
||||
CDialogLoggingWnd::GetInstance()->OpenFile(cfd.GetFolderPath(), cfd.GetFileTitle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDialogLoggingTestMainWnd::OnMenuFileClose()
|
||||
{
|
||||
m_bIsOpenFile = FALSE;
|
||||
CDialogLoggingWnd::GetInstance()->CloseFile();
|
||||
//不需要滚动条
|
||||
SetScrollRange(SB_VERT, 0, 0, TRUE);
|
||||
}
|
||||
|
||||
void CDialogLoggingTestMainWnd::OnMenuFileSave()
|
||||
{
|
||||
//CRecentFileList recentFileList;
|
||||
|
||||
}
|
||||
|
||||
void CDialogLoggingTestMainWnd::OnMenuFileSaveAs()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CDialogLoggingTestMainWnd::OnMenuExit()
|
||||
{
|
||||
CDialog::OnOK();
|
||||
}
|
||||
|
||||
void CDialogLoggingTestMainWnd::OnMenuComSetting()
|
||||
{
|
||||
CDialogLoggingSelectComPortWnd dlgComPort;
|
||||
if (IDOK == dlgComPort.DoModal())
|
||||
{
|
||||
m_strComName = dlgComPort.GetSelectComm();
|
||||
}
|
||||
}
|
||||
|
||||
void CDialogLoggingTestMainWnd::OnMenuCreateTask()
|
||||
{
|
||||
CDialogLoggingCreateTaskWnd dlgCreateTaskWnd;
|
||||
dlgCreateTaskWnd.DoModal();
|
||||
}
|
||||
|
||||
void CDialogLoggingTestMainWnd::OnMenuMeasureParamSetting()
|
||||
{
|
||||
if (m_strComName.IsEmpty())
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("请选择通讯串口"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Please select the communication serial port"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
|
||||
CDialogLoggingParameterSetting dlgParamSetting;
|
||||
if (IDOK == dlgParamSetting.DoModal())
|
||||
{
|
||||
//下发参数到下位机
|
||||
STLoggingParamSettingReq stLoggingParamReq = dlgParamSetting.GetLogParamSetting();
|
||||
m_comPort.SetScanBreakSign(FALSE);
|
||||
if (TRUE == m_comPort.OpenComm(m_strComName))
|
||||
{
|
||||
m_comPort.ClearCommReceiveBuff();
|
||||
m_comPort.ClearCommSendBuff();
|
||||
|
||||
char szSend[2048] = { 0 };
|
||||
char szRecv[2048] = { 0 };
|
||||
BYTE ucBuf[4096] = { 0 };
|
||||
STCtrlProtoHeader* pSend = NULL;
|
||||
STCtrlProtoHeader* pRecv = NULL;
|
||||
WORD wTotalLen = 0;
|
||||
BOOL bRes = FALSE;
|
||||
int iPollingTime = 0;
|
||||
int iReceive = 0;
|
||||
memset(szSend, 0, 2048);
|
||||
memset(szRecv, 0, 2048);
|
||||
memset(ucBuf, 0, 4096);
|
||||
pSend = (STCtrlProtoHeader*)ucBuf;
|
||||
pSend->wIDCode = htonl(CTRL_GD10_CODE);
|
||||
pSend->ucSrcAddr = GEOMATIVE_ADDRESS;
|
||||
pSend->ucSrcType = 2;
|
||||
pSend->ucDstAddr = UNDER_MACHINE_ADDRESS;
|
||||
|
||||
pSend->ucDstType = 5;
|
||||
pSend->ucCMD = EN_LOGGING_DOWNLOAD_LOG_PARAM;
|
||||
pSend->ucDataType = 1;
|
||||
pSend->dwSeriNO = m_iSeriNo++;
|
||||
pSend->Status_code = 0;
|
||||
pSend->ucPacketNum = 1;
|
||||
memset(pSend->ucReverse, 0, sizeof(pSend->ucReverse));
|
||||
memcpy(ucBuf + sizeof(STCtrlProtoHeader), &stLoggingParamReq, sizeof(STLoggingParamSettingReq));
|
||||
wTotalLen = sizeof(STCtrlProtoHeader) + sizeof(STLoggingParamSettingReq) + 1;
|
||||
|
||||
pSend->wTotalLen = wTotalLen;
|
||||
*((BYTE*)(ucBuf + wTotalLen - 1)) = BBCCalculate((const char*)(ucBuf), wTotalLen - 1, 0);
|
||||
|
||||
memcpy(szSend, ucBuf, wTotalLen);
|
||||
|
||||
bRes = m_comPort.SendDataDirectly(szSend, wTotalLen);
|
||||
iPollingTime = 0;
|
||||
//发送数据后,接收数据
|
||||
Sleep(200);
|
||||
while (bRes && (iPollingTime < RECV_DATA_FAILED_ATTEMPTS_TIMES))
|
||||
{
|
||||
Sleep(3);
|
||||
if (m_comPort.ReceiveDataDirectly(szRecv, &iReceive) == TRUE)
|
||||
{
|
||||
pRecv = (STCtrlProtoHeader*)szRecv;
|
||||
if (pRecv != NULL)
|
||||
{
|
||||
if (pRecv->ucCMD == EN_LOGGING_DOWNLOAD_LOG_PARAM && pRecv->ucDataType == 2)
|
||||
{
|
||||
STLoggingParamSettingRes* pstParamRes = (STLoggingParamSettingRes*)(szRecv + sizeof(STCtrlProtoHeader));
|
||||
if (pstParamRes != NULL && pstParamRes->byStatusCode == 0)
|
||||
{
|
||||
m_isDownloadParamSetting = TRUE;
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("下发参数成功"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Delivered parameters successfully"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_isDownloadParamSetting = FALSE;
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("下发参数失败"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Delivered parameters failed"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
iPollingTime++;
|
||||
}
|
||||
m_comPort.ClearCommSendBuff();
|
||||
m_comPort.ClearCommReceiveBuff();
|
||||
}
|
||||
m_comPort.CloseComm();
|
||||
LeaveCriticalSection(&g_ScanTabSection);
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT CDialogLoggingTestMainWnd::OnMsgLoggingMeasuringPointData(WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
ST_LOGGING_DATA_PACKET_REQ* pMeasuringDataRes = (ST_LOGGING_DATA_PACKET_REQ*)wParam;
|
||||
if (pMeasuringDataRes == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
UINT CDialogLoggingTestMainWnd::RecvDataThread(LPVOID lParam)
|
||||
{
|
||||
CDialogLoggingTestMainWnd* pThis = (CDialogLoggingTestMainWnd*)lParam;
|
||||
if (pThis == NULL)
|
||||
return 1;
|
||||
|
||||
char szSend[2048] = { 0 };
|
||||
char szRecv[2048] = { 0 };
|
||||
int iReceive = 0;
|
||||
STCtrlProtoHeader* pRecv = NULL;
|
||||
while (pThis->m_isRecvData)
|
||||
{
|
||||
Sleep(200);
|
||||
if (pThis->m_comPort.ReceiveDataDirectly(szRecv, &iReceive) == TRUE)
|
||||
{
|
||||
pRecv = (STCtrlProtoHeader*)szRecv;
|
||||
if (pRecv != NULL)
|
||||
{
|
||||
if (pRecv->ucCMD == EN_LOGGING_MEASURING_POINT_DATA && pRecv->ucDataType == 2)
|
||||
{
|
||||
ST_LOGGING_DATA_PACKET_REQ* pstParamRes = (ST_LOGGING_DATA_PACKET_REQ*)(szRecv + sizeof(STCtrlProtoHeader));
|
||||
if (pstParamRes != NULL)
|
||||
{
|
||||
::SendMessage(pThis->GetSafeHwnd(), WM_MSG_LOGGING_MEASURING_POINT_DATA, (WPARAM)&pstParamRes, NULL);
|
||||
//通知界面绘制
|
||||
|
||||
|
||||
//写入数据库
|
||||
/*if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("接受测试数据成功"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("recv data successfully"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));*/
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("接受测试数据失败"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("recv data failed"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CDialogLoggingTestMainWnd::OnMenuStartLogging()
|
||||
{
|
||||
//如果没有下发配置
|
||||
if (!m_isDownloadParamSetting)
|
||||
{
|
||||
OnMenuMeasureParamSetting();
|
||||
}
|
||||
|
||||
STLoggingStartTestReq stLoggingStartTest;
|
||||
stLoggingStartTest.uiTestID = 1; //默认开始测试从第一个开始
|
||||
m_comPort.SetScanBreakSign(FALSE);
|
||||
if (TRUE == m_comPort.OpenComm(m_strComName))
|
||||
{
|
||||
m_comPort.ClearCommReceiveBuff();
|
||||
m_comPort.ClearCommSendBuff();
|
||||
|
||||
char szSend[2048] = { 0 };
|
||||
char szRecv[2048] = { 0 };
|
||||
BYTE ucBuf[4096] = { 0 };
|
||||
STCtrlProtoHeader* pSend = NULL;
|
||||
STCtrlProtoHeader* pRecv = NULL;
|
||||
WORD wTotalLen = 0;
|
||||
BOOL bRes = FALSE;
|
||||
int iPollingTime = 0;
|
||||
int iReceive = 0;
|
||||
memset(szSend, 0, 2048);
|
||||
memset(szRecv, 0, 2048);
|
||||
memset(ucBuf, 0, 4096);
|
||||
|
||||
pSend = (STCtrlProtoHeader*)ucBuf;
|
||||
pSend->wIDCode = htonl(CTRL_GD10_CODE);
|
||||
pSend->ucSrcAddr = GEOMATIVE_ADDRESS;
|
||||
pSend->ucSrcType = 2;
|
||||
pSend->ucDstAddr = UNDER_MACHINE_ADDRESS;
|
||||
|
||||
pSend->ucDstType = 5;
|
||||
pSend->ucCMD = EN_LOGGING_START_TEST;
|
||||
pSend->ucDataType = 1;
|
||||
pSend->dwSeriNO = m_iSeriNo++;
|
||||
pSend->Status_code = 0;
|
||||
pSend->ucPacketNum = 1;
|
||||
memset(pSend->ucReverse, 0, sizeof(pSend->ucReverse));
|
||||
memcpy(ucBuf + sizeof(STCtrlProtoHeader), &stLoggingStartTest, sizeof(STLoggingStartTestReq));
|
||||
wTotalLen = sizeof(STCtrlProtoHeader) + sizeof(STLoggingStartTestReq) + 1;
|
||||
|
||||
pSend->wTotalLen = wTotalLen;
|
||||
*((BYTE*)(ucBuf + wTotalLen - 1)) = BBCCalculate((const char*)(ucBuf), wTotalLen - 1, 0);
|
||||
|
||||
memcpy(szSend, ucBuf, wTotalLen);
|
||||
|
||||
bRes = m_comPort.SendDataDirectly(szSend, wTotalLen);
|
||||
iPollingTime = 0;
|
||||
//发送数据后,
|
||||
Sleep(200);
|
||||
while (bRes && (iPollingTime < RECV_DATA_FAILED_ATTEMPTS_TIMES))
|
||||
{
|
||||
Sleep(3);
|
||||
if (m_comPort.ReceiveDataDirectly(szRecv, &iReceive) == TRUE)
|
||||
{
|
||||
pRecv = (STCtrlProtoHeader*)szRecv;
|
||||
if (pRecv != NULL)
|
||||
{
|
||||
if (pRecv->ucCMD == EN_LOGGING_START_TEST && pRecv->ucDataType == 2)
|
||||
{
|
||||
STLoggingStartTestRes* pRes = (STLoggingStartTestRes*)(szRecv + sizeof(STCtrlProtoHeader));
|
||||
if (pRes != NULL && pRes->byStatusCode == 0)
|
||||
{
|
||||
m_isRecvData = TRUE;
|
||||
HANDLE hThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)RecvDataThread, this, 0, 0);
|
||||
if (INVALID_HANDLE_VALUE == hThread)
|
||||
{
|
||||
CFileOperTools::GetInstance()->WriteComLog(_T("Create Thread failed to simulate script run method"));
|
||||
}
|
||||
CloseHandle(hThread);
|
||||
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("开始测井成功"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Start logging successfully"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("开始测井失败"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Log start failure"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
iPollingTime++;
|
||||
}
|
||||
|
||||
m_comPort.ClearCommSendBuff();
|
||||
m_comPort.ClearCommReceiveBuff();
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&g_ScanTabSection);
|
||||
}
|
||||
|
||||
void CDialogLoggingTestMainWnd::OnMenuPauseLogging()
|
||||
{
|
||||
//如果没有下发配置
|
||||
if (!m_isDownloadParamSetting)
|
||||
{
|
||||
OnMenuMeasureParamSetting();
|
||||
}
|
||||
|
||||
m_comPort.ClearCommReceiveBuff();
|
||||
m_comPort.ClearCommSendBuff();
|
||||
|
||||
char szSend[2048] = { 0 };
|
||||
char szRecv[2048] = { 0 };
|
||||
BYTE ucBuf[4096] = { 0 };
|
||||
STCtrlProtoHeader* pSend = NULL;
|
||||
STCtrlProtoHeader* pRecv = NULL;
|
||||
WORD wTotalLen = 0;
|
||||
BOOL bRes = FALSE;
|
||||
int iPollingTime = 0;
|
||||
int iReceive = 0;
|
||||
memset(szSend, 0, 2048);
|
||||
memset(szRecv, 0, 2048);
|
||||
memset(ucBuf, 0, 4096);
|
||||
|
||||
pSend = (STCtrlProtoHeader*)ucBuf;
|
||||
pSend->wIDCode = htonl(CTRL_GD10_CODE);
|
||||
pSend->ucSrcAddr = GEOMATIVE_ADDRESS;
|
||||
pSend->ucSrcType = 2;
|
||||
pSend->ucDstAddr = UNDER_MACHINE_ADDRESS;
|
||||
|
||||
pSend->ucDstType = 5;
|
||||
pSend->ucCMD = EN_LOGGING_PAUSE_TEST;
|
||||
pSend->ucDataType = 1;
|
||||
pSend->dwSeriNO = m_iSeriNo++;
|
||||
pSend->Status_code = 0;
|
||||
pSend->ucPacketNum = 1;
|
||||
memset(pSend->ucReverse, 0, sizeof(pSend->ucReverse));
|
||||
wTotalLen = sizeof(STCtrlProtoHeader) + 1;
|
||||
pSend->wTotalLen = wTotalLen;
|
||||
*((BYTE*)(ucBuf + wTotalLen - 1)) = BBCCalculate((const char*)(ucBuf), wTotalLen - 1, 0);
|
||||
|
||||
memcpy(szSend, ucBuf, wTotalLen);
|
||||
|
||||
bRes = m_comPort.SendDataDirectly(szSend, wTotalLen);
|
||||
iPollingTime = 0;
|
||||
//发送数据后,
|
||||
Sleep(200);
|
||||
while (bRes && (iPollingTime < RECV_DATA_FAILED_ATTEMPTS_TIMES))
|
||||
{
|
||||
Sleep(3);
|
||||
if (m_comPort.ReceiveDataDirectly(szRecv, &iReceive) == TRUE)
|
||||
{
|
||||
pRecv = (STCtrlProtoHeader*)szRecv;
|
||||
if (pRecv != NULL)
|
||||
{
|
||||
if (pRecv->ucCMD == EN_LOGGING_PAUSE_TEST && pRecv->ucDataType == 2)
|
||||
{
|
||||
STLoggingStartTestRes* pRes = (STLoggingStartTestRes*)(szRecv + sizeof(STCtrlProtoHeader));
|
||||
if (pRes != NULL && pRes->byStatusCode == 0)
|
||||
{
|
||||
//不接受数据
|
||||
m_isRecvData = FALSE;
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("暂停测井成功"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Pause logging successfully"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("暂停测井失败"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Log pause failure"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
iPollingTime++;
|
||||
}
|
||||
|
||||
m_comPort.ClearCommSendBuff();
|
||||
m_comPort.ClearCommReceiveBuff();
|
||||
|
||||
LeaveCriticalSection(&g_ScanTabSection);
|
||||
}
|
||||
|
||||
void CDialogLoggingTestMainWnd::OnMenuContinueLogging()
|
||||
{
|
||||
//如果没有下发配置
|
||||
if (!m_isDownloadParamSetting)
|
||||
{
|
||||
OnMenuMeasureParamSetting();
|
||||
}
|
||||
|
||||
m_comPort.ClearCommReceiveBuff();
|
||||
m_comPort.ClearCommSendBuff();
|
||||
|
||||
char szSend[2048] = { 0 };
|
||||
char szRecv[2048] = { 0 };
|
||||
BYTE ucBuf[4096] = { 0 };
|
||||
STCtrlProtoHeader* pSend = NULL;
|
||||
STCtrlProtoHeader* pRecv = NULL;
|
||||
WORD wTotalLen = 0;
|
||||
BOOL bRes = FALSE;
|
||||
int iPollingTime = 0;
|
||||
int iReceive = 0;
|
||||
memset(szSend, 0, 2048);
|
||||
memset(szRecv, 0, 2048);
|
||||
memset(ucBuf, 0, 4096);
|
||||
|
||||
pSend = (STCtrlProtoHeader*)ucBuf;
|
||||
pSend->wIDCode = htonl(CTRL_GD10_CODE);
|
||||
pSend->ucSrcAddr = GEOMATIVE_ADDRESS;
|
||||
pSend->ucSrcType = 2;
|
||||
pSend->ucDstAddr = UNDER_MACHINE_ADDRESS;
|
||||
|
||||
pSend->ucDstType = 5;
|
||||
pSend->ucCMD = EN_LOGGING_CONTINUE_TEST;
|
||||
pSend->ucDataType = 1;
|
||||
pSend->dwSeriNO = m_iSeriNo++;
|
||||
pSend->Status_code = 0;
|
||||
pSend->ucPacketNum = 1;
|
||||
memset(pSend->ucReverse, 0, sizeof(pSend->ucReverse));
|
||||
wTotalLen = sizeof(STCtrlProtoHeader) + 1;
|
||||
|
||||
pSend->wTotalLen = wTotalLen;
|
||||
*((BYTE*)(ucBuf + wTotalLen - 1)) = BBCCalculate((const char*)(ucBuf), wTotalLen - 1, 0);
|
||||
|
||||
memcpy(szSend, ucBuf, wTotalLen);
|
||||
|
||||
bRes = m_comPort.SendDataDirectly(szSend, wTotalLen);
|
||||
iPollingTime = 0;
|
||||
//发送数据后,
|
||||
Sleep(200);
|
||||
while (bRes && (iPollingTime < RECV_DATA_FAILED_ATTEMPTS_TIMES))
|
||||
{
|
||||
Sleep(3);
|
||||
if (m_comPort.ReceiveDataDirectly(szRecv, &iReceive) == TRUE)
|
||||
{
|
||||
pRecv = (STCtrlProtoHeader*)szRecv;
|
||||
if (pRecv != NULL)
|
||||
{
|
||||
if (pRecv->ucCMD == EN_LOGGING_CONTINUE_TEST && pRecv->ucDataType == 2)
|
||||
{
|
||||
STLoggingStartTestRes* pRes = (STLoggingStartTestRes*)(szRecv + sizeof(STCtrlProtoHeader));
|
||||
if (pRes != NULL && pRes->byStatusCode == 0)
|
||||
{
|
||||
//接受数据
|
||||
m_isRecvData = TRUE;
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("继续测井成功"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Continue logging successfully"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("开始测井失败"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Log continue failure"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
iPollingTime++;
|
||||
}
|
||||
|
||||
m_comPort.ClearCommSendBuff();
|
||||
m_comPort.ClearCommReceiveBuff();
|
||||
|
||||
LeaveCriticalSection(&g_ScanTabSection);
|
||||
}
|
||||
|
||||
void CDialogLoggingTestMainWnd::OnMenuEndLogging()
|
||||
{
|
||||
//如果没有下发配置
|
||||
if (!m_isDownloadParamSetting)
|
||||
{
|
||||
OnMenuMeasureParamSetting();
|
||||
}
|
||||
|
||||
m_comPort.ClearCommReceiveBuff();
|
||||
m_comPort.ClearCommSendBuff();
|
||||
|
||||
char szSend[2048] = { 0 };
|
||||
char szRecv[2048] = { 0 };
|
||||
BYTE ucBuf[4096] = { 0 };
|
||||
STCtrlProtoHeader* pSend = NULL;
|
||||
STCtrlProtoHeader* pRecv = NULL;
|
||||
WORD wTotalLen = 0;
|
||||
BOOL bRes = FALSE;
|
||||
int iPollingTime = 0;
|
||||
int iReceive = 0;
|
||||
memset(szSend, 0, 2048);
|
||||
memset(szRecv, 0, 2048);
|
||||
memset(ucBuf, 0, 4096);
|
||||
|
||||
pSend = (STCtrlProtoHeader*)ucBuf;
|
||||
pSend->wIDCode = htonl(CTRL_GD10_CODE);
|
||||
pSend->ucSrcAddr = GEOMATIVE_ADDRESS;
|
||||
pSend->ucSrcType = 2;
|
||||
pSend->ucDstAddr = UNDER_MACHINE_ADDRESS;
|
||||
|
||||
pSend->ucDstType = 5;
|
||||
pSend->ucCMD = EN_LOGGING_END_TEST;
|
||||
pSend->ucDataType = 1;
|
||||
pSend->dwSeriNO = m_iSeriNo++;
|
||||
pSend->Status_code = 0;
|
||||
pSend->ucPacketNum = 1;
|
||||
memset(pSend->ucReverse, 0, sizeof(pSend->ucReverse));
|
||||
wTotalLen = sizeof(STCtrlProtoHeader) + 1;
|
||||
|
||||
pSend->wTotalLen = wTotalLen;
|
||||
*((BYTE*)(ucBuf + wTotalLen - 1)) = BBCCalculate((const char*)(ucBuf), wTotalLen - 1, 0);
|
||||
|
||||
memcpy(szSend, ucBuf, wTotalLen);
|
||||
|
||||
bRes = m_comPort.SendDataDirectly(szSend, wTotalLen);
|
||||
iPollingTime = 0;
|
||||
//发送数据后,
|
||||
Sleep(200);
|
||||
while (bRes && (iPollingTime < RECV_DATA_FAILED_ATTEMPTS_TIMES))
|
||||
{
|
||||
Sleep(3);
|
||||
if (m_comPort.ReceiveDataDirectly(szRecv, &iReceive) == TRUE)
|
||||
{
|
||||
pRecv = (STCtrlProtoHeader*)szRecv;
|
||||
if (pRecv != NULL)
|
||||
{
|
||||
if (pRecv->ucCMD == EN_LOGGING_END_TEST && pRecv->ucDataType == 2)
|
||||
{
|
||||
STLoggingStartTestRes* pRes = (STLoggingStartTestRes*)(szRecv + sizeof(STCtrlProtoHeader));
|
||||
if (pRes != NULL && pRes->byStatusCode == 0)
|
||||
{
|
||||
//不接受数据
|
||||
m_isRecvData = FALSE;
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("结束测井成功"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("End logging successfully"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("结束测井失败"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Log end failure"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
iPollingTime++;
|
||||
}
|
||||
m_comPort.ClearCommSendBuff();
|
||||
m_comPort.ClearCommReceiveBuff();
|
||||
|
||||
m_comPort.CloseComm();
|
||||
LeaveCriticalSection(&g_ScanTabSection);
|
||||
}
|
||||
|
||||
void CDialogLoggingTestMainWnd::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
|
||||
{
|
||||
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
||||
SCROLLINFO si = {sizeof(si)};
|
||||
si.fMask = SIF_ALL;
|
||||
GetScrollInfo(SB_VERT, &si);
|
||||
|
||||
int nPrevPos = si.nPos;
|
||||
switch (nSBCode)
|
||||
{
|
||||
case SB_TOP:
|
||||
si.nPos = si.nMin;
|
||||
break;
|
||||
case SB_BOTTOM:
|
||||
si.nPos = si.nMax;
|
||||
break;
|
||||
case SB_LINEUP:
|
||||
si.nPos -= 15;
|
||||
break;
|
||||
case SB_LINEDOWN:
|
||||
si.nPos += 15;
|
||||
break;
|
||||
case SB_PAGEUP:
|
||||
si.nPos -= si.nPage;
|
||||
break;
|
||||
case SB_PAGEDOWN:
|
||||
si.nPos += si.nPage;
|
||||
break;
|
||||
case SB_THUMBTRACK:
|
||||
si.nPos = si.nTrackPos;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
si.fMask = SIF_POS;
|
||||
SetScrollInfo(SB_VERT, &si, TRUE);
|
||||
if (si.nPos != nPrevPos)
|
||||
{
|
||||
ScrollWindow(0, nPrevPos - si.nPos, NULL, NULL);
|
||||
//Invalidate(FALSE);
|
||||
UpdateWindow();
|
||||
}
|
||||
|
||||
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
|
||||
}
|
||||
|
||||
void CDialogLoggingTestMainWnd::OnDestroy()
|
||||
{
|
||||
CDialog::OnDestroy();
|
||||
OnMenuFileClose();
|
||||
m_comPort.CloseComm();
|
||||
m_isRecvData = FALSE;
|
||||
// TODO: 在此处添加消息处理程序代码
|
||||
}
|
||||
|
||||
BOOL CDialogLoggingTestMainWnd::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
|
||||
{
|
||||
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
||||
SCROLLINFO si = { sizeof(si) };
|
||||
si.fMask = SIF_ALL;
|
||||
GetScrollInfo(SB_VERT, &si);
|
||||
float fScrollBarHeigh = (si.nPage*(si.nPage - 32) / si.nMax);
|
||||
int nPrevPos = si.nPos;
|
||||
if (zDelta > 0)//向上滚动
|
||||
{
|
||||
if (nPrevPos <= si.nMin)
|
||||
{
|
||||
OnVScroll(SB_TOP, pt.y, this->GetScrollBarCtrl(SB_VERT));
|
||||
}
|
||||
else
|
||||
{
|
||||
si.nPos -= 15;
|
||||
int iSub = si.nPos / 15;
|
||||
int iMod = si.nPos % 15;
|
||||
if (iMod > 0)
|
||||
{
|
||||
si.nPos = (iSub + 1) * 15;
|
||||
}
|
||||
if (si.nPos < 0)
|
||||
{
|
||||
nPrevPos = 15;
|
||||
si.nPos = 0;
|
||||
}
|
||||
OnVScroll(SB_LINEUP, si.nPos, this->GetScrollBarCtrl(SB_VERT));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
else//向下滚动
|
||||
{
|
||||
if (nPrevPos >= (si.nMax -(m_rcClientWnd.bottom - m_rcClientWnd.top)))
|
||||
return FALSE;
|
||||
si.nPos += 15;
|
||||
}
|
||||
si.fMask = SIF_POS;
|
||||
SetScrollInfo(SB_VERT, &si, TRUE);
|
||||
if (si.nPos != nPrevPos && (si.nPos >= si.nMin) && (si.nPos <= si.nMax))
|
||||
{
|
||||
ScrollWindow(0, nPrevPos - si.nPos, NULL, NULL);
|
||||
UpdateWindow();
|
||||
}
|
||||
|
||||
return CDialog::OnMouseWheel(nFlags, zDelta, pt);
|
||||
}
|
||||
Reference in New Issue
Block a user