123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762 |
- #include "stdafx.h"
- #include "ascprocess.h"
- #include "Global.h"
- #include "struct.h"
- #include <stdlib.h>
- #include "BaseVar.h"
- #include "Device.h"
- #include <process.h>
- #include "NoticeQueue.h"
- //#include <Afxdll_.h>
- //#ifndef _AFXDLL
- //#error file must be compiled with _AFXDLL
- //#endif
- HANDLE g_ASCResponseThread = NULL;
- //HANDLE g_ASCRequestThread[2];
- HANDLE g_ASCRequestThread = NULL;
- CRITICAL_SECTION g_csAscReadOneData;
- BOOL LoadAscDLL(CString strpath, int iNumberdll);
- BOOL InitAscComm(int iAddr, int iPort, int iBaudrate, int iDataBit, int iStopBit, int iParity, int iIntervals);
- int AscCommandSend();
- int AscResponseValue();
- int AscSingleResponseSpecialVarData(char chDevUid[20], int iVarID, int iSpecialFlag);//用于只响应一次命令特殊变量的数据
- int AscSingleResponseData(char chDevUid[20], int iVarID);
- int AscRequestData(SETBASEPARAM SetBasePara,
- char chDataLen[4],
- char chPort[4],
- char chAddr[4],
- char chDevUid[20], int iVarid);//用于只发送一次读命令变量的请求
- int AscRequestSpecData(char chDevUid[20], int iVarID, int iSpecialFlag);//用于只发送一次读命令特殊变量的请求
- int AscRequestWrData(char chDevUid[20], int iVarID, double data);//用于请求写命令操作
- void InitAscDll(SETBASEPARAM SetBasePara, int iPort, int iBaudrate);//
- void UnInitAscDll();
- int GetVarstatus(double iParaValue, int iUpperLimit, int iLowerLimit, int iNormalState);
- CString SpecLineWarnAndWater(CBaseVar *pBaseVar, int iSpecialFlag, char chMsg[80]);
- CString SpecLineWeihuMakeWaterDianzhuFz(CBaseVar *pBaseVar, int iSpecialFlag, char chMsg[80]);
- CString LDSSpecLineWarnAndWater(CBaseVar *pBaseVar, int iSpecialFlag, char chMsg[80]);
- //ASC 动态库输出函数
- HINSTANCE g_hASCLibModule;// = NULL;
- ASC_DLLInitCom pASCDLLInitCom;// = NULL;
- ASC_DLLInit pASCDLLInit = NULL;
- ASC_DLLUnInit pASCDLLUnInit;// = NULL;
- ASC_DLLRequestStatusData pASCDLLRequestStatusData = NULL;
- //ASC_DLLDetectOnlineCallBack pASCDLLDetectOnlineCallBack = NULL;
- ASC_DLLWrCom pASC_DLLWrCom = NULL;
- ASC_DLLRequestWrStatusData pASC_DLLRequestWrStatusData = NULL;
- BOOL LoadAscDLL(CString strpath)
- {
- TCHAR strFile[MAX_PATH] = {0};
- g_hASCLibModule = NULL;
- _stprintf_s(strFile, _T("%s\\dll\\modbusasc.dll"), strpath);
- InitializeCriticalSection( &g_csAscReadOneData );
- g_hASCLibModule = AfxLoadLibrary(strFile);//::LoadLibrary(strFile);
- //ASC 动态库初始化
- if (NULL != g_hASCLibModule)
- {
- pASC_DLLWrCom = (ASC_DLLWrCom)::GetProcAddress(g_hASCLibModule, "ASC_DLLWrCom");
- pASCDLLInitCom = (ASC_DLLInitCom)::GetProcAddress(g_hASCLibModule, "ASC_DLLInitCom");
- pASCDLLInit = (ASC_DLLInit)::GetProcAddress(g_hASCLibModule, "ASC_DLLInit");
- pASCDLLUnInit = (ASC_DLLUnInit)::GetProcAddress(g_hASCLibModule, "ASC_DLLUnInit");
- pASCDLLRequestStatusData = (ASC_DLLRequestStatusData)::GetProcAddress(g_hASCLibModule, "ASC_DLLRequestStatusData");
- pASC_DLLRequestWrStatusData = (ASC_DLLRequestWrStatusData)::GetProcAddress(g_hASCLibModule, "ASC_DLLRequestWrStatusData");
-
- return TRUE;
- }
- return FALSE;
- }
- BOOL InitAscComm(int iAddr, int iPort, int iBaudrate, int iDataBit, int iStopBit, int iParity, int iIntervals)
- {
- // 是否加载了动态库和函数地址;
- if ( g_hASCLibModule == NULL || pASCDLLInitCom == NULL )
- return FALSE;
- // 初始化串口;
- return pASCDLLInitCom(iAddr,iPort, iBaudrate, iDataBit, iStopBit, iParity, iIntervals);
- }
- int AscRequestData( SETBASEPARAM SetBasePara,
- int nDataLen,
- int nPort,
- int nDevAddr,
- char chDevUid[20],
- int iVarid)
- {
- // 是否加载了动态库和函数地址(这里应该再判断是否初始化了串口);
- if ( g_hASCLibModule == NULL || pASCDLLInit == NULL )
- return -1;
- char chMsg[80] = {0};
- int nRet = pASCDLLInit(nPort, nDevAddr, SetBasePara, nDataLen, chMsg);
- if (nRet == 0)
- {
- // 响应数据;
- nRet = AscSingleResponseData(chDevUid, iVarid, chMsg);
- }
- return nRet;
- }
- //用于只发送一次读命令特殊变量的请求
- int AscRequestSpecData(char chDevUid[20], int iVarID, int iSpecialFlag)
- {
- if ( g_hASCLibModule == NULL || pASCDLLInit == NULL )
- return -1;
- SETBASEPARAM SetBasePara;
- char chMsg[80] = {0};
- char chDataLen[4] = {0};
-
- int nDeviceIndex = -1;
-
- nDeviceIndex = FindDevice(chDevUid);
- if( nDeviceIndex == -1 ) return -1;
- CDevice *pDev = g_pDevicesManager->m_Devices[nDeviceIndex];
- SetBasePara.nAddr = pDev->m_iDevideaddr;
- if ((iSpecialFlag == 10000) || (iSpecialFlag == 10001))// 读取维护、漏水电阻阀值
- {
- SetBasePara.FuncCode = 0x04;
- SetBasePara.nStartAddr = 0x02;
- SetBasePara.nRegNum = 0x01;
- strcpy(chDataLen, "9");
- }
- else if ((iSpecialFlag == 10002) || (iSpecialFlag == 10003))
- {
- SetBasePara.FuncCode = 0x03;
- SetBasePara.nStartAddr = 0x2C;
- SetBasePara.nRegNum = 0x02;
- strcpy(chDataLen, "4");
- }
- else if( (iSpecialFlag >= 10007 && iSpecialFlag <= 10010) )
- {
- SetBasePara.FuncCode = 0x04;
- SetBasePara.nStartAddr = 0x02;
- SetBasePara.nRegNum = 0x03;
- strcpy(chDataLen, "6");
- }
- int nRet = pASCDLLInit(pDev->m_iPort,
- pDev->m_iDevideaddr,
- SetBasePara,
- atoi(chDataLen),
- chMsg);
- if ( nRet == 0)
- {
- //TRACE("Enter AscSingleResponseSpecialVarData\r\n");
- nRet = AscSingleResponseSpecialVarData( chDevUid,
- iVarID,
- iSpecialFlag,
- chMsg);
- //TRACE("Leave AscSingleResponseSpecialVarData\r\n");
- }
- else
- {
- if( nRet==20005 )
- {
- LOG4C((LOG_NOTICE, "校验出错:设备:%s, iSpecialFlag = %d,iVarID = %d",pDev->m_strDeviceName,iSpecialFlag,iVarID));
- }
- else
- {
- LOG4C((LOG_NOTICE, "出错:设备:%s,nRet = %d,iSpecialFlag = %d,iVarID = %d (%s)",pDev->m_strDeviceName,nRet,iSpecialFlag,iVarID,chMsg));
- }
- }
- return nRet;
- }
- int AscRequestWrData(char chDevUid[20], int iVarID, double data)//用于请求写命令操作
- {
- SETBASEPARAM SetBasePara;
- memset( &SetBasePara, 0, sizeof(SETBASEPARAM) );
- 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];
-
- SetBasePara.nAddr = pDev->m_iDevideaddr;
- SetBasePara.nRegNum = pBaseVar->m_iRegisterNum;
- SetBasePara.nStartAddr = pBaseVar->m_nRegStartAddr;
- SetBasePara.FuncCode = pBaseVar->m_iFuncID;
-
- if (pASC_DLLWrCom(pDev->m_iPort, pDev->m_iDevideaddr, SetBasePara, data, pBaseVar->m_iDataLen) == 0)
- return 0;
- else
- return -1;
- }
- int AscSingleResponseData(char chDevUid[20], int iVarID, char chMsg[80])
- {
- 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_csAscReadOneData );
- pDev->m_dwOnlineTick = GetTickCount();
- LeaveCriticalSection( &g_csAscReadOneData );
- int nVarItemID = pBaseVar->m_nVarItemID;
- int nDataLen = pBaseVar->m_iDataLen;
- int nValue;
- double fCoef = pBaseVar->m_dbCoefficient;
- //LOG4C((LOG_NOTICE, "%s nVarItemID=%d, nStartBit=%d, nEndBit=%d",chMsg,nVarItemID,pBaseVar->m_nStartBit,pBaseVar->m_nEndBit));
- if( nVarItemID > 0 )//BIT位变量
- {
- int nStartBit = pBaseVar->m_nStartBit;
- int nEndBit = pBaseVar->m_nEndBit;
- int nStartReg, nEndReg;
- if( nEndBit - nStartBit < 7 ) // 一般告警状态会这样子定义,Modbus Ascii码暂时没有碰到,没有经过调试,待测试
- {
- 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;
- default:
- LOG4C((LOG_NOTICE, "起始位与终止位不对",pDev->m_strDeviceName, pBaseVar->m_strDesc));
- }
- nValue = atoi(strTemp);
- //strTemp.Format("%d",
- }
- 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);
- //LOG4C((LOG_NOTICE, "nValue 1 = %d , chBuffer=%s",nValue,chBuffer ));
- 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;
- default:
- LOG4C((LOG_NOTICE, "起始位与终止位不对",pDev->m_strDeviceName, pBaseVar->m_strDesc));
- }
- nValue = atoi(strTemp);
- //LOG4C((LOG_NOTICE, "nValue 2 = %d",nValue));
- }
- //itoa(ntohs(g_vtMGEEquipData[nEquipIndex].MGEStatus.Status1), buffer, 16);
- }
- // 特殊变量处理(例如,一个命令返回两个变量的情况)
- 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_csAscReadOneData );
- pBaseVar->m_dbData = (double)(nValue * fCoef);
- if( pBaseVar->m_nRearm != 0 )
- {
- pBaseVar->m_dbData = pBaseVar->m_dbData + pBaseVar->m_nRearm;
- }
-
- LeaveCriticalSection( &g_csAscReadOneData );
- //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_csAscReadOneData );
- pBaseVar->m_dbData = (double)(unionVarInt.value * fCoef);
- if( pBaseVar->m_nRearm != 0 )
- {
- pBaseVar->m_dbData = pBaseVar->m_dbData + pBaseVar->m_nRearm;
- }
- LeaveCriticalSection( &g_csAscReadOneData );
- //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_csAscReadOneData );
- pBaseVar->m_dbData = (double)(unionVarFloat.value * fCoef);
- if( pBaseVar->m_nRearm != 0 )
- {
- pBaseVar->m_dbData = pBaseVar->m_dbData + pBaseVar->m_nRearm;
- }
- LeaveCriticalSection( &g_csAscReadOneData );
- //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_csAscReadOneData );
- pBaseVar->m_dbData = (double)(unionVarDouble.value * fCoef);
- if( pBaseVar->m_nRearm != 0 )
- {
- pBaseVar->m_dbData = pBaseVar->m_dbData + pBaseVar->m_nRearm;
- }
- LeaveCriticalSection( &g_csAscReadOneData );
- //TRACE2("联合类型变量ID%d, 值=%.1f\r\n", iVarID, unionVarDouble.value);
- }
- }
- else
- {
- switch( nDataLen )
- {
- case 1:
- nValue = (AsciiToBYTE(chMsg[0]) << 4) | ( AsciiToBYTE(chMsg[1]) & 0x00FF );
- break;
- case 2:
- nValue = ( ( (AsciiToBYTE(chMsg[0]) << 4) | ( AsciiToBYTE(chMsg[1]) & 0x00FF ) ) << 8 ) |
- ( ( (AsciiToBYTE(chMsg[2]) << 4) | ( AsciiToBYTE(chMsg[3]) & 0x00FF ) ) & 0x0000FFFF );
- break;
- case 3: // 一般为字符串类型,不作处理
- case 4: // 保留,暂时不知道什么处理
- case 5: // 一般为字符串类型,不作处理
- case 6: // 一般为字符串类型,不作处理
- case 7: // 一般为字符串类型,不作处理
- case 8: // 保留,暂时没有用到
- LOG4C((LOG_NOTICE, "一般为字符串类型,不作处理"));
- break;
- }
- EnterCriticalSection( &g_csAscReadOneData );
- if( pBaseVar->m_nMaxValues != 0 || pBaseVar->m_nMinValues != 0 ||
- pBaseVar->m_nMaxConvtRate != 0 || pBaseVar->m_nMinConvtRate != 0 )
- {
- double fScale = 1.0;
- if( pBaseVar->m_nMaxValues - pBaseVar->m_nMinValues > 0 )
- {
- 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;
- }
- LeaveCriticalSection( &g_csAscReadOneData );
- //TRACE2("普通变量ID%d, 值=%d\r\n", iVarID, nValue);
- }
- }
-
- EnterCriticalSection( &g_csAscReadOneData );
- pDev->m_dwOnlineTick = GetTickCount();
- LeaveCriticalSection( &g_csAscReadOneData );
- return 0;
- }
- void UnInitAscDll()
- {
- if (g_hASCLibModule != NULL && ( NULL != pASCDLLUnInit ))
- {
- pASCDLLUnInit();
- }
- DeleteCriticalSection( &g_csAscReadOneData );
- if (g_hASCLibModule!= NULL)
- {
- AfxFreeLibrary(g_hASCLibModule);
- g_hASCLibModule = NULL;
- }
- }
- double AscSingleResponseWriteData(char chDevUid[20], int iVarID)
- {
- 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];
- char tmpData[8] = {0};
- int iResValue = pASC_DLLRequestWrStatusData(pDev->m_iPort, pDev->m_iDevideaddr, tmpData);
-
- if (iResValue != 0 )
- return -1;
- int ii=0;
- int k=0;
- int iNum = pBaseVar->m_iDataLen;
- unsigned char *StrValue = new unsigned char[2*iNum];
- memset(StrValue, 0, 2*iNum);
- while ( ii<4*iNum)
- {
- WORD wHigh,wLow;
- wHigh = AsciiToBYTE(tmpData[ii]);
- wLow = AsciiToBYTE(tmpData[ii+1]);
- StrValue[k] = ( wHigh << 4 ) | ( wLow & 0x00FF );
- ii+=2;
- k++;
- }
- Sleep(1000);
- CString strResult;
- union unStuctResponse
- {
- char chValue[4];
- float dbValue;
-
- }unStuctResponse;
- memset(&unStuctResponse.chValue, 0, sizeof(unStuctResponse.chValue));
- memset(unStuctResponse.chValue, 0, sizeof(unStuctResponse.chValue));
- memcpy(unStuctResponse.chValue, (const char*)StrValue, 4);
- EnterCriticalSection( &g_csAscReadOneData );
- pBaseVar->m_dbData = unStuctResponse.dbValue;
- LeaveCriticalSection( &g_csAscReadOneData );
-
- CString strTime;
- CTime tm;
- tm = CTime::GetCurrentTime();
- strTime = tm.Format("%Y-%m-%d %H:%M:%S");
- delete []StrValue;
- return 0;
- }
- int AscSingleResponseSpecialVarData(char chDevUid[20], int iVarID, int iSpecialFlag, char chMsg[80])
- {
- 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_csAscReadOneData );
- pDev->m_dwOnlineTick = GetTickCount();
- LeaveCriticalSection( &g_csAscReadOneData );
- CString strMemos, strWarnContent;
- if (iSpecialFlag == 10000 || iSpecialFlag == 10001)
- strWarnContent = SpecLineWarnAndWater(pBaseVar, iSpecialFlag, chMsg);
- if (iSpecialFlag == 10002 || iSpecialFlag == 10003)
- strWarnContent = SpecLineWeihuMakeWaterDianzhuFz(pBaseVar, iSpecialFlag, chMsg);
- if( (iSpecialFlag >= 10007 && iSpecialFlag <= 10010) )
- {
- strWarnContent = LDSSpecLineWarnAndWater(pBaseVar, iSpecialFlag, chMsg);
- }
- //if( pBaseVar->m_strDesc=="自循环风机层北侧漏水" )
- // LOG4C((LOG_NOTICE, "自循环风机层北侧漏水 iSpecialFlag=%d ,值=%d",iSpecialFlag,(int)pBaseVar->m_dbData));
- EnterCriticalSection( &g_csAscReadOneData );
- pDev->m_dwOnlineTick = GetTickCount();
- LeaveCriticalSection( &g_csAscReadOneData );
- return 0;
- }
- CString LDSSpecLineWarnAndWater(CBaseVar *pBaseVar, int iSpecialFlag, char chMsg[80])
- {
- DWORD nDLWarn = 0;
- DWORD nLsPos = 0;
- float fLspos = 0;
- if (iSpecialFlag == 10007)//LDS线缆1当前电缆告警
- {
- nDLWarn = (AsciiToBYTE(chMsg[0]) << 4) | ( AsciiToBYTE(chMsg[1]) & 0x00FF );
- EnterCriticalSection( &g_csAscReadOneData );
- pBaseVar->m_nStatus = (int)nDLWarn;
- LeaveCriticalSection( &g_csAscReadOneData );
- EnterCriticalSection( &g_csAscReadOneData );
- pBaseVar->m_dbData = (int)nDLWarn;//fLspos;
- LeaveCriticalSection( &g_csAscReadOneData );
- //LOG4C((LOG_NOTICE, "变量id=%d, 电缆告警=%d\r\n", pBaseVar->m_nVarID, (int)nDLWarn));
- }
- else if (iSpecialFlag == 10008)//LDS线缆1漏水位置
- {
- nDLWarn = (AsciiToBYTE(chMsg[0]) << 4) | ( AsciiToBYTE(chMsg[1]) & 0x00FF );
- if( nDLWarn > 0 )
- {
- //memcpy(chReadLsPosData, chMsg + 2, sizeof(chReadLsPosData));
- nLsPos = ( ( (AsciiToBYTE(chMsg[4]) << 4) | ( AsciiToBYTE(chMsg[5]) & 0x00FF ) ) << 8 ) |
- ( ( (AsciiToBYTE(chMsg[6]) << 4) | ( AsciiToBYTE(chMsg[7]) & 0x00FF ) ) & 0x0000FFFF );
- EnterCriticalSection( &g_csAscReadOneData );
- pBaseVar->m_dbData = (double)nLsPos/10;
- LeaveCriticalSection( &g_csAscReadOneData );
- }
- else
- {
- EnterCriticalSection( &g_csAscReadOneData );
- pBaseVar->m_dbData = 0;
- LeaveCriticalSection( &g_csAscReadOneData );
- }
- //LOG4C((LOG_NOTICE, "变量id=%d, 电缆漏水=%d", pBaseVar->m_nVarID, (int)pBaseVar->m_dbData ));
- }
- else if (iSpecialFlag == 10009)//LDS线缆2当前电缆告警
- {
- nDLWarn = (AsciiToBYTE(chMsg[2]) << 4) | ( AsciiToBYTE(chMsg[3]) & 0x00FF );
- EnterCriticalSection( &g_csAscReadOneData );
- pBaseVar->m_nStatus = (int)nDLWarn;
- LeaveCriticalSection( &g_csAscReadOneData );
- EnterCriticalSection( &g_csAscReadOneData );
- pBaseVar->m_dbData = (int)nDLWarn;//fLspos;
- LeaveCriticalSection( &g_csAscReadOneData );
- }
- else if (iSpecialFlag == 10010)//LDS线缆2漏水位置
- {
- nDLWarn = (AsciiToBYTE(chMsg[2]) << 4) | ( AsciiToBYTE(chMsg[3]) & 0x00FF );
- if( nDLWarn > 0 )
- {
- //memcpy(chReadLsPosData, chMsg + 2, sizeof(chReadLsPosData));
- nLsPos = ( ( (AsciiToBYTE(chMsg[8]) << 4) | ( AsciiToBYTE(chMsg[9]) & 0x00FF ) ) << 8 ) |
- ( ( (AsciiToBYTE(chMsg[10]) << 4) | ( AsciiToBYTE(chMsg[11]) & 0x00FF ) ) & 0x0000FFFF );
- EnterCriticalSection( &g_csAscReadOneData );
- pBaseVar->m_dbData = (double)nLsPos/10;
- LeaveCriticalSection( &g_csAscReadOneData );
- }
- else
- {
- EnterCriticalSection( &g_csAscReadOneData );
- pBaseVar->m_dbData = 0;
- LeaveCriticalSection( &g_csAscReadOneData );
- }
- //LOG4C((LOG_NOTICE, "变量id=%d, 电缆漏水=%d", pBaseVar->m_nVarID, (int)pBaseVar->m_dbData ));
- }
- CString strWarnContent = "";
- return strWarnContent;
- }
- CString SpecLineWarnAndWater(CBaseVar *pBaseVar, int iSpecialFlag, char chMsg[80])
- {
- DWORD nDLWarn = 0;
- DWORD nLsPos = 0;
- float fLspos = 0;
- if (iSpecialFlag == 10000)//电缆告警
- {
- //memcpy(chReadWarnData, chMsg, sizeof(chReadWarnData));
- nDLWarn = (AsciiToBYTE(chMsg[0]) << 4) | ( AsciiToBYTE(chMsg[1]) & 0x00FF );
- EnterCriticalSection( &g_csAscReadOneData );
- pBaseVar->m_nStatus = (int)nDLWarn;
- LeaveCriticalSection( &g_csAscReadOneData );
- nLsPos = ( ( (AsciiToBYTE(chMsg[2]) << 4) | ( AsciiToBYTE(chMsg[3]) & 0x00FF ) ) << 8 ) |
- ( ( (AsciiToBYTE(chMsg[4]) << 4) | ( AsciiToBYTE(chMsg[5]) & 0x00FF ) ) & 0x0000FFFF );
- fLspos = ((float)nLsPos)/10;
- EnterCriticalSection( &g_csAscReadOneData );
- pBaseVar->m_dbData = (int)nDLWarn;//fLspos;
- LeaveCriticalSection( &g_csAscReadOneData );
- if( pBaseVar->m_strDesc=="自循环风机托水盘漏水" )
- LOG4C((LOG_NOTICE, "自循环风机托水盘漏水 m_nStatus=%d,m_dbData=%d %s", pBaseVar->m_nStatus,(int)pBaseVar->m_dbData,chMsg ));
- //TRACE("变量id=%d, 电缆告警=%d\r\n", pBaseVar->m_nVarID, (int)nDLWarn);
- }
- if (iSpecialFlag == 10001)//电缆漏水
- {
- nDLWarn = (AsciiToBYTE(chMsg[0]) << 4) | ( AsciiToBYTE(chMsg[1]) & 0x00FF );
- if( nDLWarn > 0 )
- {
- //memcpy(chReadLsPosData, chMsg + 2, sizeof(chReadLsPosData));
- nLsPos = ( ( (AsciiToBYTE(chMsg[2]) << 4) | ( AsciiToBYTE(chMsg[3]) & 0x00FF ) ) << 8 ) |
- ( ( (AsciiToBYTE(chMsg[4]) << 4) | ( AsciiToBYTE(chMsg[5]) & 0x00FF ) ) & 0x0000FFFF );
- EnterCriticalSection( &g_csAscReadOneData );
- pBaseVar->m_dbData = (double)nLsPos/10;
- LeaveCriticalSection( &g_csAscReadOneData );
- }
- else
- {
- EnterCriticalSection( &g_csAscReadOneData );
- pBaseVar->m_dbData = 0;
- LeaveCriticalSection( &g_csAscReadOneData );
- }
- //TRACE("变量id=%d, 电缆漏水=%.1f\r\n", pBaseVar->m_nVarID, pBaseVar->m_dbData );
- }
-
- CString strWarnContent = "";
- return strWarnContent;
- }
- //读取维护、漏水电阻阀值
- CString SpecLineWeihuMakeWaterDianzhuFz(CBaseVar *pBaseVar, int iSpecialFlag, char chMsg[80])
- {
- DWORD nWeihu = 0;
- DWORD nMakerwater = 0;
- float fValue = 0;
- CString strWarnContent = "";
- if (iSpecialFlag == 10002)
- {
- nWeihu = ( ( (AsciiToBYTE(chMsg[0]) << 4) | ( AsciiToBYTE(chMsg[1]) & 0x00FF ) ) << 8 ) |
- ( ( (AsciiToBYTE(chMsg[2]) << 4) | ( AsciiToBYTE(chMsg[3]) & 0x00FF ) ) & 0x0000FFFF );
- fValue = ((float)nWeihu);
- //strWarnContent.Format("维护电阻阀值: %f", fValue);
- }
- if (iSpecialFlag == 10003)
- {
- nMakerwater = ( ( (AsciiToBYTE(chMsg[4]) << 4) | ( AsciiToBYTE(chMsg[5]) & 0x00FF ) ) << 8 ) |
- ( ( (AsciiToBYTE(chMsg[6]) << 4) | ( AsciiToBYTE(chMsg[7]) & 0x00FF ) ) & 0x0000FFFF );
-
- fValue = ((float)nMakerwater);
- //strWarnContent.Format("漏水电阻阀值: %f", fValue);
- }
- EnterCriticalSection( &g_csAscReadOneData );
- pBaseVar->m_dbData = fValue;
- LeaveCriticalSection ( &g_csAscReadOneData );
- return strWarnContent;
- }
|