a
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
//logging\CDialogLoggingSelectComPortWnd.cpp : 实现文件
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "GeoMative.h"
|
||||
#include "logging\CDialogLoggingSelectComPortWnd.h"
|
||||
#include "afxdialogex.h"
|
||||
|
||||
extern int g_iUILanguage;
|
||||
extern CDevLinkRecord* aDevLinkTable[256];
|
||||
extern BOOL g_bScanFun;
|
||||
extern CRITICAL_SECTION g_ScanTabSection;
|
||||
extern BYTE BBCCalculate(const char *pData, int iSize, BYTE ucOrgRes);
|
||||
// CDialogLoggingSelectComPortWnd 对话框
|
||||
|
||||
IMPLEMENT_DYNAMIC(CDialogLoggingSelectComPortWnd, CDialog)
|
||||
|
||||
CDialogLoggingSelectComPortWnd::CDialogLoggingSelectComPortWnd(CWnd* pParent /*=NULL*/)
|
||||
: CDialog(CDialogLoggingSelectComPortWnd::IDD, pParent)
|
||||
{
|
||||
m_iSeriNo = 1;
|
||||
}
|
||||
|
||||
CDialogLoggingSelectComPortWnd::~CDialogLoggingSelectComPortWnd()
|
||||
{
|
||||
}
|
||||
|
||||
void CDialogLoggingSelectComPortWnd::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
DDX_Control(pDX, IDC_COMBO_AVAILABLE_SERIAL_PORT, m_comComNameList);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CDialogLoggingSelectComPortWnd, CDialog)
|
||||
ON_BN_CLICKED(IDOK, &CDialogLoggingSelectComPortWnd::OnBnClickedOk)
|
||||
ON_BN_CLICKED(IDCANCEL, &CDialogLoggingSelectComPortWnd::OnBnClickedCancel)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
// CDialogLoggingSelectComPortWnd 消息处理程序
|
||||
BOOL CDialogLoggingSelectComPortWnd::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
SetWindowTextA(_T("选中通讯端口"));
|
||||
GetDlgItem(IDC_STATIC_AVAILABLE_SERIAL_PORT)->SetWindowTextA(_T("可用串口"));
|
||||
GetDlgItem(IDOK)->SetWindowTextA(_T("确定"));
|
||||
GetDlgItem(IDCANCEL)->SetWindowTextA(_T("取消"));
|
||||
}
|
||||
|
||||
CStringArray strComNameArray;
|
||||
CSComPort::FindComName(&strComNameArray);
|
||||
|
||||
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;
|
||||
for (int i = 0; i < strComNameArray.GetSize(); i++)
|
||||
{
|
||||
//通过Login指令过滤掉,不可以的串口
|
||||
EnterCriticalSection(&g_ScanTabSection);
|
||||
m_SComPort.SetScanBreakSign(FALSE);
|
||||
if (TRUE == m_SComPort.OpenComm(strComNameArray.GetAt(i)))
|
||||
{
|
||||
m_SComPort.ClearCommReceiveBuff();
|
||||
m_SComPort.ClearCommSendBuff();
|
||||
|
||||
/*CString szOrder = _T("");
|
||||
szOrder.Empty();
|
||||
szOrder.Format(_T("\r\n"));
|
||||
m_SComPort.SendDataDirectly(szOrder.GetBuffer(szOrder.GetLength()), szOrder.GetLength());
|
||||
Sleep(500);
|
||||
|
||||
szOrder.ReleaseBuffer();
|
||||
szOrder.Empty();*/
|
||||
|
||||
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_CHECK_PORT_LOGIN;
|
||||
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_SComPort.SendDataDirectly(szSend, wTotalLen);
|
||||
iPollingTime = 0;
|
||||
//发送数据后,接受数据
|
||||
Sleep(200);
|
||||
while (bRes && (iPollingTime < RECV_DATA_FAILED_ATTEMPTS_TIMES))
|
||||
{
|
||||
Sleep(3);
|
||||
if (m_SComPort.ReceiveDataDirectly(szRecv, &iReceive) == TRUE)
|
||||
{
|
||||
pRecv = (STCtrlProtoHeader*)szRecv;
|
||||
if (pRecv != NULL)
|
||||
{
|
||||
if (pRecv->ucCMD == EN_LOGGING_CHECK_PORT_LOGIN && pRecv->ucDataType == 2)
|
||||
{
|
||||
m_comComNameList.AddString(strComNameArray.GetAt(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
iPollingTime++;
|
||||
}
|
||||
|
||||
m_SComPort.ClearCommSendBuff();
|
||||
m_SComPort.ClearCommReceiveBuff();
|
||||
}
|
||||
m_SComPort.CloseComm();
|
||||
|
||||
LeaveCriticalSection(&g_ScanTabSection);
|
||||
|
||||
}
|
||||
m_comComNameList.SetCurSel(0);
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// 异常: OCX 属性页应返回 FALSE
|
||||
}
|
||||
|
||||
void CDialogLoggingSelectComPortWnd::OnBnClickedOk()
|
||||
{
|
||||
int iIndex = m_comComNameList.GetCurSel();
|
||||
m_comComNameList.GetLBText(iIndex, m_strComName);
|
||||
CDialog::OnOK();
|
||||
}
|
||||
|
||||
void CDialogLoggingSelectComPortWnd::OnBnClickedCancel()
|
||||
{
|
||||
// TODO: 在此添加控件通知处理程序代码
|
||||
CDialog::OnCancel();
|
||||
}
|
||||
|
||||
CString CDialogLoggingSelectComPortWnd::GetSelectComm()
|
||||
{
|
||||
return m_strComName;
|
||||
}
|
||||
Reference in New Issue
Block a user