• 大小: 5.01MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-08-15
  • 语言: 其他
  • 标签: modbus  vc++  

资源简介

modbus上位机测试源码。。

资源截图

代码片段和文件信息

// ComControl.cpp

#include “StdAfx.h“
#include “ComControl.h“
#include “DlgComSet.h“

UINT ComThreadProc(LPVOID para)
{
CComControl* pCom = (CComControl*)para;
DWORD dwEventMask;
OVERLAPPED eov;
memset( &eov 0 sizeof( OVERLAPPED ) ) ;
eov.hEvent = CreateEvent( NULL // no security attributes
  FALSE // auto reset event
  FALSE // not signaled
  NULL // no name
);
HANDLE hWaits[2];
DWORD dwWait;
hWaits[0] = eov.hEvent;
hWaits[1] = pCom->m_hExit;
while(true)
{
dwEventMask = 0;
WaitCommEvent(pCom->m_hCom &dwEventMask &eov);
dwWait = WaitForMultipleobjects(2 hWaits false INFINITE);
if(dwWait == WAIT_object_0+1)
break;

//EnterCriticalSection(&pCom->m_csWmThreshold);
pCom->ResetBytes();

if(dwEventMask & EV_ERR) // 线路错误CE_frame CE_OVERRUN and CE_RXPARITY.
{
SendMessage( pCom->m_hOwner WM_COM COM_ERR 0 );
}

if(dwEventMask & EV_TXEMPTY) // 输出缓冲区空
{
SendMessage( pCom->m_hOwner WM_COM COM_EMPTY 0 );
}

if( dwEventMask & EV_RXCHAR && 
// pCom->m_bCanInterrupt && //确认上一条消息已处理完
// pCom->m_nThresHold &&
pCom->m_cbInQue >= pCom->m_nThresHold // 输入缓冲区接收到一字符
  ) 
{
pCom->m_bCanInterrupt = false;
SendMessage( pCom->m_hOwner WM_COMCOM_THRESHOLD0);
}
//LeaveCriticalSection(&pCom->m_csWmThreshold);
}
CloseHandle(eov.hEvent);

return true;
}

CComControl::CComControl(HWND hOwner)
{
m_hOwner = hOwner;
InitCom();
}

void CComControl::InitCom()
{
InitializeCriticalSection(&m_csWmThreshold);
memset( &m_ovRead 0 sizeof( OVERLAPPED ) ) ;
    memset( &m_ovWrite 0 sizeof( OVERLAPPED ) ) ;
    m_ovRead.hEvent = CreateEvent( NULL // no security
                                   TRUE // explicit reset req;TRUE=人工重置;FASE=自动重置
                                   FALSE // initial event reset;TRUE=已通知状态;FALSE=未通知状态
                                   NULL // no name
  );       
    m_ovWrite.hEvent = CreateEvent( NULL TRUE FALSE NULL );  // See above
m_nThresHold = 0;
m_bCanInterrupt = false;
m_hExit = CreateEvent(NULL false false NULL);
m_szPortName = “COM1“;
m_lBaudRate = 9600;
m_nParity = NOPARITY;
m_hCom = INVALID_HANDLE_VALUE;
m_cbInQue = 0;
m_cbOutQue = 0;
m_pThread = AfxBeginThread(ComThreadProc (LPVOID)thisTHREAD_PRIORITY_NORMAL 0 CREATE_SUSPENDED); 
}

CComControl::~CComControl()
{
m_pThread->ResumeThread();
SetEvent(m_hExit);
WaitForSingleobject(m_pThread->m_hThread INFINITE);
m_pThread = NULL;   //this ensure pCom->ClosePort work correct
ClosePort();
CloseHandle(m_ovRead.hEvent);
CloseHandle(m_ovWrite.hEvent);
CloseHandle(m_hExit);
DeleteCriticalSection(&m_csWmThreshold);
}

bool __fastcall CComControl::IsWindowsNT()
{
OSVERSIONINFO osv;
osv.dwOSVersionInfoSize = sizeof(osv);
GetVersionEx(&osv);
return (osv.dwPlatformId == VER_PLATFORM_WIN32_NT);
}

void CComControl::ResetByte

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      17328  2004-02-08 14:52  vc test\jkModbus\CDTCS.RC

     文件      10158  2004-06-01 14:55  vc test\jkModbus\ComControl.cpp

     文件       1921  2004-06-01 15:26  vc test\jkModbus\ComControl.h

     文件       5697  2004-06-01 15:08  vc test\jkModbus\CRCClass.cpp

     文件       1544  2004-06-01 15:19  vc test\jkModbus\CRCClass.h

     文件      26813  2006-02-26 12:26  vc test\jkModbus\Debug\ComControl.obj

     文件          0  2006-02-26 12:26  vc test\jkModbus\Debug\ComControl.sbr

     文件      10113  2006-02-26 12:26  vc test\jkModbus\Debug\CRCClass.obj

     文件          0  2006-02-26 12:26  vc test\jkModbus\Debug\CRCClass.sbr

     文件      20390  2006-02-26 12:26  vc test\jkModbus\Debug\DlgComSet.obj

     文件          0  2006-02-26 12:26  vc test\jkModbus\Debug\DlgComSet.sbr

     文件    3138560  2006-02-26 12:26  vc test\jkModbus\Debug\jkModbus.bsc

     文件    2121838  2006-02-26 12:26  vc test\jkModbus\Debug\jkModbus.exe

     文件    2500432  2006-02-26 12:26  vc test\jkModbus\Debug\jkModbus.ilk

     文件      14427  2006-02-26 12:26  vc test\jkModbus\Debug\jkModbus.obj

     文件    6842740  2006-02-26 12:26  vc test\jkModbus\Debug\jkModbus.pch

     文件    3548160  2006-02-26 12:26  vc test\jkModbus\Debug\jkModbus.pdb

     文件       4244  2006-02-26 12:26  vc test\jkModbus\Debug\jkModbus.res

     文件          0  2006-02-26 12:26  vc test\jkModbus\Debug\jkModbus.sbr

     文件      72748  2006-02-26 12:26  vc test\jkModbus\Debug\jkModbusDlg.obj

     文件          0  2006-02-26 12:26  vc test\jkModbus\Debug\jkModbusDlg.sbr

     文件     106024  2006-02-26 12:26  vc test\jkModbus\Debug\StdAfx.obj

     文件    1363263  2006-02-26 12:26  vc test\jkModbus\Debug\StdAfx.sbr

     文件     214016  2006-09-03 15:24  vc test\jkModbus\Debug\VC60.IDB

     文件     364544  2006-02-26 12:26  vc test\jkModbus\Debug\VC60.PDB

     目录          0  2010-10-21 20:45  vc test\jkModbus\Debug

     文件       2836  2004-05-28 14:24  vc test\jkModbus\DlgComSet.cpp

     文件       1409  2004-02-08 16:18  vc test\jkModbus\DlgComSet.h

     文件      24244  2006-09-03 15:24  vc test\jkModbus\jkModbus.aps

     文件       3149  2006-09-03 15:24  vc test\jkModbus\jkModbus.clw

............此处省略23个文件信息

评论

共有 条评论