#include "stdafx.h" #include ".\device.h" #include "Global.h" CDevice::CDevice(void) { // m_iVarId = 0; //变量ID m_iID = 0; //设备的ID m_iPort = 0; //设备串口号 m_iDeviceType = 0; //设备类型 m_iBaudrate = 0; //波特率 m_iDatabit = 0; //数据位 m_iStopbit = 0; //停止位 m_iParitybit = 0; //奇偶校验位 m_iRsmode = 0; //串口通信方式,0 - RS232;1 - RS422; 2 - RS485 m_iIpport = 0; //ip端口号 m_iCommmode = 0; //通信的方式,有 0 - 串口方式;... m_iDeviceflag = -1; //该设备是否采集器 ;... m_iDevideaddr = 0; //设备地址 m_iTimeout = 0; //通讯超时 m_iIsuse = 0; //是否启用设备1:启用,0:禁用 m_strUid =_T(""); //设备UID m_strDeviceName = _T(""); //设备名称 m_strIp = _T(""); //ip地址号 m_strProtocoldllname = _T("");//协议DLL名称 m_bySpecialdevice = 0; //Modbus Rtu;Modbus Ascii;Modbus Tcp;Snmp;RS232; m_dwOnlineTick = 0; m_bCommStatus = TRUE; //=============================================== // 新增成员变量 in 2010-04-07 m_strIniName = _T(""); //配置文件名称 m_strReserved1 = _T(""); m_strReserved2 = _T(""); m_strReserved3 = _T(""); m_strReserved4 = _T(""); m_strReserved5 = _T(""); m_strReserved6 = _T(""); m_strReserved7 = _T(""); m_strReserved8 = _T(""); m_strReserved9 = _T(""); m_strReserved10 = _T(""); m_nReserved1 = 0; m_nReserved2 = 0; m_nReserved3 = 0; m_nReserved4 = 0; m_nReserved5 = 0; m_nReserved6 = 0; m_nReserved7 = 0; m_nReserved8 = 0; m_nReserved9 = 0; m_nReserved10 = 0; m_bReserved1 = false; m_bReserved2 = false; m_bReserved3 = false; m_bReserved4 = false; m_bReserved5 = false; m_bReserved6 = false; m_bReserved7 = false; m_bReserved8 = false; m_bReserved9 = false; m_bReserved10 = false; MTVERIFY( m_hSemNet = CreateEvent( NULL, TRUE, TRUE, 0 ) ); } CDevice::CDevice(const CDevice & other) { // m_iVarId = other.m_iVarId; //变量ID m_iID = other.m_iID; //设备的ID m_iPort = other.m_iPort; //设备串口号 m_iDeviceType = other.m_iDeviceType; //设备类型 m_iBaudrate = other.m_iBaudrate; //波特率 m_iDatabit = other.m_iDatabit; //数据位 m_iStopbit = other.m_iStopbit; //停止位 m_iParitybit = other.m_iParitybit; //奇偶校验位 m_iRsmode = other.m_iRsmode; //串口通信方式,0 - RS232;1 - RS422; 2 - RS485 m_iIpport = other.m_iIpport; //ip端口号 m_iCommmode = other.m_iCommmode; //通信的方式,有 0 - 串口方式;... m_iDeviceflag = other.m_iDeviceflag; //该设备是否采集器 ;... m_iDevideaddr = other.m_iDevideaddr; //设备地址 m_iTimeout = other.m_iTimeout; //通讯超时 m_iIsuse = other.m_iIsuse; //是否启用设备1:启用,0:禁用 m_strUid = other.m_strUid; //设备UID m_strDeviceName = other.m_strDeviceName; //设备名称 m_strIp = other.m_strIp; //ip地址号 m_strProtocoldllname = other.m_strProtocoldllname;//协议DLL名称 m_bySpecialdevice = other.m_bySpecialdevice; //Modbus Rtu;Modbus Ascii;Modbus Tcp;Snmp;RS232; m_dwOnlineTick = other.m_dwOnlineTick; m_bCommStatus = other.m_bCommStatus; //=============================================== // 新增成员变量 in 2010-04-07 m_strIniName = other.m_strIniName; m_strReserved1 = other.m_strReserved1; m_strReserved2 = other.m_strReserved2; m_strReserved3 = other.m_strReserved3; m_strReserved4 = other.m_strReserved4; m_strReserved5 = other.m_strReserved5; m_strReserved6 = other.m_strReserved6; m_strReserved7 = other.m_strReserved7; m_strReserved8 = other.m_strReserved8; m_strReserved9 = other.m_strReserved9; m_strReserved10 = other.m_strReserved10; m_nReserved1 = other.m_nReserved1; m_nReserved2 = other.m_nReserved2; m_nReserved3 = other.m_nReserved3; m_nReserved4 = other.m_nReserved4; m_nReserved5 = other.m_nReserved5; m_nReserved6 = other.m_nReserved6; m_nReserved7 = other.m_nReserved7; m_nReserved8 = other.m_nReserved8; m_nReserved9 = other.m_nReserved9; m_nReserved10 = other.m_nReserved10; m_bReserved1 = other.m_bReserved1; m_bReserved2 = other.m_bReserved2; m_bReserved3 = other.m_bReserved3; m_bReserved4 = other.m_bReserved4; m_bReserved5 = other.m_bReserved5; m_bReserved6 = other.m_bReserved6; m_bReserved7 = other.m_bReserved7; m_bReserved8 = other.m_bReserved8; m_bReserved9 = other.m_bReserved9; m_bReserved10 = other.m_bReserved10; } CDevice &CDevice::operator =(const CDevice & other) { if (this == &other) return *this; // m_iVarId = other.m_iVarId; //变量ID m_iID = other.m_iID; //设备的ID m_iPort = other.m_iPort; //设备串口号 m_iDeviceType = other.m_iDeviceType; //设备类型 m_iBaudrate = other.m_iBaudrate; //波特率 m_iDatabit = other.m_iDatabit; //数据位 m_iStopbit = other.m_iStopbit; //停止位 m_iParitybit = other.m_iParitybit; //奇偶校验位 m_iRsmode = other.m_iRsmode; //串口通信方式,0 - RS232;1 - RS422; 2 - RS485 m_iIpport = other.m_iIpport; //ip端口号 m_iCommmode = other.m_iCommmode; //通信的方式,有 0 - 串口方式;... m_iDeviceflag = other.m_iDeviceflag; //该设备是否采集器 ;... m_iDevideaddr = other.m_iDevideaddr; //设备地址 m_iTimeout = other.m_iTimeout; //通讯超时 m_iIsuse = other.m_iIsuse; //是否启用设备1:启用,0:禁用 m_strUid = other.m_strUid; //设备UID m_strDeviceName = other.m_strDeviceName; //设备名称 m_strIp = other.m_strIp; //ip地址号 m_strProtocoldllname = other.m_strProtocoldllname;//协议DLL名称 m_bySpecialdevice = other.m_bySpecialdevice; //Modbus Rtu;Modbus Ascii;Modbus Tcp;Snmp;RS232; m_dwOnlineTick = other.m_dwOnlineTick; m_bCommStatus = other.m_bCommStatus; //=============================================== // 新增成员变量 in 2010-04-07 m_strIniName = other.m_strIniName; m_strReserved1 = other.m_strReserved1; m_strReserved2 = other.m_strReserved2; m_strReserved3 = other.m_strReserved3; m_strReserved4 = other.m_strReserved4; m_strReserved5 = other.m_strReserved5; m_strReserved6 = other.m_strReserved6; m_strReserved7 = other.m_strReserved7; m_strReserved8 = other.m_strReserved8; m_strReserved9 = other.m_strReserved9; m_strReserved10 = other.m_strReserved10; m_nReserved1 = other.m_nReserved1; m_nReserved2 = other.m_nReserved2; m_nReserved3 = other.m_nReserved3; m_nReserved4 = other.m_nReserved4; m_nReserved5 = other.m_nReserved5; m_nReserved6 = other.m_nReserved6; m_nReserved7 = other.m_nReserved7; m_nReserved8 = other.m_nReserved8; m_nReserved9 = other.m_nReserved9; m_nReserved10 = other.m_nReserved10; m_bReserved1 = other.m_bReserved1; m_bReserved2 = other.m_bReserved2; m_bReserved3 = other.m_bReserved3; m_bReserved4 = other.m_bReserved4; m_bReserved5 = other.m_bReserved5; m_bReserved6 = other.m_bReserved6; m_bReserved7 = other.m_bReserved7; m_bReserved8 = other.m_bReserved8; m_bReserved9 = other.m_bReserved9; m_bReserved10 = other.m_bReserved10; return *this; } CDevice::~CDevice(void) { if( m_hSemNet ) { MTVERIFY( SetEvent(m_hSemNet) ); MTVERIFY( CloseHandle( m_hSemNet )); } } int FindDevice(CString strDevUid) { int nRet = -1; int nDeviceSize = (int)g_pDevicesManager->m_Devices.GetSize(); for (int i = 0; i< nDeviceSize; i++) { CDevice *pDev = g_pDevicesManager->m_Devices[i]; if( pDev->m_strUid.Compare(strDevUid) == 0 ) { nRet = i; } } return nRet; } BOOL FindVar(CString strDevUid, int nVarID, int &nDeviceIndex, int &nVarIndex) { BOOL bRet = FALSE; int i, j; int nDeviceSize = (int)g_pDevicesManager->m_Devices.GetSize(); for( i = 0; i < nDeviceSize; i++ ) { CDevice *pDev = g_pDevicesManager->m_Devices[i]; int nVarSize = (int)pDev->m_Vars.GetSize(); for( j = 0; j < nVarSize; j++ ) { CBaseVar *pBaseVar = pDev->m_Vars[j]; if( pBaseVar->m_nVarID == nVarID && pDev->m_strUid.Compare(strDevUid) == 0 ) { nDeviceIndex = i; nVarIndex = j; bRet = TRUE; return bRet; } } } return bRet; } BOOL FindVar(CString strDevUid, CString strVarName, int &nDeviceIndex, int &nVarIndex) { BOOL bRet = FALSE; int i, j; int nDeviceSize = (int)g_pDevicesManager->m_Devices.GetSize(); for( i = 0; i < nDeviceSize; i++ ) { CDevice *pDev = g_pDevicesManager->m_Devices[i]; int nVarSize = (int)pDev->m_Vars.GetSize(); for( j = 0; j < nVarSize; j++ ) { CBaseVar *pBaseVar = pDev->m_Vars[j]; if( pBaseVar->m_strName.Compare(strVarName) == 0 ) { nDeviceIndex = i; nVarIndex = j; bRet = TRUE; return bRet; } } } return bRet; } BOOL FindVar(CString &strDevUid, int &iVarID,CString strVarName, int &nDeviceIndex, int &nVarIndex) { BOOL bRet = FALSE; int i, j; int nDeviceSize = (int)g_pDevicesManager->m_Devices.GetSize(); for( i = 0; i < nDeviceSize; i++ ) { CDevice *pDev = g_pDevicesManager->m_Devices[i]; int nVarSize = (int)pDev->m_Vars.GetSize(); for( j = 0; j < nVarSize; j++ ) { CBaseVar *pBaseVar = pDev->m_Vars[j]; if( pBaseVar->m_strName.Compare(strVarName) == 0 ) { strDevUid = pDev->m_strUid; iVarID = pBaseVar->m_nVarID; nDeviceIndex = i; nVarIndex = j; bRet = TRUE; return bRet; } } } return bRet; } CBaseVar* FindVar( CString sDevName,CString sVarName ) { if( sVarName!="" ) { for( int i = 0; i < (int)g_pDevicesManager->m_Devices.GetSize(); i++ ) { CDevice *pDev = g_pDevicesManager->m_Devices[i]; if( pDev->m_strDeviceName==sDevName ) { int nVarSize = (int)pDev->m_Vars.GetSize(); for( int m = 0; m < nVarSize; m++ ) { CBaseVar *pBaseVar = pDev->m_Vars[m]; if( pBaseVar->m_strName == sVarName ) { return pBaseVar; } } return NULL; } } } else { for( int i = 0; i < (int)g_pDevicesManager->m_Devices.GetSize(); i++ ) { CDevice *pDev = g_pDevicesManager->m_Devices[i]; if( pDev->m_strDeviceName==sDevName ) { int nVarSize = (int)pDev->m_Vars.GetSize(); for( int m = 0; m < nVarSize; m++ ) { CBaseVar *pBaseVar = pDev->m_Vars[m]; if( pBaseVar->m_bReadOnly==0 && pBaseVar->m_nVarTypeID != ONLINE_VAR_ID && pBaseVar->m_nVarTypeID != HIGH_PRIORITY_ONLINE_ID ) { return pBaseVar; } } return NULL; } } } return NULL; } BOOL IsExistVar( CString sVarName )//判断变量是否存在 { if( sVarName=="" ) return FALSE; BOOL bRet = FALSE; int i, j; int nDeviceSize = (int)g_pDevicesManager->m_Devices.GetSize(); for( i = 0; i < nDeviceSize; i++ ) { CDevice *pDev = g_pDevicesManager->m_Devices[i]; int nVarSize = (int)pDev->m_Vars.GetSize(); for( j = 0; j < nVarSize; j++ ) { CBaseVar *pBaseVar = pDev->m_Vars[j]; if( pBaseVar->m_strName.Compare(sVarName) == 0 ) { bRet = TRUE; return bRet; } } } LOG4C((LOG_NOTICE, "报警联动表里有不存在的变量:sVarName=%s",sVarName)); return bRet; } BOOL IsExistDev( CString sDevName )//判断设备是否存在 { if( sDevName=="" ) return FALSE; BOOL bRet = FALSE; int i, j; int nDeviceSize = (int)g_pDevicesManager->m_Devices.GetSize(); for( i = 0; i < nDeviceSize; i++ ) { CDevice *pDev = g_pDevicesManager->m_Devices[i]; if( pDev->m_strDeviceName.Compare(sDevName) == 0 ) { bRet = TRUE; return bRet; } } return bRet; }