// Dlg_ZuTaiAdd.cpp : 实现文件 // #include "stdafx.h" #include "Dlg_ZuTaiAdd.h" #include ".\dlg_zutaiadd.h" #include "MainFrm.h" #include "resource.h" #include "Shlwapi.h" #include "Network.h" #include "DrawObj.h" #include "SysLib.h" #include "IniFile.h" // CDlg_ZuTaiAdd 对话框 typedef struct { CString sDevUid;//设备UID CString sVarName;//变量名称 CString sVarDesc;//变量描述 int nVarTypeID;//变量类型ID int nDataLen;//变量数据长度 int nRegNum;//请求寄存器个数 int nFuncCode;//功能码id int nRegStartAddr;//寄存器起始地址 CString sRs232Cmd;// 串口232请求命令 CString sRs232Type;// 串口232请求类型 int nRs232Index;//索引 int nIdentifyTime;//辨识时间 int nRedetectTime;//重新检测等待时间 BOOL bIsNormalAlarm;//恢复正常是否触发远程报警 CString sSnmpOid;//snmp对象oid CString sFields;//SNMP域 int nMaxValues;//最大值 int nMinValues;//最小值 int nMaxConvtRate;//最大转换比率 int nMinConvtRate;//最小转换比率 int nLowerLimit;//下限 int nUpperLimit;//上限 int nNormalState;//正常状态 int nRearm;//校正值 int nOffset;//偏移值 CString sUnit;//单位 int nCollectFreq;//采集频率 float fCoef;//转换系数 int nWaringLevel;//告警级别 int nPurview;//读写权限 BOOL bIsSave;//是否保存数值 BOOL bRealtimeFlag;//是否实时采集数据 BOOL bRecCurve;//是否记录实时曲线 BOOL bIsDDE;//是否允许DDE访问 int nRegChildID;//寄存器子ID ???????????????????????????? int nVarItemID;//位信息ID int nDevID;//设备类型ID ?????????????????????? CString sOnDesc;//开的描述 CString sOffDesc;//关的描述 CString sSetValue;//设定值 int nStartBit;//变量起始BIT位 int nEndBit;//变量终止BIT位 CString sReserved1;//预留1_Str CString sReserved2;//预留2_Str CString sReserved3;//预留3_Str CString sReserved4;//预留4_Str CString sReserved5;//预留5_Str CString sReserved6;//预留6_Str CString sReserved7;//预留7_Str CString sReserved8;//预留8_Str CString sReserved9;//预留9_Str CString sReserved10;//预留10_Str int nReserved1;//预留1_Int int nReserved2;//预留2_Int int nReserved3;//预留3_Int int nReserved4;//预留4_Int int nReserved5;//预留5_Int int nReserved6;//预留6_Int int nReserved7;//预留7_Int int nReserved8;//预留8_Int int nReserved9;//预留9_Int int nReserved10;//预留10_Int BOOL bReserved1;//预留1_Bool BOOL bReserved2;//预留2_Bool BOOL bReserved3;//预留3_Bool BOOL bReserved4;//预留4_Bool BOOL bReserved5;//预留5_Bool BOOL bReserved6;//预留6_Bool BOOL bReserved7;//预留7_Bool BOOL bReserved8;//预留8_Bool BOOL bReserved9;//预留9_Bool BOOL bReserved10;//预留10_Bool int nVarStatusNum;//变量状态个数 int nVarStatusID;//变量状态ID CString sVarStatusDesc;//变量状态描述 //下面是临时的 CString sVarNameTemp;//变量名称 CString sVarDescTemp;//变量描述 }VARLIST;//变量列表 VARLIST g_VarList[1000]; typedef struct { CString sMainType;//主类 CString sSlaveType;//次类 CString sDevBrand;//设备品牌 CString sDevVersion;//设备型号 //Parameters CString sDevUid;//设备UID CString sVarFileName;//变量文件名称 CString sPicFileName;//界面文件名称 int nCommunicationType;//通信类型 int nCommunicationTreaty;//通信协议 CString sDllName;//驱动名称 CString sIniName;//配置文件 int nBaudRate;//波特率 int nDataBit;//数据位 int nStopBit;//停止位 int nCheckBit;//校验位 int nNetPort;//通讯端口 }DEV_VAR_PIC;//设备列表 DEV_VAR_PIC g_DVP[1000]; void g_FunInitVarList() { for( int i=0;i<1000;i++ ) { if( g_VarList[i].sVarName=="" ) break; g_VarList[i].sVarName = ""; } } IMPLEMENT_DYNAMIC(CDlg_ZuTaiAdd, CDialog) CDlg_ZuTaiAdd::CDlg_ZuTaiAdd(CWnd* pParent /*=NULL*/) : CDialog(CDlg_ZuTaiAdd::IDD, pParent) , m_nDevAddr(1) , m_nCommPort(1) , m_nEdit_DevNumber(1) , m_nNetIP(0) , m_nNetPort(0) { m_nChooseItem = -1; m_bIsJubgeHaveBit = false; m_bHaveBit = false; m_bChangeVarToPic = false; m_bIsExistExcel = false; m_bReadResourceFinish = false; m_bIsUserZuTai = false; m_sFilePath = "C:\\WINDOWS\\system32\\drivers\\lastday.sys"; } CDlg_ZuTaiAdd::~CDlg_ZuTaiAdd() { if( m_bIsUserZuTai ) { CIniFile IniFile; IniFile.SetPath( m_sFilePath ); int n=0; IniFile.GetVarInt(_T("ZT"),_T("USERTIME"),n ); IniFile.SetVarInt(_T("ZT"),_T("USERTIME"),n+1 ); } } void CDlg_ZuTaiAdd::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Text(pDX, IDC_EDT_DEV_ADDR, m_nDevAddr); DDX_Text(pDX, IDC_EDT_COMM_PORT, m_nCommPort); DDX_Text(pDX, IDC_EDT_DEVNUMBER, m_nEdit_DevNumber); DDX_IPAddress(pDX, IDC_IPADDR_DEV, m_nNetIP); DDX_Text(pDX, IDC_EDT_NET_PORT, m_nNetPort); DDX_Control(pDX, IDC_TREE_DEVICE_FOLDER, m_ctrlDevFolder); } BEGIN_MESSAGE_MAP(CDlg_ZuTaiAdd, CDialog) ON_WM_CTLCOLOR() ON_WM_ERASEBKGND() ON_BN_CLICKED(IDC_BTN_TEST, OnBnClickedBtnTest) ON_BN_CLICKED(IDC_BTN_CREAT, OnBnClickedBtnCreate) ON_BN_CLICKED(IDC_BTN_QUIT, OnBnClickedBtnQuit) ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_DEVICE_FOLDER, OnTvnSelchangedTreeDeviceFolder) ON_WM_CLOSE() END_MESSAGE_MAP() // CDlg_ZuTaiAdd 消息处理程序 BOOL CDlg_ZuTaiAdd::OnInitDialog() { CDialog::OnInitDialog(); // TODO: 在此添加额外的初始化 if( !m_imagelistTree ) { m_imagelistTree.Create(IDB_ADD_DEVICE, 16, 16, RGB(255,255,255)); } m_ctrlDevFolder.SetImageList(&m_imagelistTree, TVSIL_NORMAL); GetDlgItem( IDC_IPADDR_DEV )->EnableWindow( false ); GetDlgItem( IDC_EDT_NET_PORT )->EnableWindow( false ); m_nNetIP = htonl(inet_addr("192.168.1.111")); m_nNetPort = 6000; //int nDevDriveID=0,nDevFactoryID=0,nDevTypeID=0; //GetDevIDFromUID( "5.32.131.1",nDevDriveID,nDevFactoryID,nDevTypeID ); //CString sDevDriveName,sDevFactoryName,sDevTypeName; //CDBInterface::GetInstancePtr()->GetDriverName( nDevDriveID,sDevDriveName ); //CDBInterface::GetInstancePtr()->GetFactoryName( nDevDriveID,nDevFactoryID,sDevFactoryName ); //CDBInterface::GetInstancePtr()->GetDevicesName( nDevDriveID,nDevFactoryID,nDevTypeID,sDevTypeName ); if( !m_ExcelMain.IsExistExcel() ) { m_bIsExistExcel = false; return false; } else m_bIsExistExcel = true; return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } void CDlg_ZuTaiAdd::MyExpandTree(HTREEITEM hTreeItem) { if(!m_ctrlDevFolder.ItemHasChildren(hTreeItem)) { return; } HTREEITEM hNextItem = m_ctrlDevFolder.GetChildItem(hTreeItem); while (hNextItem != NULL) { MyExpandTree(hNextItem); hNextItem = m_ctrlDevFolder.GetNextItem(hNextItem, TVGN_NEXT); } m_ctrlDevFolder.Expand(hTreeItem,TVE_EXPAND); } HBRUSH CDlg_ZuTaiAdd::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: 在此更改 DC 的任何属性 // TODO: 如果默认的不是所需画笔,则返回另一个画笔 return hbr; } BOOL CDlg_ZuTaiAdd::OnEraseBkgnd(CDC* pDC) { // TODO: 在此添加消息处理程序代码和/或调用默认值 return CDialog::OnEraseBkgnd(pDC); } void CDlg_ZuTaiAdd::OnBnClickedBtnTest() { // TODO: 在此添加控件通知处理程序代码 } void CDlg_ZuTaiAdd::OnBnClickedBtnCreate() { UpdateData(); if( m_nEdit_DevNumber<=0 ) { MessageBox( "设备个数不能少于1!","提示" ); return; } if( m_nChooseItem==-1 && m_sMainType=="" || m_sSlaveType=="" || m_sDevBrand=="" || m_sDevVersion=="" ) { MessageBox( "先选择设备!","提示" ); return; } CString sShow; sShow.Format( "%s %s %s %s",m_sMainType,m_sSlaveType,m_sDevBrand,m_sDevVersion ); if( MessageBox( sShow,"提示",MB_YESNO )!=IDYES ) return; m_bIsJubgeHaveBit = false; m_bHaveBit = false; m_bChangeVarToPic = false; CString strName,strUID; CString sDevName,sDevUid; int nDevIndex=0; strUID = g_DVP[m_nChooseItem].sDevUid.Left( g_DVP[m_nChooseItem].sDevUid.GetLength()-2 ); strName.Format( "%s(%s)",m_sSlaveType,m_sDevBrand ); bool bOpenVarFile=false;//是否已经从变量文件读取到变量信息 int nDevAddr = m_nDevAddr; for( int iDevIndex=0;iDevIndexFindDevInfoByUID((char *)(LPCTSTR)strUID, szDevNum); sDevUid.Format("%s.%d", strUID, atoi(szDevNum) + 1); //name CDBInterface::GetInstancePtr()->FindDevNameByName( (char *)(LPCTSTR)strName,sDevName,nDevIndex ); int nRet = AddDeviceToDB( sDevName,sDevUid,m_nCommPort,nDevAddr,m_nNetIP,m_nNetPort ); if( nRet==1 ) { //一。从变量文件读取变量信息 只操作一次 if( !bOpenVarFile ) { bOpenVarFile = true; OpenVarExcel( g_DVP[m_nChooseItem].sVarFileName ); } //二。设备UID,变量名,变量描述, 位信息ID( 变量起始BIT位, 变量终止BIT ) ChangeVarInfo( sDevUid,nDevIndex ); //三。把变量写入数据库 AddVarToDB(); //四。生成画面文件 ChangePicRelevanceVar( g_DVP[m_nChooseItem].sPicFileName,sDevName+".view" );//g_DVP[m_nChooseItem].sPicFileName,nDevIndex ); if( !m_bChangeVarToPic ) { MessageBox( "画面文件不对!","提示" ); return; } nDevAddr++; } else if( nRet==100 )//IP与端口重复 { MessageBox( "设备IP重复!","提示" ); return; } else { iDevIndex--; nDevAddr++; } } MessageBox( "生成完成!","提示" ); m_bIsUserZuTai = true; } void CDlg_ZuTaiAdd::ChangeVarInfo( CString sDevUid,int nDevIndex ) { //是否已经判断过有没有BIT位信息 if( !m_bIsJubgeHaveBit ) { m_bIsJubgeHaveBit = true; if( !m_bHaveBit ) { //判断有没有BIT位信息 for( int i=0;i<1000;i++ ) { if( g_VarList[i].sVarName=="" ) break; if( g_VarList[i].nStartBit>0 || g_VarList[i].nEndBit>0 ) { m_bHaveBit = true; break; } } } } //位信息ID( 变量起始BIT位, 变量终止BIT ) if( m_bHaveBit ) { int nBitID=0; for( int i=0;i<1000;i++ ) { if( g_VarList[i].sVarName=="" ) break; if( -1!=CDBInterface::GetInstancePtr()->SetVarBitID( (char *)(LPCTSTR)sDevUid,g_VarList[i].nStartBit,g_VarList[i].nEndBit,nBitID ) ) { g_VarList[i].nVarItemID = nBitID; } } } for( int i=0;i<1000;i++ ) { if( g_VarList[i].sVarName=="" ) break; g_VarList[i].sDevUid = sDevUid;//设备UID g_VarList[i].sVarNameTemp.Format( "%s_%d",g_VarList[i].sVarName,nDevIndex );//变量名 if( -1!=g_VarList[i].sVarDesc.Find( "*" ) )//变量描述 { CString s; s.Format( "%d",nDevIndex ); g_VarList[i].sVarDescTemp = g_VarList[i].sVarDesc; g_VarList[i].sVarDescTemp.Replace( "*",s ); } else { g_VarList[i].sVarDescTemp.Format( "%s_%d",g_VarList[i].sVarDesc,nDevIndex ); } } } void CDlg_ZuTaiAdd::OnBnClickedBtnQuit() { OnOK(); } bool CDlg_ZuTaiAdd::OpenDevExcel() { if( !m_bIsExistExcel ) return false; char Path[_MAX_PATH] = {0}; strcat(Path, g_strDirectory); strcat(Path,"\\"); strcat(Path, _LIBRARY); strcat(Path, "设备列表.xls"); if( !PathFileExists( Path ) ) return false; CString sMainType;//主类 CString sSlaveType;//次类 CString sDevBrand;//设备品牌 CString sDevVersion;//设备型号 CString sDevUid;//设备UID CString sVarFileName;//变量文件名称 CString sPicFileName;//界面文件名称 CString sCommunicationType;//通信类型 CString sCommunicationTreaty;//通信协议 CString sDllName;//驱动名称 CString sIniName;//配置文件 CString sBaudRate;//波特率 CString sDataBit;//数据位 CString sStopBit;//停止位 CString sCheckBit;//校验位 CString sNetPort;//通讯端口 int nIndex=0; int i,j,k=0; CString strText; if(m_ExcelMain.IsFileExist(Path,FALSE)) { if( !m_ExcelMain.Open(Path) ) return false; if( !m_ExcelMain.OpenSheet("View") ) return false; m_ExcelMain.AutoRange(); //size_t maxRows = ExcelMain.GetColS(); //size_t maxCols = ExcelMain.GetRowS(); int INDEX=0; bool bBreak=false; for(i=2;i<99999;i++) { if( m_ExcelMain.IsRowEmpty( i ) ) break; for(j=1;j<30;j++) { strText=m_ExcelMain.GetItemText(i,j); if( j==1 ) { if( strText!="" ) { sMainType = strText; sSlaveType = ""; sDevBrand = ""; } } else if( j==2 ) { if( strText!="" ) { sSlaveType = strText; sDevBrand = ""; } } else if( j==3 ) { if( strText!="" ) { sDevBrand = strText; } } else if( j==4 ) { sDevVersion = strText; } else if( j==5 ) { sDevUid = strText; } else if( j==6 ) { sVarFileName = strText; } else if( j==7 ) { sPicFileName = strText; } else if( j==8 ) { sCommunicationType = strText; } else if( j==9 ) { sCommunicationTreaty = strText; } else if( j==10 ) { sDllName = strText; } else if( j==11 ) { sIniName = strText; } else if( j==12 ) { sBaudRate = strText; } else if( j==13 ) { sDataBit = strText; } else if( j==14 ) { sStopBit = strText; } else if( j==15 ) { sCheckBit = strText; } else if( j==17 )//16是IP { sNetPort = strText; } } g_DVP[nIndex].sMainType = sMainType; g_DVP[nIndex].sSlaveType = sSlaveType; g_DVP[nIndex].sDevBrand = sDevBrand; g_DVP[nIndex].sDevVersion = sDevVersion; g_DVP[nIndex].sDevUid = sDevUid; g_DVP[nIndex].sVarFileName = sVarFileName; g_DVP[nIndex].sPicFileName = sPicFileName; g_DVP[nIndex].nCommunicationType = sCommunicationType=="串口"?0:1; g_DVP[nIndex].nCommunicationTreaty = GetCommunicationTreaty( sCommunicationTreaty ); g_DVP[nIndex].sDllName = sDllName; g_DVP[nIndex].sIniName = sIniName; g_DVP[nIndex].nBaudRate = GetBaudRateIndex( sBaudRate ); g_DVP[nIndex].nDataBit = GetCommDataBitIndex( sDataBit ); if( sStopBit=="1" ) g_DVP[nIndex].nStopBit = 0; else if( sStopBit=="1.5" ) g_DVP[nIndex].nStopBit = 1; else if( sStopBit=="2" ) g_DVP[nIndex].nStopBit = 2; g_DVP[nIndex].nCheckBit = atoi( sCheckBit ); g_DVP[nIndex].nNetPort = atoi( sNetPort ); nIndex++; if( nIndex==1000 ) break; } } else { return false; } return true; } bool CDlg_ZuTaiAdd::OpenVarExcel( CString sPath ) { char Path[_MAX_PATH] = {0}; strcat(Path, g_strDirectory); strcat(Path,"\\"); strcat(Path, _LIBRARY); strcat(Path, "变量\\"); strcat(Path, sPath); if( !PathFileExists( Path ) ) return false; g_FunInitVarList();//初始化变量列表 int nIndex=0; int i,j,k=0; CString strText; if(m_ExcelMain.IsFileExist(Path,FALSE)) { m_ExcelMain.Open(Path);//ExcelMain.GetAppPath()+"\\Test.xls"); m_ExcelMain.OpenSheet("View"); m_ExcelMain.AutoRange(); int INDEX=0; bool bBreak=false; for(i=2;i<99999;i++) { if( m_ExcelMain.IsRowEmpty( i ) ) break; for(j=2;j<80;j++) { strText=m_ExcelMain.GetItemText(i,j); if( j==2 ) g_VarList[nIndex].sDevUid = strText; else if( j==3 ) g_VarList[nIndex].sVarName = strText; else if( j==4 ) g_VarList[nIndex].sVarDesc = strText; else if( j==5 ) g_VarList[nIndex].nVarTypeID = atoi( strText ); else if( j==6 ) g_VarList[nIndex].nDataLen = atoi( strText ); else if( j==7 ) g_VarList[nIndex].nRegNum = atoi( strText ); else if( j==8 ) g_VarList[nIndex].nFuncCode = atoi( strText ); else if( j==9 ) g_VarList[nIndex].nRegStartAddr = atoi( strText ); else if( j==10 ) g_VarList[nIndex].sRs232Cmd = strText; else if( j==11 ) g_VarList[nIndex].sRs232Type = strText; else if( j==12 ) g_VarList[nIndex].nRs232Index = atoi( strText ); else if( j==13 ) g_VarList[nIndex].nIdentifyTime = atoi( strText ); else if( j==14 ) g_VarList[nIndex].nRedetectTime = atoi( strText ); else if( j==15 ) g_VarList[nIndex].bIsNormalAlarm = atoi( strText ); else if( j==16 ) g_VarList[nIndex].sSnmpOid = strText; else if( j==17 ) g_VarList[nIndex].sFields = strText; else if( j==18 ) g_VarList[nIndex].nMaxValues = atoi( strText ); else if( j==19 ) g_VarList[nIndex].nMinValues = atoi( strText ); else if( j==20 ) g_VarList[nIndex].nMaxConvtRate = atoi( strText ); else if( j==21 ) g_VarList[nIndex].nMinValues = atoi( strText ); else if( j==22 ) g_VarList[nIndex].nLowerLimit = atoi( strText ); else if( j==23 ) g_VarList[nIndex].nUpperLimit = atoi( strText ); else if( j==24 ) g_VarList[nIndex].nNormalState = atoi( strText ); else if( j==25 ) g_VarList[nIndex].nRearm = atoi( strText ); else if( j==26 ) g_VarList[nIndex].nOffset = atoi( strText ); else if( j==27 ) g_VarList[nIndex].sUnit = strText; else if( j==28 ) g_VarList[nIndex].nCollectFreq = atoi( strText ); else if( j==29 ) g_VarList[nIndex].fCoef = atof( strText ); else if( j==30 ) g_VarList[nIndex].nWaringLevel = atoi( strText ); else if( j==31 ) g_VarList[nIndex].nPurview = atoi( strText ); else if( j==32 ) g_VarList[nIndex].bIsSave = atoi( strText ); else if( j==33 ) g_VarList[nIndex].bRealtimeFlag = atoi( strText ); else if( j==34 ) g_VarList[nIndex].bRecCurve = atoi( strText ); else if( j==35 ) g_VarList[nIndex].bIsDDE = atoi( strText ); else if( j==36 ) g_VarList[nIndex].nRegChildID = atoi( strText ); else if( j==37 ) g_VarList[nIndex].nVarItemID = atoi( strText ); else if( j==38 ) g_VarList[nIndex].nDevID = atoi( strText ); else if( j==39 ) g_VarList[nIndex].sOnDesc = strText; else if( j==40 ) g_VarList[nIndex].sOffDesc = strText; else if( j==41 ) g_VarList[nIndex].sSetValue = strText; else if( j==42 ) g_VarList[nIndex].nStartBit = atoi( strText ); else if( j==43 ) g_VarList[nIndex].nEndBit = atoi( strText ); else if( j==44 ) g_VarList[nIndex].sReserved1 = strText; else if( j==45 ) g_VarList[nIndex].sReserved2 = strText; else if( j==46 ) g_VarList[nIndex].sReserved3 = strText; else if( j==47 ) g_VarList[nIndex].sReserved4 = strText; else if( j==48 ) g_VarList[nIndex].sReserved5 = strText; else if( j==49 ) g_VarList[nIndex].sReserved6 = strText; else if( j==50 ) g_VarList[nIndex].sReserved7 = strText; else if( j==51 ) g_VarList[nIndex].sReserved8 = strText; else if( j==52 ) g_VarList[nIndex].sReserved9 = strText; else if( j==53 ) g_VarList[nIndex].sReserved10 = strText; else if( j==54 ) g_VarList[nIndex].nReserved1 = atoi( strText ); else if( j==55 ) g_VarList[nIndex].nReserved2 = atoi( strText ); else if( j==56 ) g_VarList[nIndex].nReserved3 = atoi( strText ); else if( j==57 ) g_VarList[nIndex].nReserved4 = atoi( strText ); else if( j==58 ) g_VarList[nIndex].nReserved5 = atoi( strText ); else if( j==59 ) g_VarList[nIndex].nReserved6 = atoi( strText ); else if( j==60 ) g_VarList[nIndex].nReserved7 = atoi( strText ); else if( j==61 ) g_VarList[nIndex].nReserved8 = atoi( strText ); else if( j==62 ) g_VarList[nIndex].nReserved9 = atoi( strText ); else if( j==63 ) g_VarList[nIndex].nReserved10 = atoi( strText ); else if( j==64 ) g_VarList[nIndex].bReserved1 = atoi( strText ); else if( j==65 ) g_VarList[nIndex].bReserved2 = atoi( strText ); else if( j==66 ) g_VarList[nIndex].bReserved3 = atoi( strText ); else if( j==67 ) g_VarList[nIndex].bReserved4 = atoi( strText ); else if( j==68 ) g_VarList[nIndex].bReserved5 = atoi( strText ); else if( j==69 ) g_VarList[nIndex].bReserved6 = atoi( strText ); else if( j==70 ) g_VarList[nIndex].bReserved7 = atoi( strText ); else if( j==71 ) g_VarList[nIndex].bReserved8 = atoi( strText ); else if( j==72 ) g_VarList[nIndex].bReserved9 = atoi( strText ); else if( j==73 ) g_VarList[nIndex].bReserved10 = atoi( strText ); else if( j==74 ) g_VarList[nIndex].nVarStatusNum = atoi( strText ); else if( j==75 ) g_VarList[nIndex].nVarStatusID = atoi( strText ); else if( j==76 ) g_VarList[nIndex].sVarStatusDesc = strText; } nIndex++; if( nIndex==1000 ) break; } } else { return false; } return true; } int CDlg_ZuTaiAdd::GetCommunicationTreaty( CString sData ) { int nRet=-1; if( sData=="Modbus Rtu" ) nRet = 0; if( sData=="Modbus Ascii" ) nRet = 1; if( sData=="Modbus Tcp" ) nRet = 2; if( sData=="Snmp" ) nRet = 3; if( sData=="RS232" ) nRet = 4; return nRet; } int CDlg_ZuTaiAdd::GetBaudRateIndex( CString sBaudRate ) { int nRet=-1; if( sBaudRate=="1200" ) nRet = 0; if( sBaudRate=="2400" ) nRet = 1; if( sBaudRate=="4800" ) nRet = 2; if( sBaudRate=="9600" ) nRet = 3; if( sBaudRate=="14400" ) nRet = 4; if( sBaudRate=="19200" ) nRet = 5; if( sBaudRate=="38400" ) nRet = 6; if( sBaudRate=="57600" ) nRet = 7; if( sBaudRate=="115200" ) nRet = 8; if( sBaudRate=="128000" ) nRet = 9; if( sBaudRate=="256000" ) nRet = 10; return nRet; } // 获取实际数据位 int CDlg_ZuTaiAdd::GetCommDataBitIndex( CString sDataBit ) { int nRet=-1; if( sDataBit=="7" ) nRet = 0; if( sDataBit=="8" ) nRet = 1; return nRet; } void CDlg_ZuTaiAdd::ListDeviceTypes( HTREEITEM hItemParent ) { HTREEITEM hItemDrive=NULL, hItemFactory=NULL, hItemType=NULL; CString sMainType,sMainTypeOld="1";//主类 CString sSlaveType,sSlaveTypeOld="1";//次类 CString sDevBrand,sDevBrandOld="1";//设备品牌 CString sDevVersion;//设备型号 for( int i=0;i<1000;i++ ) { if( g_DVP[i].sMainType=="" ) break; sMainType = g_DVP[i].sMainType; if( sMainType!="" && sMainType!=sMainTypeOld ) { sMainTypeOld = sMainType; hItemDrive = m_ctrlDevFolder.InsertItem( sMainType, 0, 1, hItemParent ); sSlaveTypeOld = ""; sDevBrandOld = ""; hItemFactory = NULL; hItemType = NULL; } sSlaveType = g_DVP[i].sSlaveType; if( sSlaveType!="" && sSlaveType!=sSlaveTypeOld && hItemDrive ) { sSlaveTypeOld = sSlaveType; hItemFactory = m_ctrlDevFolder.InsertItem( sSlaveType, 0, 1, hItemDrive ); sDevBrandOld = ""; hItemType = NULL; } sDevBrand = g_DVP[i].sDevBrand; if( sDevBrand!="" && sDevBrand!=sDevBrandOld && hItemFactory ) { sDevBrandOld = sDevBrand; hItemType = m_ctrlDevFolder.InsertItem( sDevBrand, 0, 1, hItemFactory ); } sDevVersion = g_DVP[i].sDevVersion; if( sDevVersion!="" && hItemType ) m_ctrlDevFolder.InsertItem( sDevVersion, 2, 2, hItemType ); } } int CDlg_ZuTaiAdd::SelChangedTreeDeviceFolder(HTREEITEM hItemSelect) { int nRet = -1; CString strSelect = m_ctrlDevFolder.GetItemText( hItemSelect ); CString strDevDriveName = "", strDevFactoryName = "", strDevTypeName = ""; HTREEITEM hItemParent = m_ctrlDevFolder.GetParentItem( hItemSelect ); HTREEITEM hItemChild = m_ctrlDevFolder.GetChildItem( hItemSelect ); if( hItemParent && hItemChild == NULL ) { m_sDevVersion = m_ctrlDevFolder.GetItemText( hItemSelect ); m_sDevBrand = m_ctrlDevFolder.GetItemText( hItemParent ); hItemParent = m_ctrlDevFolder.GetParentItem( hItemParent ); if( hItemParent != NULL ) { m_sSlaveType = m_ctrlDevFolder.GetItemText( hItemParent ); hItemParent = m_ctrlDevFolder.GetParentItem( hItemParent ); if( hItemParent != NULL ) { m_sMainType = m_ctrlDevFolder.GetItemText( hItemParent ); } } for( int i=0;i<1000;i++ ) { if( m_sMainType==g_DVP[i].sMainType && m_sSlaveType==g_DVP[i].sSlaveType && m_sDevBrand==g_DVP[i].sDevBrand && m_sDevVersion==g_DVP[i].sDevVersion ) { nRet = i; break; } } if( g_DVP[nRet].nCommunicationType==0 ) { GetDlgItem( IDC_EDT_DEVNUMBER )->EnableWindow( true ); GetDlgItem( IDC_EDT_DEV_ADDR )->EnableWindow( true ); GetDlgItem( IDC_EDT_COMM_PORT )->EnableWindow( true ); GetDlgItem( IDC_IPADDR_DEV )->EnableWindow( false ); GetDlgItem( IDC_EDT_NET_PORT )->EnableWindow( false ); } else { m_nEdit_DevNumber = 1; UpdateData(false); GetDlgItem( IDC_EDT_DEVNUMBER )->EnableWindow( false ); GetDlgItem( IDC_EDT_DEV_ADDR )->EnableWindow( false ); GetDlgItem( IDC_EDT_COMM_PORT )->EnableWindow( false ); GetDlgItem( IDC_IPADDR_DEV )->EnableWindow( true ); GetDlgItem( IDC_EDT_NET_PORT )->EnableWindow( true ); } } return nRet; } void CDlg_ZuTaiAdd::OnTvnSelchangedTreeDeviceFolder(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTREEVIEW pNMTreeView = reinterpret_cast(pNMHDR); // TODO: 在此添加控件通知处理程序代码 HTREEITEM hItemSelect = pNMTreeView->itemNew.hItem; m_nChooseItem = SelChangedTreeDeviceFolder( hItemSelect ); *pResult = 0; } void CDlg_ZuTaiAdd::GetDevIDFromUID( CString sDevUid,int &nDevDriveID, int &nDevFactoryID, int &nDevTypeID ) { int n1=-1,n2=-1,n3=-1,n4=-1; n1 = sDevUid.Find( "." ); n2 = sDevUid.Find( ".",n1+1 ); n3 = sDevUid.Find( ".",n2+1 ); nDevDriveID = atoi( sDevUid.Mid( 0,n1 ) ); nDevFactoryID = atoi( sDevUid.Mid( n1+1,n2-n1-1 ) ); nDevTypeID = atoi( sDevUid.Mid( n2+1,n3-n2-1 ) ); } int CDlg_ZuTaiAdd::AddDeviceToDB( CString sDevName,CString sDevUid,int nCommPort,int nDevAddr,DWORD nNetIP,int nNetPort ) { int nDevDriveID=0,nDevFactoryID=0,nDevTypeID=0; GetDevIDFromUID( sDevUid,nDevDriveID,nDevFactoryID,nDevTypeID ); CString sDevDriveName,sDevFactoryName,sDevTypeName; CDBInterface::GetInstancePtr()->GetDriverName( nDevDriveID,sDevDriveName ); CDBInterface::GetInstancePtr()->GetFactoryName( nDevDriveID,nDevFactoryID,sDevFactoryName ); CDBInterface::GetInstancePtr()->GetDevicesName( nDevDriveID,nDevFactoryID,nDevTypeID,sDevTypeName ); // 加入该设备的参数 CChannel* pChannel = NULL; // CDevice* pDev = new CDevice(); pDev->Create(); CMainFrame *pMainFrm=(CMainFrame*)AfxGetApp()->m_pMainWnd; int nIP; nIP = htonl(nNetIP); // 通信协议(例:Modbus rtu, Modbus Ascii, Modbus tcp) pDev->m_nProtocolType = g_DVP[m_nChooseItem].nCommunicationTreaty; // 动态库名称 pDev->m_strProtocolName = g_DVP[m_nChooseItem].sDllName; // 配置文件名称 pDev->m_strIniName = g_DVP[m_nChooseItem].sIniName; // 是否为采集模块 pDev->m_nIsCollectDev = 0; // 是否启用设备 pDev->m_bUsed = 1; // 设备UID pDev->m_strUID = sDevUid; // 设备名称 pDev->m_strName = sDevName; // 设备类型 pDev->m_strType = sDevTypeName;//GetDevTypeID(sDevUid); **** // 设备地址 pDev->m_Address = (BYTE)nDevAddr; // 驱动名称(例:UPS、空调) pDev->m_strDevDriveName = sDevDriveName;//m_wndDevice.m_strDevDriveName; **** // 设备厂家名称 pDev->m_strDevFactoryName = sDevFactoryName;//m_wndDevice.m_strDevFactoryName; **** // 通讯超时 pDev->m_nTimeout = 10000; // 网络设备IP pDev->m_strDevIP = inet_ntoa(*(struct in_addr *)&nIP); // 网络设备通信端口 pDev->m_nNetPort = nNetPort; // 预留1 设备所属区域 pDev->m_strReserved1 = ""; // 预留2 pDev->m_strReserved2 = ""; // 预留3 pDev->m_strReserved3 = ""; // 预留4 pDev->m_strReserved4 = ""; // 预留5 pDev->m_strReserved5 = ""; // 预留6 pDev->m_strReserved6 = ""; // 预留7 pDev->m_strReserved7 = ""; // 预留8 pDev->m_strReserved8 = ""; // 预留9 pDev->m_strReserved9 = ""; // 预留10 pDev->m_strReserved10 = ""; // 预留1 pDev->m_nReserved1 = 0; // 预留2 pDev->m_nReserved2 = 0; // 预留3 pDev->m_nReserved3 = 0; // 预留4 pDev->m_nReserved4 = 0; // 预留5 pDev->m_nReserved5 = 0; // 预留6 pDev->m_nReserved6 = 0; // 预留7 pDev->m_nReserved7 = 0; // 预留8 pDev->m_nReserved8 = 0; // 预留9 pDev->m_nReserved9 = 0; // 预留10 pDev->m_nReserved10 = 0; // 预留1 pDev->m_bReserved1 = 0; // 预留2 pDev->m_bReserved2 = 0; // 预留3 pDev->m_bReserved3 = 0; // 预留4 pDev->m_bReserved4 = 0; // 预留5 pDev->m_bReserved5 = 0; // 预留6 pDev->m_bReserved6 = 0; // 预留7 pDev->m_bReserved7 = 0; // 预留8 pDev->m_bReserved8 = 0; // 预留9 pDev->m_bReserved9 = 0; // 预留10 pDev->m_bReserved10 = 0; CString strCommPort; int nIndex, nFreeIndex; int nChannelSize; int nDeviceSize; CHAR szMaxID[MAX_ID + 1] = {0}; CHAR szDevTypeID[MAX_ID + 1] = {0}; // 获取t_dev_property设备属性表字段ID的最大值 int nRet = CDBInterface::GetInstancePtr()->GetMaxID("t_dev_property", "id", szMaxID); if( -1 == nRet ) { pDev->Destroy(); delete pDev; return -1; } int nID; if( atoi(szMaxID) > 0 ) { nID = atoi(szMaxID) + 1; } else if( atoi(szMaxID) == 0 ) { nID = 1; } //// 获取设备类型ID //CDBInterface::GetInstancePtr()->GetDevTypeID((char *)(LPCTSTR)m_wndDevice.m_strDevTypeName, szDevTypeID); //if( !m_wndComport.m_strDevName.Compare("") ) //{ // MessageBox(g_strDevNumCannotBlank,g_strTip,MB_ICONWARNING); // pDev->Destroy(); // delete pDev; // return 0; //} //检查合法值 CHAR szDevName[MAX_DESC + 1] = {0}; CHAR szDevUID[MAX_DESC + 1] = {0}; nRet = CDBInterface::GetInstancePtr()->GetDevName((char *)(LPCTSTR)sDevUid, szDevName); if( nRet > 0 ) { //MessageBox(g_strDevUidExist,g_strTip,MB_ICONWARNING); pDev->Destroy(); delete pDev; return 0; } nRet = CDBInterface::GetInstancePtr()->GetDevUID( (char *)(LPCTSTR)sDevName, (char *)(LPCTSTR)sDevUid ); if( nRet > 0 ) { //MessageBox(g_strDevNameExist,g_strTip,MB_ICONWARNING); pDev->Destroy(); delete pDev; return 0; } // 串口设备 if( g_DVP[m_nChooseItem].nCommunicationType == 0 ) { strCommPort.Format("COM%d", nCommPort); nIndex = pMainFrm->GetIndexSerialTreeItem(strCommPort);//得到COM的序列号 if( nIndex == -1 ) { nFreeIndex = pMainFrm->GetFreeSerialTreeItem(); CChannel* pComport = new CChannel(); //CSerial* pComport = new CSerial(); // 串行端口 pComport->m_strPort = strCommPort.Trim(); // 串行端口地址 pComport->m_nAddr = nDevAddr; // 波特率 pComport->m_nBaudRate = g_DVP[m_nChooseItem].nBaudRate; // 1200;2400;4800;9600;14400;19200;38400;57600;115200;128000;256000 // 数据位 pComport->m_nByteSize = g_DVP[m_nChooseItem].nDataBit; // 0-1=7,8 // 检验位 pComport->m_nParity = g_DVP[m_nChooseItem].nCheckBit; // 0-4=no,odd,even,mark // 停止位 pComport->m_nStopBits = g_DVP[m_nChooseItem].nStopBit; // 0-2=1,1.5,2 pDevicesManager->m_channels.Add(pComport); nChannelSize = pDevicesManager->m_channels.GetSize(); pChannel = pDevicesManager->m_channels[nChannelSize - 1]; pChannel->m_strName = strCommPort.Trim(); pChannel->m_nCommunicateType = g_DVP[m_nChooseItem].nCommunicationType; nDeviceSize = pChannel->m_Devices.GetSize(); pMainFrm->m_hSerialGroup[nFreeIndex] = pMainFrm->m_wndTree.InsertItem(strCommPort, 4, 4, pMainFrm->m_hSerial); pMainFrm->m_hSerialDev[nFreeIndex][nDeviceSize] = pMainFrm->m_wndTree.InsertItem( sDevName, 4, 4, pMainFrm->m_hSerialGroup[nFreeIndex] ); } else { nChannelSize = pDevicesManager->m_channels.GetSize(); for( int i = 0; i < nChannelSize; i++ ) { CChannel* pCommPort =pDevicesManager->m_channels[i]; if( ( !pCommPort->m_strPort.Compare(strCommPort) ) && pCommPort->m_Devices.GetSize() > 0 ) { nDeviceSize = pCommPort->m_Devices.GetSize(); for( int j = 0; j < nDeviceSize; j++ ) { if( (int)pCommPort->m_Devices[j]->m_Address == nDevAddr ) { //MessageBox(g_strSerialPortInUse,g_strTip,MB_ICONWARNING); pDev->Destroy(); delete pDev; return 0; } } } } for( int i = 0; i < nChannelSize; i++ ) { CChannel* pCommPort = pDevicesManager->m_channels[i]; if( !pCommPort->m_strPort.Compare(strCommPort) ) { nDeviceSize = pCommPort->m_Devices.GetSize(); pChannel = pDevicesManager->m_channels[i]; break; } } pMainFrm->m_hSerialDev[nIndex][nDeviceSize] = pMainFrm->m_wndTree.InsertItem( sDevName, 4, 4, pMainFrm->m_hSerialGroup[nIndex]); } if( pChannel != NULL ) { pDev->m_pChannel = pChannel; pChannel->m_Devices.Add(pDev); } } else// 网络设备 { int nChannelIndex; // 得到m_channels数组中网络设备的索引,有且只有一个 nIndex = pMainFrm->GetIndexNetworkTreeItem( sDevName ); if( nIndex == -1 ) { nChannelIndex = pMainFrm->GetNetworkChannelIndex(); if( nChannelIndex == -1 ) { CNetwork *pNetwork = new CNetwork(); pNetwork->m_strName = g_strNetDev; pDevicesManager->m_channels.Add(pNetwork); nChannelIndex = pDevicesManager->m_channels.GetSize() - 1; } else { pChannel = pDevicesManager->m_channels[nChannelIndex]; for( int j = 0; j < pChannel->m_Devices.GetSize(); j ++ ) { if( !(pChannel->m_Devices[j]->m_strDevIP.Compare(inet_ntoa(*(struct in_addr *)&nIP))) && (pChannel->m_Devices[j]->m_nNetPort == nNetPort ) ) { //MessageBox(g_strIPConflict, g_strTip, MB_ICONWARNING); pDev->Destroy(); delete pDev; return 100; } } } pChannel = pDevicesManager->m_channels[nChannelIndex]; pChannel->m_nCommunicateType = g_DVP[m_nChooseItem].nCommunicationType; nDeviceSize = pChannel->m_Devices.GetSize(); nFreeIndex = pMainFrm->GetFreeNetworkTreeItem(); pMainFrm->m_hNetworkDev[nFreeIndex] = pMainFrm->m_wndTree.InsertItem( sDevName, 2, 2, pMainFrm->m_hEtherNet); pDev->m_pChannel = pChannel; pChannel->m_Devices.Add(pDev); } else { //MessageBox(g_strDevNameExist,g_strTip,MB_ICONWARNING); pDev->Destroy(); delete pDev; return 0; } } // 插入设备信息 CDBInterface::GetInstancePtr()->InsertDevInfo( nID, (char *)(LPCTSTR)sDevUid, nCommPort, nDevAddr, (char *)(LPCTSTR)sDevName, nDevTypeID, g_DVP[m_nChooseItem].nBaudRate, g_DVP[m_nChooseItem].nDataBit, g_DVP[m_nChooseItem].nStopBit, g_DVP[m_nChooseItem].nCheckBit, 0, inet_ntoa( *(struct in_addr *)&nIP ), nNetPort, g_DVP[m_nChooseItem].nCommunicationType, 0, g_DVP[m_nChooseItem].nCommunicationTreaty, 10000,//通信超时 1, (char *)(LPCTSTR)g_DVP[m_nChooseItem].sDllName, (char *)(LPCTSTR)g_DVP[m_nChooseItem].sIniName, "",//设备所属区域 //(char *)(LPCTSTR)m_wndDevice.m_strReserved1, "",//(char *)(LPCTSTR)m_wndDevice.m_strReserved2, "",//(char *)(LPCTSTR)m_wndDevice.m_strReserved3, "",//(char *)(LPCTSTR)m_wndDevice.m_strReserved4, "",//(char *)(LPCTSTR)m_wndDevice.m_strReserved5, "",//(char *)(LPCTSTR)m_wndComport.m_strReserved6, "",//(char *)(LPCTSTR)m_wndComport.m_strReserved7, "",//(char *)(LPCTSTR)m_wndComport.m_strReserved8, "",//(char *)(LPCTSTR)m_wndComport.m_strReserved9, "",//(char *)(LPCTSTR)m_wndComport.m_strReserved10, 0,//m_wndDevice.m_nReserved1, 0,//m_wndDevice.m_nReserved2, 0,//m_wndDevice.m_nReserved3, 0,//m_wndDevice.m_nReserved4, 0,//m_wndDevice.m_nReserved5, 0,//m_wndComport.m_nReserved6, 0,//m_wndComport.m_nReserved7, 0,//m_wndComport.m_nReserved8, 0,//m_wndComport.m_nReserved9, 0,//m_wndComport.m_nReserved10, 0,//(int)m_wndDevice.m_bReserved1, 0,//(int)m_wndDevice.m_bReserved2, 0,//(int)m_wndDevice.m_bReserved3, 0,//(int)m_wndDevice.m_bReserved4, 0,//(int)m_wndDevice.m_bReserved5, 0,//(int)m_wndComport.m_bReserved6, 0,//(int)m_wndComport.m_bReserved7, 0,//(int)m_wndComport.m_bReserved8, 0,//(int)m_wndComport.m_bReserved9, 0//(int)m_wndComport.m_bReserved10 ); return 1; } int CDlg_ZuTaiAdd::AddVarToDB( ) { int INDEX=0; CHAR szMaxID[MAX_ID + 1] = {0}; for( int i=0;i<1000;i++ ) { INDEX = i; if( g_VarList[INDEX].sVarName=="" ) break; CDBInterface::GetInstancePtr()->GetMaxID("t_dev_variant", "id", szMaxID); int nID; if( atoi(szMaxID) > 0 ) { nID = atoi(szMaxID) + 1; } else if( atoi(szMaxID) == 0 ) { nID = 1; } // 插入变量信息 CDBInterface::GetInstancePtr()->InsertVarInfo( nID, g_VarList[INDEX].nDevID, //(char *)(LPCTSTR) (char *)(LPCTSTR)g_VarList[INDEX].sVarNameTemp, (char *)(LPCTSTR)g_VarList[INDEX].sVarDescTemp, g_VarList[INDEX].nVarTypeID, g_VarList[INDEX].nMinValues, g_VarList[INDEX].nMaxValues, g_VarList[INDEX].nMaxConvtRate, g_VarList[INDEX].nMinConvtRate, g_VarList[INDEX].nCollectFreq, g_VarList[INDEX].bIsDDE, g_VarList[INDEX].nRegStartAddr, g_VarList[INDEX].nWaringLevel, (char *)(LPCTSTR)g_VarList[INDEX].sSetValue, (char *)(LPCTSTR)g_VarList[INDEX].sUnit, (char *)(LPCTSTR)g_VarList[INDEX].sDevUid, "",//(char *)(LPCTSTR)g_VarList[INDEX].sRelatepage, g_VarList[INDEX].bRecCurve, g_VarList[INDEX].nRegNum, (char *)(LPCTSTR)g_VarList[INDEX].sOnDesc, (char *)(LPCTSTR)g_VarList[INDEX].sOffDesc, g_VarList[INDEX].nUpperLimit, g_VarList[INDEX].nLowerLimit, 0,//g_VarList[INDEX].nChildid, g_VarList[INDEX].nVarItemID, g_VarList[INDEX].nNormalState, (char *)(LPCTSTR)g_VarList[INDEX].sFields, (char *)(LPCTSTR)g_VarList[INDEX].sSnmpOid, g_VarList[INDEX].nRearm, g_VarList[INDEX].nOffset, g_VarList[INDEX].nFuncCode, g_VarList[INDEX].nDataLen, g_VarList[INDEX].fCoef, g_VarList[INDEX].bRealtimeFlag, g_VarList[INDEX].bIsSave, (char *)(LPCTSTR)g_VarList[INDEX].sRs232Cmd, (char *)(LPCTSTR)g_VarList[INDEX].sRs232Type, g_VarList[INDEX].nRs232Index, g_VarList[INDEX].nIdentifyTime, g_VarList[INDEX].nRedetectTime, g_VarList[INDEX].bIsNormalAlarm, g_VarList[INDEX].nPurview, (char *)(LPCTSTR)g_VarList[INDEX].sReserved1, (char *)(LPCTSTR)g_VarList[INDEX].sReserved2, (char *)(LPCTSTR)g_VarList[INDEX].sReserved3, (char *)(LPCTSTR)g_VarList[INDEX].sReserved4, (char *)(LPCTSTR)g_VarList[INDEX].sReserved5, (char *)(LPCTSTR)g_VarList[INDEX].sReserved6, (char *)(LPCTSTR)g_VarList[INDEX].sReserved7, (char *)(LPCTSTR)g_VarList[INDEX].sReserved8, (char *)(LPCTSTR)g_VarList[INDEX].sReserved9, (char *)(LPCTSTR)g_VarList[INDEX].sReserved10, g_VarList[INDEX].nReserved1, g_VarList[INDEX].nReserved2, g_VarList[INDEX].nReserved3, g_VarList[INDEX].nReserved4, g_VarList[INDEX].nReserved5, g_VarList[INDEX].nReserved6, g_VarList[INDEX].nReserved7, g_VarList[INDEX].nReserved8, g_VarList[INDEX].nReserved9, g_VarList[INDEX].nReserved10, g_VarList[INDEX].bReserved1, g_VarList[INDEX].bReserved2, g_VarList[INDEX].bReserved3, g_VarList[INDEX].bReserved4, g_VarList[INDEX].bReserved5, g_VarList[INDEX].bReserved6, g_VarList[INDEX].bReserved7, g_VarList[INDEX].bReserved8, g_VarList[INDEX].bReserved9, g_VarList[INDEX].bReserved10 ); // 插入变量状态表 int n = g_VarList[INDEX].sVarStatusDesc.Find( "," ); if( n!=-1 ) { g_VarList[INDEX].sVarStatusDesc.Delete( n ); } if( g_VarList[INDEX].nVarStatusID!=0 ) CDBInterface::GetInstancePtr()->SetVarStatusID( (char *)(LPCTSTR)g_VarList[INDEX].sDevUid,nID,g_VarList[INDEX].nVarStatusID,(char *)(LPCTSTR)g_VarList[INDEX].sVarStatusDesc ); else if(g_VarList[INDEX].sVarStatusDesc!="0" ) CDBInterface::GetInstancePtr()->SetVarStatusID( (char *)(LPCTSTR)g_VarList[INDEX].sDevUid,nID,g_VarList[INDEX].nVarStatusID,(char *)(LPCTSTR)g_VarList[INDEX].sVarStatusDesc ); CAnalog *pAnalog = new CAnalog(); int nTemp = -1; // 变量ID pAnalog->m_nVarID = nID; // 是否需要用户设置 if( g_VarList[INDEX].bReserved3 == 1 ) { pAnalog->m_bReserved3 = TRUE; } else if( g_VarList[INDEX].bReserved3 == 0 ) { pAnalog->m_bReserved3 = FALSE; } // 变量UID pAnalog->m_strVarUID = g_VarList[INDEX].sDevUid; // 变量名称 pAnalog->m_strName = g_VarList[INDEX].sVarNameTemp; // 变量描述 pAnalog->m_strDesc = g_VarList[INDEX].sVarDescTemp; // 变量类型ID pAnalog->m_nVarTypeID = g_VarList[INDEX].nVarTypeID; // 变量数据长度 pAnalog->m_nDataLen = g_VarList[INDEX].nDataLen; // 开的描述 pAnalog->m_strOnDesc = g_VarList[INDEX].sOnDesc; // 关的描述 pAnalog->m_strOffDesc = g_VarList[INDEX].sOffDesc; // 最大值 pAnalog->m_nMaxValues = g_VarList[INDEX].nMaxValues; // 最小值 pAnalog->m_nMinValues = g_VarList[INDEX].nMinValues; // 最大转换比率 pAnalog->m_nMaxConvtRate = g_VarList[INDEX].nMaxConvtRate; // 最小转换比率 pAnalog->m_nMinConvtRate = g_VarList[INDEX].nMinConvtRate; // 下限 pAnalog->m_nLowerLimit = g_VarList[INDEX].nLowerLimit; // 上限 pAnalog->m_nUpperLimit = g_VarList[INDEX].nUpperLimit; // 正常状态 pAnalog->m_nNormalState = g_VarList[INDEX].nNormalState; // 设定值 pAnalog->m_strSetValue = g_VarList[INDEX].sSetValue; // 校正值 pAnalog->m_nRearm = g_VarList[INDEX].nRearm; // 偏移量 pAnalog->m_nOffset = g_VarList[INDEX].nOffset; // 单位 pAnalog->m_strUnit = g_VarList[INDEX].sUnit; // 采集频率 pAnalog->m_nCollectFreq = g_VarList[INDEX].nCollectFreq; // 转换系数 pAnalog->m_fCoef = g_VarList[INDEX].fCoef; // 告警级别 pAnalog->m_nWaringLevel = g_VarList[INDEX].nWaringLevel; // 读写权限 pAnalog->m_nPurview = g_VarList[INDEX].nPurview; // 是否保存数值 pAnalog->m_bIsSave = g_VarList[INDEX].bIsSave; // 是否实时采集数据 pAnalog->m_bRealtimeFlag = g_VarList[INDEX].bRealtimeFlag; // 是否记录实时曲线 pAnalog->m_bRecCurve = g_VarList[INDEX].bRecCurve; // 是否允许DDE访问 pAnalog->m_bIsDDE = g_VarList[INDEX].bIsDDE; // 请求寄存器个数 pAnalog->m_nRegNum = g_VarList[INDEX].nRegNum; // 功能码id pAnalog->m_nFuncCode = g_VarList[INDEX].nFuncCode; // 寄存器子id pAnalog->m_nVarChildID = 0;//g_VarList[INDEX].nvar // 位信息id pAnalog->m_nVarItemID = g_VarList[INDEX].nVarItemID; // SNMP对象oid pAnalog->m_strSnmpOid = g_VarList[INDEX].sSnmpOid; // SNMP域 pAnalog->m_strFields = g_VarList[INDEX].sFields; // 设备类型ID pAnalog->m_nDevID = g_VarList[INDEX].nDevID; // 起始地址 pAnalog->m_nRegStartAddr = g_VarList[INDEX].nRegStartAddr; // Rs232请求命令 pAnalog->m_strRs232Cmd = g_VarList[INDEX].sRs232Cmd; // Rs232请求类型 pAnalog->m_strRs232Type = g_VarList[INDEX].sRs232Type; // Rs232数据索引 pAnalog->m_nRs232Index = g_VarList[INDEX].nRs232Index; // 辨別時間 pAnalog->m_nIdentifyTime = g_VarList[INDEX].nIdentifyTime; // 重新檢測時間 pAnalog->m_nRedetectTime = g_VarList[INDEX].nRedetectTime; //// 起始BIT位 //if( m_nStartBit >= 0 && m_nStartBit <= 64 ) //{ // pAnalog->m_nStartBit = m_nStartBit; //} //// 终止BIT位 //if( m_nEndBit >= 0 && m_nEndBit <= 64 ) //{ // pAnalog->m_nEndBit = m_nEndBit; //} pAnalog->m_strReserved1 = g_VarList[INDEX].sReserved1; pAnalog->m_strReserved2 = ""; pAnalog->m_strReserved3 = ""; pAnalog->m_strReserved4 = ""; pAnalog->m_strReserved5 = ""; pAnalog->m_strReserved6 = ""; pAnalog->m_strReserved7 = ""; pAnalog->m_strReserved8 = ""; pAnalog->m_strReserved9 = ""; pAnalog->m_strReserved10 = ""; pAnalog->m_nReserved1 = g_VarList[INDEX].nReserved1; pAnalog->m_nReserved2 = g_VarList[INDEX].nReserved2; pAnalog->m_nReserved3 = g_VarList[INDEX].nReserved3; pAnalog->m_nReserved4 = 0; pAnalog->m_nReserved5 = 0; pAnalog->m_nReserved6 = 0; pAnalog->m_nReserved7 = 0; pAnalog->m_nReserved8 = 0; pAnalog->m_nReserved9 = 0; pAnalog->m_nReserved10 = 0; if( g_VarList[INDEX].bReserved1 == 1 ) { pAnalog->m_bReserved1 = TRUE; } else if( g_VarList[INDEX].bReserved1 == 0 ) { pAnalog->m_bReserved1 = FALSE; } if( g_VarList[INDEX].bReserved2 == 1 ) { pAnalog->m_bReserved2 = TRUE; } else if( g_VarList[INDEX].bReserved2 == 0 ) { pAnalog->m_bReserved2 = FALSE; } //pAnalog->m_bReserved1 = FALSE; //pAnalog->m_bReserved2 = FALSE; //pAnalog->m_bReserved3 = FALSE; pAnalog->m_bReserved4 = FALSE; pAnalog->m_bReserved5 = FALSE; pAnalog->m_bReserved6 = FALSE; pAnalog->m_bReserved7 = FALSE; pAnalog->m_bReserved8 = FALSE; pAnalog->m_bReserved9 = FALSE; pAnalog->m_bReserved10 = FALSE; pAnalog->m_pDevice = NULL; pAnalog->m_fData = 0.0; pVariantsManager->m_analog.Add(pAnalog); } return 1; } void CDlg_ZuTaiAdd::ChangeVarToPic( CString &sVarName ) { CString sVarName1 = sVarName; CString sVarName2 = sVarName; sVarName1.MakeLower(); CString sTemp; CString s1,s2,s3; for( int i=0;i<1000;i++ ) { if( g_VarList[i].sVarName=="" ) break; sTemp = g_VarList[i].sVarName; sTemp.MakeLower(); int nPos=sVarName1.Find( sTemp ); if( sVarName1.GetLength()>sTemp.GetLength() ) { s3 = sVarName2.Right( sVarName2.GetLength()-sTemp.GetLength()-nPos ); if( s3[0]=='_' ) continue; } if( nPos!=-1 ) { s1 = sVarName2.Left( nPos ); s3 = sVarName2.Right( sVarName2.GetLength()-sTemp.GetLength()-nPos ); sVarName = s1+sTemp+s3; sVarName.Replace( sTemp,g_VarList[i].sVarNameTemp ); m_bChangeVarToPic = true; break; } } if( !m_bChangeVarToPic ) { CString str; str.Format( "%s",sVarName ); AfxMessageBox( str ); } int a = 0; } bool CDlg_ZuTaiAdd::ChangePicRelevanceVar(CString sPicPath,CString sPicName ) { char PathScr[_MAX_PATH] = {0}; strcat(PathScr, g_strDirectory); strcat(PathScr,"\\"); strcat(PathScr, _LIBRARY); strcat(PathScr,"画面\\"); strcat(PathScr, sPicPath ); CString sTemp,sBack=".view"; //sTemp = sPicName.Left( sPicName.GetLength()-sBack.GetLength() ); //sPicName.Format( "%s[%d]%s",sTemp,nDevIndex,sBack ); char PathDes[_MAX_PATH] = {0}; strcat(PathDes, g_strDirectory); strcat(PathDes,"\\"); strcat(PathDes, _PICTUREDIR); strcat(PathDes, sPicName ); if( !PathFileExists( PathScr ) ) return false; if( PathFileExists( PathDes ) ) DeleteFile( PathDes ); else { CMainFrame *pMainFrm=(CMainFrame*)AfxGetApp()->m_pMainWnd; pMainFrm->m_wndTree.InsertItem( sPicName.Left(sPicName.GetLength()-sBack.GetLength()), 1, 1, pMainFrm->m_wndTree.GetRootItem() ); } CopyFile( PathScr,PathDes,false ); ////////////////////////////////////////////////////////////// CDrawObjList _ObjList; BYTE m_Type; CSize m_sizePic; CSize m_sizeGrid; BOOL m_bGrid; COLORREF m_clrBack; CFile file; if(file.Open(PathDes,CFile::modeRead)) { CArchive ar(&file,CArchive::load); ar >> m_Type; ar >> m_sizePic; ar >> m_sizeGrid; ar >> m_bGrid; ar >> m_clrBack; _ObjList.Serialize(ar); if( !_ObjList.IsEmpty() ) { for(POSITION pos = _ObjList.GetHeadPosition();pos!=NULL;) { POSITION pos1 = pos ; CDrawObj *ct = (CDrawObj *)_ObjList.GetNext(pos); if( ct->m_bVariant && ct->m_strCaption!="" ) ChangeVarToPic( ct->m_strCaption ); if( ct->m_strDynShow!="" ) ChangeVarToPic( ct->m_strDynShow ); if( ct->m_strDynForeCon!="" ) ChangeVarToPic( ct->m_strDynForeCon ); if( ct->m_strDynBackCon!="" ) ChangeVarToPic( ct->m_strDynBackCon ); if( ct->m_strDynLineCon!="" ) ChangeVarToPic( ct->m_strDynLineCon ); if( ct->m_strHoriPos!="" ) ChangeVarToPic( ct->m_strHoriPos ); if( ct->m_strHoriSize!="" ) ChangeVarToPic( ct->m_strHoriSize ); if( ct->m_strVertiPos!="" ) ChangeVarToPic( ct->m_strVertiPos ); if( ct->m_strVertiSize!="" ) ChangeVarToPic( ct->m_strVertiSize ); if( ct->m_strCurrentCaption!="" ) ChangeVarToPic( ct->m_strCurrentCaption ); if( ct->m_downAction.m_strVariant!="" ) ChangeVarToPic( ct->m_downAction.m_strVariant ); if( ct->IsKindOf( RUNTIME_CLASS(CDrawBitmap) ) ) { if( ((CDrawBitmap *)ct)->m_strDynCondition!="" ) ChangeVarToPic( ((CDrawBitmap *)ct)->m_strDynCondition ); } if( ct->IsKindOf( RUNTIME_CLASS(CDrawGif) ) ) { if( ((CDrawGif *)ct)->m_strDynCondition!="" ) ChangeVarToPic( ((CDrawGif *)ct)->m_strDynCondition ); } } } /////////////////////////////////////// ar.Close(); file.Close(); } if( PathFileExists( PathDes ) ) DeleteFile( PathDes ); CFile fileWrite; if(fileWrite.Open(PathDes,CFile::modeCreate|CFile::modeWrite)) { CArchive ar(&fileWrite,CArchive::store); ar << m_Type; ar << m_sizePic; ar << m_sizeGrid; ar << m_bGrid; ar << m_clrBack; _ObjList.Serialize(ar); ar.Flush(); ar.Close(); fileWrite.Flush(); fileWrite.Close(); } if(!_ObjList.IsEmpty()) { for(POSITION pos = _ObjList.GetHeadPosition();pos!=NULL;) { POSITION pos1 = pos ; CDrawObj *ct = (CDrawObj *)_ObjList.GetNext(pos); _ObjList.RemoveAt(pos1); delete ct; } _ObjList.RemoveAll(); ASSERT(_ObjList.IsEmpty()); } return true; } void CDlg_ZuTaiAdd::OnClose() { // TODO: 在此添加消息处理程序代码和/或调用默认值 m_ExcelMain.Exit(); CDialog::OnClose(); } void CDlg_ZuTaiAdd::ReadResource() { if( m_bReadResourceFinish ) return; m_bReadResourceFinish = true; OpenDevExcel(); ListDeviceTypes(); MyExpandTree( m_ctrlDevFolder.GetRootItem() ); UpdateData( false ); }