123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- #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;
- }
|