#include "stdafx.h" #include "DaiKinProcess.h" #include "Global.h" #include "struct.h" #include "NoticeQueue.h" #define SET_RUN 1 // 设置空调运转(开/关) #define SET_RUN_MODE 2 // 设置空调运转模式(0:送风,1:制热,2:制冷,3:自动,4:换气清洗,7:除湿 #define SET_TEMP 3 // 设定温度 #define SET_FAN 4 // 设置风量 CRITICAL_SECTION g_csDaiKinReadOneData; char g_szDaiKinAnlogMsg[DAIKIN_MAX_MSG] = {0}; char g_szDaiKinDigitalMsg[DAIKIN_MAX_MSG] = {0}; char g_szDaiKinAlarmMsg[DAIKIN_MAX_MSG] = {0}; char g_szDaiKinGetParamMsg[DAIKIN_MAX_MSG] = {0}; //大金空调动态库输出函数 HINSTANCE g_hDaiKinLibModule = NULL; DAIKIN_DLLInitCom pDaiKin_DLLInitCom = NULL; DAIKIN_DLLInit pDaiKin_DLLInit = NULL; DAIKIN_DLLUnInit pDaiKin_DLLUnInit = NULL; DAIKIN_DLLSetParam pDaiKin_DLLSetParam = NULL; DAIKIN_DLLRemoteCtrl pDaiKin_DLLRemoteCtrl = NULL; int DaiKinCommandSend(); void UnInitDaiKinDll(); int GetDaiKinFromIni(char chCmd[32], int &nVer, int &nCid2, char chAdrBeginPos[MAX_ID], char chCmdLen[MAX_ID], char chDataLen[MAX_ID]); BOOL LoadDaiKinDll(CString strpath) { char strFile[256] = {0}; g_hDaiKinLibModule = NULL; sprintf(strFile, "%s\\dll\\Daikin.dll", strpath); InitializeCriticalSection( &g_csDaiKinReadOneData ); g_hDaiKinLibModule = AfxLoadLibrary(strFile); //大金空调动态库初始化 if (NULL != g_hDaiKinLibModule) { pDaiKin_DLLInitCom =( DAIKIN_DLLInitCom)::GetProcAddress(g_hDaiKinLibModule, "DAIKIN_DLLInitCom"); pDaiKin_DLLInit =(DAIKIN_DLLInit)::GetProcAddress(g_hDaiKinLibModule, "DAIKIN_DLLInit"); pDaiKin_DLLUnInit =(DAIKIN_DLLUnInit)::GetProcAddress(g_hDaiKinLibModule, "DAIKIN_DLLUnInit"); pDaiKin_DLLSetParam = (DAIKIN_DLLSetParam)::GetProcAddress(g_hDaiKinLibModule, "DAIKIN_DLLSetParam"); pDaiKin_DLLRemoteCtrl = (DAIKIN_DLLRemoteCtrl)::GetProcAddress(g_hDaiKinLibModule, "DAIKIN_DLLRemoteCtrl"); return TRUE; } else { return FALSE; } } BOOL InitDaiKinComm(int iAddr, int iPort, int iBaudrate, int iDataBit, int iStopBit, int iParity, int iIntervals) { if (pDaiKin_DLLInitCom(iAddr,iPort, iBaudrate, iDataBit, iStopBit, iParity, iIntervals))//初始化串口 return TRUE; else return FALSE; } int DaiKinRequestData( int nPort, int nDevAddr, char chDevUid[20], int iVarID, char chRs232cmd[32]) { char chMsg[80] = {0}; int nCid1 = 0x60; int nCid2; WORD wLenId = 0x00;//INFO字节长度 BYTE byCmdType = 0x00;//命令类型 BYTE byCmdId = 0x00; char byDataFlag = 0; char chAdrBeginPos[MAX_ID] = {0}; char chCmdLen[MAX_ID] = {0}; char chDataLen[MAX_ID] = {0}; int nVer; GetDaiKinFromIni((char*)(LPCTSTR)chRs232cmd, nVer, nCid2, chAdrBeginPos, chCmdLen, chDataLen); int nRet = -1; if( strlen(g_szDaiKinAnlogMsg) == 0 ) { int nRet = pDaiKin_DLLInit( nPort, //端口 nDevAddr, //设备地址 nVer, //版本号 nCid1, //控制标识码 nCid2, //命令信息 wLenId, //INFO字节长度 byCmdId, //命令ID atoi(chDataLen), //请求数据长度 atoi(chAdrBeginPos), //变量索引 atoi(chCmdLen), //变量长度 g_szDaiKinAnlogMsg, //读到变量值 &byDataFlag); //保留未用 if( nRet != 0 ) { return -1; } } if( strlen(g_szDaiKinDigitalMsg) == 0 ) { int nRet = pDaiKin_DLLInit( nPort, //端口 nDevAddr, //设备地址 nVer, //版本号 nCid1, //控制标识码 nCid2, //命令信息 wLenId, //INFO字节长度 byCmdId, //命令ID atoi(chDataLen), //请求数据长度 atoi(chAdrBeginPos), //变量索引 atoi(chCmdLen), //变量长度 g_szDaiKinDigitalMsg, //读到变量值 &byDataFlag); //保留未用 if( nRet != 0 ) { return -1; } } if( strlen(g_szDaiKinAlarmMsg) == 0 ) { int nRet = pDaiKin_DLLInit( nPort, //端口 nDevAddr, //设备地址 nVer, //版本号 nCid1, //控制标识码 nCid2, //命令信息 wLenId, //INFO字节长度 byCmdId, //命令ID atoi(chDataLen), //请求数据长度 atoi(chAdrBeginPos), //变量索引 atoi(chCmdLen), //变量长度 g_szDaiKinAlarmMsg, //读到变量值 &byDataFlag); //保留未用 if( nRet != 0 ) { return -1; } } if( strlen(g_szDaiKinGetParamMsg) == 0 ) { int nRet = pDaiKin_DLLInit( nPort, //端口 nDevAddr, //设备地址 nVer, //版本号 nCid1, //控制标识码 nCid2, //命令信息 wLenId, //INFO字节长度 byCmdId, //命令ID atoi(chDataLen), //请求数据长度 atoi(chAdrBeginPos), //变量索引 atoi(chCmdLen), //变量长度 g_szDaiKinGetParamMsg, //读到变量值 &byDataFlag); //保留未用 if( nRet != 0 ) { return -1; } } if( strcmp(chRs232cmd, "cmd-1") == 0 && strlen(g_szDaiKinAnlogMsg) > 0 ) { int nRet = pDaiKin_DLLInit( nPort, //端口 nDevAddr, //设备地址 nVer, //版本号 nCid1, //控制标识码 nCid2, //命令信息 wLenId, //INFO字节长度 byCmdId, //命令ID atoi(chDataLen), //请求数据长度 atoi(chAdrBeginPos), //变量索引 atoi(chCmdLen), //变量长度 g_szDaiKinAnlogMsg, //读到变量值 &byDataFlag); //保留未用 if( nRet != 0 ) { return -1; } } else if( strcmp(chRs232cmd, "cmd-2") == 0 && strlen(g_szDaiKinDigitalMsg) > 0 ) { int nRet = pDaiKin_DLLInit( nPort, //端口 nDevAddr, //设备地址 nVer, //版本号 nCid1, //控制标识码 nCid2, //命令信息 wLenId, //INFO字节长度 byCmdId, //命令ID atoi(chDataLen), //请求数据长度 atoi(chAdrBeginPos), //变量索引 atoi(chCmdLen), //变量长度 g_szDaiKinDigitalMsg, //读到变量值 &byDataFlag); //保留未用 if( nRet != 0 ) { return -1; } } else if( strcmp(chRs232cmd, "cmd-9") == 0 && strlen(g_szDaiKinAlarmMsg) > 0 ) { int nRet = pDaiKin_DLLInit( nPort, //端口 nDevAddr, //设备地址 nVer, //版本号 nCid1, //控制标识码 nCid2, //命令信息 wLenId, //INFO字节长度 byCmdId, //命令ID atoi(chDataLen), //请求数据长度 atoi(chAdrBeginPos), //变量索引 atoi(chCmdLen), //变量长度 g_szDaiKinAlarmMsg, //读到变量值 &byDataFlag); //保留未用 if( nRet != 0 ) { return -1; } } else if( strcmp(chRs232cmd, "cmd-11") == 0 && strlen(g_szDaiKinGetParamMsg) > 0 ) { int nRet = pDaiKin_DLLInit( nPort, //端口 nDevAddr, //设备地址 nVer, //版本号 nCid1, //控制标识码 nCid2, //命令信息 wLenId, //INFO字节长度 byCmdId, //命令ID atoi(chDataLen), //请求数据长度 atoi(chAdrBeginPos), //变量索引 atoi(chCmdLen), //变量长度 g_szDaiKinGetParamMsg, //读到变量值 &byDataFlag); //保留未用 if( nRet != 0 ) { return -1; } } if( strcmp(chRs232cmd, "cmd-1") == 0 ) { if( strlen(g_szDaiKinAnlogMsg) > 0 ) { for( int i = 0; i < atoi(chCmdLen); i++ ) { chMsg[i] = g_szDaiKinAnlogMsg[sizeof(CHILD) + atoi(chAdrBeginPos) + i]; } } } else if( strcmp(chRs232cmd, "cmd-2") == 0 || strcmp(chRs232cmd, "cmd-3") == 0 || strcmp(chRs232cmd, "cmd-4") == 0 || strcmp(chRs232cmd, "cmd-5") == 0 || strcmp(chRs232cmd, "cmd-6") == 0 || strcmp(chRs232cmd, "cmd-7") == 0 || strcmp(chRs232cmd, "cmd-8") == 0 ) { if( strlen(g_szDaiKinAlarmMsg) > 0 ) { for( int i = 0; i < atoi(chCmdLen); i++ ) { chMsg[i] = g_szDaiKinDigitalMsg[sizeof(CHILD) + atoi(chAdrBeginPos) + i]; } } } else if( strcmp(chRs232cmd, "cmd-9") == 0 ) { if( strlen(g_szDaiKinDigitalMsg) > 0 ) { for( int i = 0; i < atoi(chCmdLen); i++ ) { chMsg[i] = g_szDaiKinAlarmMsg[sizeof(CHILD) + atoi(chAdrBeginPos) + i]; } } } else if( strcmp(chRs232cmd, "cmd-11") == 0 || strcmp(chRs232cmd, "cmd-12") == 0 || strcmp(chRs232cmd, "cmd-13") == 0 || strcmp(chRs232cmd, "cmd-14") == 0 ) { if( strlen(g_szDaiKinGetParamMsg) > 0 ) { for( int i = 0; i < atoi(chCmdLen); i++ ) { chMsg[i] = g_szDaiKinGetParamMsg[sizeof(CHILD) + atoi(chAdrBeginPos) + i]; } } } if( strlen(chMsg) == 0 ) return -1; nRet = DaiKinSingleResponseData(chDevUid, iVarID, chMsg, byDataFlag, nCid2 ); return nRet; } int DaiKinSingleResponseData(char chDevUid[20], int iVarID, char chMsg[80], char byDataFlag, int nCid2) { int nDeviceIndex = -1, nVarIndex = -1; BOOL bFind = FindVar(chDevUid, iVarID, nDeviceIndex, nVarIndex); if( bFind == FALSE ) return -1; CDevice *pDev = g_pDevicesManager->m_Devices[nDeviceIndex]; CBaseVar *pBaseVar = pDev->m_Vars[nVarIndex]; EnterCriticalSection(&g_csDaiKinReadOneData); pDev->m_dwOnlineTick = GetTickCount(); LeaveCriticalSection(&g_csDaiKinReadOneData); DWORD nValue = 0; WORD wdValue = 0; double fCoef = pBaseVar->m_dbCoefficient; int nDataLen = pBaseVar->m_iDataLen; int nVarItemID = pBaseVar->m_nVarItemID; if( nVarItemID > 0 )//BIT位变量 { int nStartBit = pBaseVar->m_nStartBit; int nEndBit = pBaseVar->m_nEndBit; int nStartReg, nEndReg; if( nEndBit - nStartBit < 7 )// 一般告警状态会这样子定义,Modbus Rtu 码暂时没有碰到,没有经过调试,待测试 { if( nDataLen == 1 ) { char chBuffer[8] = {0}; memset(chBuffer, 0, sizeof(chBuffer)); nValue = (AsciiToBYTE(chMsg[0]) << 4) | ( AsciiToBYTE(chMsg[0 + 1]) & 0x00FF ); itoa(nValue, chBuffer, 2); CString strTemp; switch( nEndBit - nStartBit ) { case 0: strTemp.Format("%c", chBuffer[nStartBit]); break; case 1: strTemp.Format("%c%c", chBuffer[nStartBit], chBuffer[nStartBit + 1]); break; case 2: strTemp.Format("%c%c%c", chBuffer[nStartBit], chBuffer[nStartBit + 1], chBuffer[nStartBit + 2]); break; case 3: strTemp.Format("%c%c%c%c", chBuffer[nStartBit], chBuffer[nStartBit + 1], chBuffer[nStartBit + 2], chBuffer[nStartBit +3]); break; case 4: strTemp.Format("%c%c%c%c%c", chBuffer[nStartBit], chBuffer[nStartBit + 1], chBuffer[nStartBit + 2], chBuffer[nStartBit + 3], chBuffer[nStartBit + 4]); break; case 5: strTemp.Format("%c%c%c%c%c%c", chBuffer[nStartBit], chBuffer[nStartBit + 1], chBuffer[nStartBit + 2], chBuffer[nStartBit + 3], chBuffer[nStartBit + 4], chBuffer[nStartBit + 5]); break; case 6: strTemp.Format("%c%c%c%c%c%c%c", chBuffer[nStartBit], chBuffer[nStartBit + 1], chBuffer[nStartBit + 2], chBuffer[nStartBit + 3], chBuffer[nStartBit + 4], chBuffer[nStartBit + 5], chBuffer[nStartBit + 6]); break; } nValue = atoi(strTemp); } else if( nDataLen == 2 ) { char chBuffer[16] = {0}; memset(chBuffer, 0, sizeof(chBuffer)); nValue = ( ( (AsciiToBYTE(chMsg[0]) << 4) | ( AsciiToBYTE(chMsg[1]) & 0x00FF ) ) << 8 ) | ( ( (AsciiToBYTE(chMsg[2]) << 4) | ( AsciiToBYTE(chMsg[3]) & 0x00FF ) ) & 0x0000FFFF ); itoa(nValue, chBuffer, 2); CString strTemp; switch( nEndBit - nStartBit ) { case 0: strTemp.Format("%c", chBuffer[nStartBit]); break; case 1: strTemp.Format("%c%c", chBuffer[nStartBit], chBuffer[nStartBit + 1]); break; case 2: strTemp.Format("%c%c%c", chBuffer[nStartBit], chBuffer[nStartBit + 1], chBuffer[nStartBit + 2]); break; case 3: strTemp.Format("%c%c%c%c", chBuffer[nStartBit], chBuffer[nStartBit + 1], chBuffer[nStartBit + 2], chBuffer[nStartBit +3]); break; case 4: strTemp.Format("%c%c%c%c%c", chBuffer[nStartBit], chBuffer[nStartBit + 1], chBuffer[nStartBit + 2], chBuffer[nStartBit + 3], chBuffer[nStartBit + 4]); break; case 5: strTemp.Format("%c%c%c%c%c%c", chBuffer[nStartBit], chBuffer[nStartBit + 1], chBuffer[nStartBit + 2], chBuffer[nStartBit + 3], chBuffer[nStartBit + 4], chBuffer[nStartBit + 5]); break; case 6: strTemp.Format("%c%c%c%c%c%c%c", chBuffer[nStartBit], chBuffer[nStartBit + 1], chBuffer[nStartBit + 2], chBuffer[nStartBit + 3], chBuffer[nStartBit + 4], chBuffer[nStartBit + 5], chBuffer[nStartBit + 6]); break; } nValue = atoi(strTemp); } } // 特殊变量处理(例如,一个命令返回两个变量的情况) else if( nEndBit - nStartBit == 7 ) // 1个字节的情况 { nStartReg = (int)nStartBit / 8; nEndReg = (int)(nEndBit + 1) / 8; nValue = (AsciiToBYTE(chMsg[nStartReg]) << 4) | ( AsciiToBYTE(chMsg[nStartReg + 1]) & 0x00FF ); } else if( nEndBit - nStartBit == 15 ) // 2个字节的情况 { nStartReg = (int)nStartBit / 8; nEndReg = (int)(nEndBit + 1) / 8; nValue = ( ( (AsciiToBYTE(chMsg[nStartReg]) << 4) | ( AsciiToBYTE(chMsg[nStartReg + 1]) & 0x00FF ) ) << 8 ) | ( ( (AsciiToBYTE(chMsg[nStartReg + 2]) << 4) | ( AsciiToBYTE(chMsg[nStartReg + 3]) & 0x00FF ) ) & 0x0000FFFF ); } EnterCriticalSection( &g_csDaiKinReadOneData ); pBaseVar->m_dbData = (double)(nValue * fCoef); if( pBaseVar->m_nRearm != 0 ) { pBaseVar->m_dbData = pBaseVar->m_dbData + pBaseVar->m_nRearm; } LeaveCriticalSection( &g_csDaiKinReadOneData ); //TRACE2("变量ID%d, 值=%d\r\n", iVarID, nValue); } else { // 联合类型变量做特殊处理 if( pBaseVar->m_nVarTypeID >= UNION_TYPE_MIN_ID && pBaseVar->m_nVarTypeID <= UNION_TYPE_MAX_ID ) { if( nDataLen == 2 ) { //int类型 union __UNION_VAR_INT{ char ch[2]; int value; }unionVarInt; unionVarInt.ch[0] = (AsciiToBYTE(chMsg[0]) << 4) | (AsciiToBYTE(chMsg[1]) & 0x00FF); unionVarInt.ch[1] = (AsciiToBYTE(chMsg[2]) << 4) | (AsciiToBYTE(chMsg[3]) & 0x00FF); EnterCriticalSection( &g_csDaiKinReadOneData ); pBaseVar->m_dbData = (double)(unionVarInt.value * fCoef); if( pBaseVar->m_nRearm != 0 ) { pBaseVar->m_dbData = pBaseVar->m_dbData + pBaseVar->m_nRearm; } LeaveCriticalSection( &g_csDaiKinReadOneData ); //TRACE2("联合类型变量ID%d, 值=%d\r\n", iVarID, unionVarInt.value); } else if( nDataLen == 4 ) { //float类型 union __UNION_VAR_FLOAT{ char ch[4]; float value; }unionVarFloat; unionVarFloat.ch[0] = (AsciiToBYTE(chMsg[0]) << 4) | (AsciiToBYTE(chMsg[1]) & 0x00FF); unionVarFloat.ch[1] = (AsciiToBYTE(chMsg[2]) << 4) | (AsciiToBYTE(chMsg[3]) & 0x00FF); unionVarFloat.ch[2] = (AsciiToBYTE(chMsg[4]) << 4) | (AsciiToBYTE(chMsg[5]) & 0x00FF); unionVarFloat.ch[3] = (AsciiToBYTE(chMsg[6]) << 4) | (AsciiToBYTE(chMsg[7]) & 0x00FF); EnterCriticalSection( &g_csDaiKinReadOneData ); pBaseVar->m_dbData = (double)(unionVarFloat.value * fCoef); if( pBaseVar->m_nRearm != 0 ) { pBaseVar->m_dbData = pBaseVar->m_dbData + pBaseVar->m_nRearm; } LeaveCriticalSection( &g_csDaiKinReadOneData ); //TRACE2("联合类型变量ID%d, 值=%.1f\r\n", iVarID, unionVarFloat.value); } else if( nDataLen == 8 ) { //double类型 union __UNION_VAR_DOUBLE{ char ch[8]; double value; }unionVarDouble; unionVarDouble.ch[0] = (AsciiToBYTE(chMsg[0]) << 4) | (AsciiToBYTE(chMsg[1]) & 0x00FF); unionVarDouble.ch[1] = (AsciiToBYTE(chMsg[2]) << 4) | (AsciiToBYTE(chMsg[3]) & 0x00FF); unionVarDouble.ch[2] = (AsciiToBYTE(chMsg[4]) << 4) | (AsciiToBYTE(chMsg[5]) & 0x00FF); unionVarDouble.ch[3] = (AsciiToBYTE(chMsg[6]) << 4) | (AsciiToBYTE(chMsg[7]) & 0x00FF); unionVarDouble.ch[4] = (AsciiToBYTE(chMsg[8]) << 4) | (AsciiToBYTE(chMsg[9]) & 0x00FF); unionVarDouble.ch[5] = (AsciiToBYTE(chMsg[10]) << 4) | (AsciiToBYTE(chMsg[11]) & 0x00FF); unionVarDouble.ch[6] = (AsciiToBYTE(chMsg[12]) << 4) | (AsciiToBYTE(chMsg[13]) & 0x00FF); unionVarDouble.ch[7] = (AsciiToBYTE(chMsg[14]) << 4) | (AsciiToBYTE(chMsg[15]) & 0x00FF); EnterCriticalSection( &g_csDaiKinReadOneData ); pBaseVar->m_dbData = (double)(unionVarDouble.value * fCoef); if( pBaseVar->m_nRearm != 0 ) { pBaseVar->m_dbData = pBaseVar->m_dbData + pBaseVar->m_nRearm; } LeaveCriticalSection( &g_csDaiKinReadOneData ); //TRACE2("联合类型变量ID%d, 值=%.1f\r\n", iVarID, unionVarDouble.value); } } else { switch( nDataLen ) { case 1: nValue = AsciiToBYTE(chMsg[0]) << 4; break; case 2: nValue = (AsciiToBYTE(chMsg[0]) << 4) | ( AsciiToBYTE(chMsg[1]) & 0x00FF ); break; case 3: // 一般为字符串类型,不作处理 break; case 4: // 保留,暂时不知道什么处理 nValue = ( ( (AsciiToBYTE(chMsg[0]) << 4) | ( AsciiToBYTE(chMsg[1]) & 0x00FF ) ) << 8 ) | ( ( (AsciiToBYTE(chMsg[2]) << 4) | ( AsciiToBYTE(chMsg[3]) & 0x00FF ) ) & 0x0000FFFF ); break; case 5: // 一般为字符串类型,不作处理 break; case 6: // 一般为字符串类型,不作处理 break; case 7: // 一般为字符串类型,不作处理 break; case 8: // 保留,暂时没有用到 break; } EnterCriticalSection( &g_csDaiKinReadOneData ); if( pBaseVar->m_nMaxValues != 0 || pBaseVar->m_nMinValues != 0 || pBaseVar->m_nMaxConvtRate != 0 || pBaseVar->m_nMinConvtRate != 0 ) { double fScale = (double)(pBaseVar->m_nMaxConvtRate - pBaseVar->m_nMinConvtRate) / (double)(pBaseVar->m_nMaxValues - pBaseVar->m_nMinValues); pBaseVar->m_dbData = nValue * fCoef * fScale; } else { pBaseVar->m_dbData = (double)(nValue * fCoef); } if( pBaseVar->m_nRearm != 0 ) { pBaseVar->m_dbData = pBaseVar->m_dbData + pBaseVar->m_nRearm; } //g_RtuReadOneData.dbData = (double)(nValue * fCoef); LeaveCriticalSection( &g_csDaiKinReadOneData ); //TRACE2("普通变量ID%d, 值=%f\r\n", iVarID, g_ParadigmReadOneData.dbData); } } // g_RtuReadOneData.iStatus = GetVarstatus(g_RtuReadOneData.dbData, g_RtuReadOneData.iUpperlimit, g_RtuReadOneData.iLowerlimit, g_RtuReadOneData.iNormalstate); EnterCriticalSection(&g_csDaiKinReadOneData); pDev->m_dwOnlineTick = GetTickCount(); LeaveCriticalSection(&g_csDaiKinReadOneData); return 0; } void UnInitDaiKinDll() { if (g_hDaiKinLibModule != NULL && ( NULL != pDaiKin_DLLUnInit )) { pDaiKin_DLLUnInit(); } DeleteCriticalSection( &g_csDaiKinReadOneData ); if (g_hDaiKinLibModule!= NULL) { AfxFreeLibrary(g_hDaiKinLibModule); g_hDaiKinLibModule = NULL; } } int GetDaiKinFromIni(char chCmd[32], int &nVer, int &nCid2, char chAdrBeginPos[MAX_ID], char chCmdLen[MAX_ID], char chDataLen[MAX_ID]) { CHAR strFile[MAX_FILE_LENGTH + 1] = ""; CHAR strValue[MAX_VALUE_LENGTH + 1] = ""; CHAR strCid2[4] =""; CHAR strVer[10]={0}; CHAR strParaSum[4] = {0}; CHAR strParaIndex[4] = {0}; wsprintf(strFile, "%s\\config\\DaiKin.ini", g_strDirectory); //模块版本 GetPrivateProfileString("VER", "Ver", "", strVer, sizeof(strVer), strFile); //命令模块 GetPrivateProfileString(chCmd,"cmdModule", "", strValue, sizeof(strValue), strFile); //命令ID的参数索引 GetPrivateProfileString(chCmd, "Para_Index", "", strParaIndex, sizeof(strParaIndex), strFile); //命令长度 GetPrivateProfileString(chCmd, "cmdlen", "", chCmdLen, sizeof(chCmdLen), strFile); //命令的CID2 GetPrivateProfileString(chCmd, "Cid2", "", strCid2, sizeof(strCid2), strFile); //模块命令参数的数量 GetPrivateProfileString(strValue, "ParaSum", "", strParaSum, sizeof(strParaSum), strFile); //数据总长度 GetPrivateProfileString(strValue, "datalen", "", chDataLen, sizeof(chDataLen), strFile); //读:起始位置,写:设置命令 char ParaIndex[12]={0}; strcpy(ParaIndex, "para"); strcat(ParaIndex, strParaIndex); GetPrivateProfileString(strValue, ParaIndex, "", chAdrBeginPos, sizeof(chAdrBeginPos), strFile); nCid2 = atoi(strCid2); nVer = atoi(strVer); return 0; } int RequestDaiKinWrData(char chDevUid[20], int iVarID, double data, char chRs232cmd[32])//用于请求写命令操作 { int nDeviceIndex = -1, nVarIndex = -1; BOOL bFind = FindVar(chDevUid, iVarID, nDeviceIndex, nVarIndex); if( bFind == FALSE ) return -1; CDevice *pDev = g_pDevicesManager->m_Devices[nDeviceIndex]; CBaseVar *pBaseVar = pDev->m_Vars[nVarIndex]; if( strcmp(chRs232cmd, "cmd-15") == 0 || strcmp(chRs232cmd, "cmd-16") == 0 || strcmp(chRs232cmd, "cmd-17") == 0 || strcmp(chRs232cmd, "cmd-18") == 0 || strcmp(chRs232cmd, "cmd-19") == 0 || strcmp(chRs232cmd, "cmd-20") == 0 ) //设置参数 { char chMsg[80] = {0}; int nCid1 = 0x60; int nCid2; WORD wLenId = 0x00;//INFO字节长度 BYTE byCmdType = 0x00;//命令类型 BYTE byCmdId = 0x00; char byDataFlag = 0; char chAdrBeginPos[MAX_ID] = {0}; char chCmdLen[MAX_ID] = {0}; char chDataLen[MAX_ID] = {0}; int nVer; GetDaiKinFromIni((char*)(LPCTSTR)chRs232cmd, nVer, nCid2, chAdrBeginPos, chCmdLen, chDataLen); CHAR strFile[MAX_FILE_LENGTH + 1] = ""; CHAR strValue[MAX_VALUE_LENGTH + 1] = ""; wsprintf(strFile, "%s\\config\\DaiKin.ini", g_strDirectory); //模块版本 GetPrivateProfileString(chRs232cmd,"cmdType", "", strValue, sizeof(strValue), strFile); if( pDaiKin_DLLSetParam( pDev->m_iPort, pDev->m_iDevideaddr, nVer, nCid1, nCid2, atoi(chCmdLen), atoi(strValue), (int)data ) == 0 ) { return 0; } else { return -1; } } else if( strcmp(chRs232cmd, "cmd-21") == 0 ) //控制空调运转 { if( pDaiKin_DLLRemoteCtrl( pDev->m_iPort, pDev->m_iDevideaddr, SET_RUN, 0, (int)data ) == 0 ) { return 0; } else { return -1; } } else if( strcmp(chRs232cmd, "cmd-22") == 0 ) //控制运转模式 { if( pDaiKin_DLLRemoteCtrl( pDev->m_iPort, pDev->m_iDevideaddr, SET_RUN_MODE, 0, (int)data ) == 0 ) { return 0; } else { return -1; } } else if( strcmp(chRs232cmd, "cmd-23") == 0 ) //设定制冷温度 { if( pDaiKin_DLLRemoteCtrl( pDev->m_iPort, pDev->m_iDevideaddr, SET_TEMP, 0, (int)data ) == 0 ) { return 0; } else { return -1; } } else if( strcmp(chRs232cmd, "cmd-24") == 0 ) //设定制热温度 { if( pDaiKin_DLLRemoteCtrl( pDev->m_iPort, pDev->m_iDevideaddr, SET_TEMP, 1, (int)data ) == 0 ) { return 0; } else { return -1; } } else if( strcmp(chRs232cmd, "cmd-25") == 0 ) //设定制热风扇1风量 { if( pDaiKin_DLLRemoteCtrl( pDev->m_iPort, pDev->m_iDevideaddr, SET_FAN, 0, (int)data ) == 0 ) { return 0; } else { return -1; } } else if( strcmp(chRs232cmd, "cmd-26") == 0 ) //设定制热风扇2风量 { if( pDaiKin_DLLRemoteCtrl( pDev->m_iPort, pDev->m_iDevideaddr, SET_FAN, 1, (int)data ) == 0 ) { return 0; } else { return -1; } } else if( strcmp(chRs232cmd, "cmd-27") == 0 ) //设定制冷风扇1风量 { if( pDaiKin_DLLRemoteCtrl( pDev->m_iPort, pDev->m_iDevideaddr, SET_FAN, 2, (int)data ) == 0 ) { return 0; } else { return -1; } } else if( strcmp(chRs232cmd, "cmd-28") == 0 ) //设定制冷风扇2风量 { if( pDaiKin_DLLRemoteCtrl( pDev->m_iPort, pDev->m_iDevideaddr, SET_FAN, 3, (int)data ) == 0 ) { return 0; } else { return -1; } } return 0; }