123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624 |
- #include "stdafx.h"
- #include "ascprocess.h"
- #include "Global.h"
- #include "struct.h"
- #include "MainPro.h"
- #include "rtuprocess.h"
- #include "tcpprocess.h"
- #include "icpdasprocess.h"
- #include "SnmpProcess.h"
- #include "upsParadigmProcess.h"
- #include "stulzprocess.h"
- #include "NoticeQueue.h"
- #include "DaiKinProcess.h"
- #include "PowerwareProcess.h"
- #include "greeprocess.h"
- #include "CarelProcess.h"
- #include "Client2SrvType.h"
- #include "SysLib.h"
- #include "Separate.h"
- #include "MostDevice.h"
- #include "Const.h"
- #include "ping.h"
- CRITICAL_SECTION g_csDevOnlineReadOneData;
- #define DATA_CHANGE_FLAG 0.01//0.00001
- #if IS_USER_MUL_THREAD_REQUEST
- HANDLE g_hRequestDataThread[MAX_DLL_TYPE] = {0};
- CString g_strPort[MAX_DLL_TYPE];
- #else
- HANDLE g_hRequestDataThread = NULL;
- #endif
- HANDLE g_hReConnectCommThread = NULL;
- INT g_nRequestDataThreadCount = 0;
- INT g_nTimingSendFinished = 0;
- HANDLE g_hTimingSendSmsThread = NULL;
- HANDLE g_hDevOnlineThread = NULL;
- HANDLE g_hVoiceNoticeThread = NULL;
- HANDLE g_hOutputThread = NULL;
- HANDLE g_hGetDatePlanThread = NULL;
- INT g_nRtuThreadIndex = RTU_THREAD_START; //预留100个Modbus Rtu设备,每个串口一个处理线程
- INT g_nAscThreadIndex = ASC_THREAD_START; //预留100个Modbus Asc设备,每个串口一个处理线程
- INT g_nTcpThreadIndex = TCP_THREAD_START; //预留100个Modbus Tcp设备,每个IP一个处理线程
- INT g_nSnmpThreadIndex = SNMP_THREAD_START; //预留200个Snmp设备,每个IP一个处理线程
- INT g_nMostDeviceIndex = MOSTDEVICE_THREAD_START; //预留100个MostDevice类型有设备,每个IP一个处理线程
- INT g_nIcpdasIndex = ICPDAS_THREAD_START; //预留10个泓格设备,每个串口一个处理线程
- INT g_nParadigmIndex = PARADIGM_THREAD_START; //预留10个Paradigm设备,每个串口一个处理线程
- INT g_nStulzIndex = STULZ_THREAD_START; //预留10个Stulz设备,每个串口一个处理线程
- INT g_nDaiKinIndex = DAIKIN_THREAD_START; //预留10个Dinkin设备,每个串口一个处理线程
- INT g_nPowerwareIndex = POWERWARE_THREAD_START; //预留10个Powerware设备,每个串口一个处理线程
- INT g_nGreeIndex = GREE_THREAD_START; //预留10个Gree设备,每个串口一个处理线程
- INT g_nCarelIndex = CAREL_THREAD_START; //预留10个Carel设备,每个串口一个处理线程
- INT g_nScantakIndex = SCANTAK_THREAD_START; //预留10个Scantak设备,每个串口一个处理线程
- INT g_nDeltaIndex = DELTA_THREAD_START; //预留10个Delta设备,每个串口一个处理线程
- // 该结构体用于网络设备;
- typedef struct __TCP_THREAD_STRUCT
- {
- int nTcpTheadIndex; // 每一个网络设备对应的一个线程ID索引;(每一个ip就一个线程)
- CString strUid; // 与索引相联的网络设备UID;
- }TcpThreadStruct;
- INT g_nTcpThreadStructIndex = 0; // 供g_tcpThreadStruct数组使用,下标号;
- TcpThreadStruct g_tcpThreadStruct[MAX_TCP_THREAD];
- DWORD WINAPI RequestDataThreadProc(void *pPara);
- DWORD WINAPI ReConnectCommThreadProc(void *Para);
- DWORD WINAPI TimingSendSmsThread(void *pPara);
- DWORD WINAPI DevOnlineThreadProc(void *pPara);
- DWORD WINAPI VoiceNoticeThreadProc(void *pPara);
- DWORD WINAPI OutputThreadProc(void *pPara);
- DWORD WINAPI GetDatePlanThreadProc(void *pPara);
- // 获取实际波特率
- INT GetCommRate(int nRate);
- // 获取实际数据位
- INT GetCommDataBit(int nDataBitIndex);
- // 以下查找串口是否使用的13个函数,由函数主函数StartMain调用;
- BOOL FindRtuCommPort(CString strPort);
- BOOL FindAscCommPort(CString strPort);
- BOOL FindTcpCommPort(CString strPort);
- BOOL FindMostDeviceCommPort(CString strPort);
- BOOL FindIcpdasCommPort(CString strPort);
- BOOL FindParadigmCommPort(CString strPort);
- BOOL FindStulzCommPort(CString strPort);
- BOOL FindDaiKinCommPort(CString strPort);
- BOOL FindPowerwareCommPort(CString strPort);
- BOOL FindGreeCommPort(CString strPort);
- BOOL FindCarelCommPort(CString strPort);
- BOOL FindScanTakCommPort(CString strPort);
- BOOL FindDeltaCommPort(CString strPort);
- INT StartMain()
- {
- //INT iCount = GetDevProperty();
- // 初始化该结构体数组 , 每个网络设备的信息;
- for( int i = 0; i < MAX_TCP_THREAD; i++ )
- {
- // g_tcpThreadStruct存放TCP线程索引和设备uid;
- g_tcpThreadStruct[i].nTcpTheadIndex = 0;
- g_tcpThreadStruct[i].strUid = "";
- }
- // 从数据库中获取设备信息;
- CDBInterface::GetInstancePtr()->GetDevInfo();
- // 初始化设备在线采集数据 互斥量;
- InitializeCriticalSection( &g_csDevOnlineReadOneData );
- // **********************************************加载各种采集I/O设备动态库**********************************************;
- // 改进:加载动态库时,应该考虑如何根据设备信息来动态加载,而不是一次全部加载;
- LoadAscDLL(g_strDirectory);
- LoadRtuDll(g_strDirectory);
- LoadTcpDll(g_strDirectory);
- LoadIcpdasDll(g_strDirectory);
- LoadSnmpDll(g_strDirectory);
- LoadParadigmDll(g_strDirectory);
- LoadStulzDll(g_strDirectory);
- LoadDaiKinDll(g_strDirectory);
- LoadPowerwareDll(g_strDirectory);
- LoadGreeDll(g_strDirectory);
- LoadCarelDll(g_strDirectory);
- LoadSeparateDll(g_strDirectory);
- LoadMostDeviceDll(g_strDirectory);
- // 获取设备总数;
- int iSize = (int)g_pDevicesManager->m_Devices.GetSize();
- //int iVarCount = 0;
- #if IS_USER_MUL_THREAD_REQUEST // 是否使用多线程请求; 现在 == 1, 未知这段代码有何用?;
- int nDllType[MAX_DLL_TYPE] = {0};
- for( int i = 0; i < MAX_DLL_TYPE; i++ )
- {
- nDllType[i] = 0; // ?未知该变量意义 ;
- g_hRequestDataThread[i] = NULL; // 线程句柄;
- g_strPort[i] = ""; // 通信端口;
- }
- #endif
- /************************************************************************/
- /*
- 0.循环所有设备->next;
- 1.判断设备类型->next;
- 2.打开串口 ->next;
- 3.判断是否使用->next;
- 4.创建串口线程->end;
- */
- /************************************************************************/
- int iVarCount = 0; // 存储所有变量总数;
- // 遍历所有设备,创建对应串口线程,进行设备采集;
- int nBaudRate, nDataBit;
- for( int i = 0; i < iSize; i++ )
- {
- CDevice *pDev = g_pDevicesManager->m_Devices[i];
- char chDllName[MAX_PATH] = {0};
- char szIniName[MAX_PATH] = {0};
- strcpy(chDllName, (char *)(LPCTSTR)pDev->m_strProtocoldllname);
- strcpy(szIniName, (char *)(LPCTSTR)pDev->m_strIniName);
- StrLower(chDllName,chDllName);
- StrLower(szIniName, szIniName);
- //LOG4C((LOG_NOTICE, "Devive = %s, IniName = %s", pDev->m_strDeviceName, szIniName));
- nBaudRate = GetCommRate( pDev->m_iBaudrate );
- nDataBit = GetCommDataBit( pDev->m_iDatabit );
- iVarCount += pDev->m_Vars.GetSize();
- /************************************************************************/
- /*
- 1.判断设备类型->next;
- 2.打开串口 ->next;
- 3.判断是否使用->next;
- 4.创建串口线程->end;
- */
- /************************************************************************/
- // == 0 RTU设备;
- if( pDev->m_bySpecialdevice == 0 )
- {
- if (!InitRtuComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate, nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- pDev->m_bCommStatus = FALSE; // 打开串口失败;
- else
- pDev->m_bCommStatus = TRUE; // 打开串口成功;
- // 如果该 设备变量个数大于0,进行数据采集,创建线程;
- if( pDev->m_Vars.GetSize() >= 1 )
- {
- DWORD dwThreadId;
- CString strPort;
- strPort.Format("%d", pDev->m_iPort);
- // 判断串口是否已经使用(是否存在数组里),未使用继续执行代码;
- if( FALSE == FindRtuCommPort(strPort) )
- {
- g_strPort[g_nRtuThreadIndex] = strPort;
- if( g_hRequestDataThread[g_nRtuThreadIndex] == NULL )
- {
- // 一个串口一个线程;
- MTVERIFY( g_hRequestDataThread[g_nRtuThreadIndex] =
- CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)RequestDataThreadProc,
- (char *)(LPCTSTR)g_strPort[g_nRtuThreadIndex],
- 0,
- &dwThreadId) );
- g_nRtuThreadIndex++;
- }
- }
- }
- }
- // == 1,ASC设备;
- else if( pDev->m_bySpecialdevice == 1 )
- {
- if (!InitAscComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d lost!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d success!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = TRUE;
- }
- if( pDev->m_Vars.GetSize() >= 1 )
- {
- CString strPort;
- strPort.Format("%d", pDev->m_iPort);
- if( FALSE == FindAscCommPort(strPort) )
- {
- g_strPort[g_nAscThreadIndex].Format("%d", pDev->m_iPort);
- DWORD dwThreadId;
- MTVERIFY( g_hRequestDataThread[g_nAscThreadIndex] =
- CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)RequestDataThreadProc,
- (char *)(LPCTSTR)g_strPort[g_nAscThreadIndex],
- 0,
- &dwThreadId) );
- g_nAscThreadIndex++;
- }
- }
- }
- // == 2,网络设备;
- else if( pDev->m_bySpecialdevice == 2 )
- {
- if (!InitTcpNet(pDev->m_iDevideaddr, pDev->m_iIpport, (char *)(LPCTSTR)pDev->m_strIp))
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d lost!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d success!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = TRUE;
- }
- if( pDev->m_Vars.GetSize() >= 1 )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hRequestDataThread[g_nTcpThreadIndex] =
- CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)RequestDataThreadProc,
- (char *)(LPCTSTR)pDev->m_strUid,
- 0,
- &dwThreadId) );
- g_tcpThreadStruct[g_nTcpThreadStructIndex].nTcpTheadIndex = g_nTcpThreadIndex;
- g_tcpThreadStruct[g_nTcpThreadStructIndex].strUid = pDev->m_strUid;
- g_nTcpThreadStructIndex++;
- g_nTcpThreadIndex++;
- }
- }
- else if( pDev->m_bySpecialdevice == 3 )
- {
- int iPingResult = 0;
- // ping 10 次,如果都是timeout, 认为设备已断线
- for( int iPingIndex = 0; iPingIndex < 10; iPingIndex++ )
- {
- if( Ping(2000, pDev->m_strIp) == 0 )
- {
- iPingResult = 0;
- break;
- }
- else
- {
- iPingResult = 1;
- }
- }
- if( 1 == iPingResult ) // 设备已断线
- {
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- pDev->m_bCommStatus = TRUE;
- }
- if( pDev->m_Vars.GetSize() >= 1 )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hRequestDataThread[g_nSnmpThreadIndex] =
- CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)RequestDataThreadProc,
- (char *)(LPCTSTR)pDev->m_strUid,
- 0,
- &dwThreadId) );
- g_nSnmpThreadIndex++;
- }
- }
- else if( pDev->m_bySpecialdevice == 4 )
- {
- if ( strcmp(chDllName, "icpdas.dll") == 0 )
- {
- if (!InitIcpdasComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- LOG4C((LOG_NOTICE, "device name:%s, port:%d, addr=%d, baudrate=%d, databit=%d, stopbit=%d, paritybit=%d open com lost!",
- pDev->m_strDeviceName, pDev->m_iPort, pDev->m_iDevideaddr, nBaudRate, nDataBit, pDev->m_iStopbit, pDev->m_iParitybit));
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d success!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = TRUE;
- }
- CString strPort;
- strPort.Format("%d", pDev->m_iPort);
- if( FALSE == FindIcpdasCommPort(strPort) )
- {
- g_strPort[g_nIcpdasIndex].Format("%d", pDev->m_iPort);
- if( pDev->m_Vars.GetSize() >= 1 )
- {
- //LOG4C((LOG_NOTICE, "create thread by hg module port = com%s", g_strPort[g_nIcpdasIndex] ));
- DWORD dwThreadId;
- MTVERIFY( g_hRequestDataThread[g_nIcpdasIndex] =
- CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)RequestDataThreadProc,
- (char *)(LPCTSTR)g_strPort[g_nIcpdasIndex],
- 0,
- &dwThreadId) );
- g_nIcpdasIndex++;
- }
- }
- }
- else if ( strcmp(chDllName, "upsparadigm.dll") == 0 )
- {
- if (!InitParadigmComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d lost!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d success!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = TRUE;
- }
- CString strPort;
- strPort.Format("%d", pDev->m_iPort);
- if( FALSE == FindParadigmCommPort(strPort) )
- {
- g_strPort[g_nParadigmIndex].Format("%d", pDev->m_iPort);
- if( pDev->m_Vars.GetSize() >= 1 )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hRequestDataThread[g_nParadigmIndex] =
- CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)RequestDataThreadProc,
- (char *)(LPCTSTR)g_strPort[g_nParadigmIndex],
- 0,
- &dwThreadId) );
- g_nParadigmIndex++;
- }
- }
- }
- else if ( strcmp(chDllName, "stulz.dll") == 0 )
- {
- if (!InitStulzComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d lost!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d success!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = TRUE;
- }
- CString strPort;
- strPort.Format("%d", pDev->m_iPort);
- if( FALSE == FindStulzCommPort(strPort) )
- {
- g_strPort[g_nStulzIndex].Format("%d", pDev->m_iPort);
- if( pDev->m_Vars.GetSize() >= 1 )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hRequestDataThread[g_nStulzIndex] =
- CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)RequestDataThreadProc,
- (char *)(LPCTSTR)g_strPort[g_nStulzIndex],
- 0,
- &dwThreadId) );
- g_nStulzIndex++;
- }
- }
- }
- else if ( strcmp(chDllName, "daikin.dll") == 0 )
- {
- if( !InitDaiKinComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000) )
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d lost!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d success!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = TRUE;
- }
- CString strPort;
- strPort.Format("%d", pDev->m_iPort);
- if( FALSE == FindDaiKinCommPort(strPort) )
- {
- g_strPort[g_nDaiKinIndex].Format("%d", pDev->m_iPort);
- if( pDev->m_Vars.GetSize() >= 1 )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hRequestDataThread[g_nDaiKinIndex] =
- CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)RequestDataThreadProc,
- (char *)(LPCTSTR)g_strPort[g_nDaiKinIndex],
- 0,
- &dwThreadId) );
- g_nDaiKinIndex++;
- }
- }
- }
- else if ( strcmp(chDllName, "powerware.dll") == 0 )
- {
- if( !InitPowerwareComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000) )
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d lost!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d success!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = TRUE;
- }
- CString strPort;
- strPort.Format("%d", pDev->m_iPort);
- if( FALSE == FindPowerwareCommPort(strPort) )
- {
- g_strPort[g_nPowerwareIndex].Format("%d", pDev->m_iPort);
- if( pDev->m_Vars.GetSize() >= 1 )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hRequestDataThread[g_nPowerwareIndex] =
- CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)RequestDataThreadProc,
- (char *)(LPCTSTR)g_strPort[g_nPowerwareIndex],
- 0,
- &dwThreadId) );
- g_nPowerwareIndex++;
- }
- }
- }
- else if ( strcmp(chDllName, "gree.dll") == 0 )
- {
- if (!InitGreeComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d lost!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d success!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = TRUE;
- }
- CString strPort;
- strPort.Format("%d", pDev->m_iPort);
- if( FALSE == FindGreeCommPort(strPort) )
- {
- g_strPort[g_nGreeIndex].Format("%d", pDev->m_iPort);
- if( pDev->m_Vars.GetSize() >= 1 )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hRequestDataThread[g_nGreeIndex] =
- CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)RequestDataThreadProc,
- (char *)(LPCTSTR)g_strPort[g_nGreeIndex],
- 0,
- &dwThreadId) );
- g_nGreeIndex++;
- }
- }
- }
- else if ( strcmp(chDllName, "carel.dll") == 0 )
- {
- if (!InitCarelComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d lost!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d success!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = TRUE;
- }
- CString strPort;
- strPort.Format("%d", pDev->m_iPort);
- if( FALSE == FindCarelCommPort(strPort) )
- {
- g_strPort[g_nCarelIndex].Format("%d", pDev->m_iPort);
- if( pDev->m_Vars.GetSize() >= 1 )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hRequestDataThread[g_nCarelIndex] =
- CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)RequestDataThreadProc,
- (char *)(LPCTSTR)g_strPort[g_nCarelIndex],
- 0,
- &dwThreadId) );
- g_nCarelIndex++;
- }
- }
- }
- else if( strcmp( chDllName, "scantak_3c.dll" ) == 0 )
- {
- if (!InitSeparateComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d lost!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d success!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = TRUE;
- }
- CString strPort;
- strPort.Format("%d", pDev->m_iPort);
- if( FALSE == FindScanTakCommPort(strPort) )
- {
- g_strPort[g_nScantakIndex].Format("%d", pDev->m_iPort);
- if( pDev->m_Vars.GetSize() >= 1 )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hRequestDataThread[g_nScantakIndex] =
- CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)RequestDataThreadProc,
- (char *)(LPCTSTR)g_strPort[g_nScantakIndex],
- 0,
- &dwThreadId) );
- g_nScantakIndex++;
- }
- }
- }
- else if( strcmp( chDllName, "delta.dll" ) == 0 )
- {
- if (!InitSeparateComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d lost!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d success!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = TRUE;
- }
- CString strPort;
- strPort.Format("%d", pDev->m_iPort);
- if( FALSE == FindDeltaCommPort(strPort) )
- {
- g_strPort[g_nDeltaIndex].Format("%d", pDev->m_iPort);
- if( pDev->m_Vars.GetSize() >= 1 )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hRequestDataThread[g_nDeltaIndex] =
- CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)RequestDataThreadProc,
- (char *)(LPCTSTR)g_strPort[g_nDeltaIndex],
- 0,
- &dwThreadId) );
- g_nDeltaIndex++;
- }
- }
- }
- else if ( strcmp(szIniName, "upsuh31.ini") == 0 ||
- strcmp(szIniName, "emerson_cm.ini") == 0 ||
- strcmp(szIniName, "dme3000.ini") == 0 ||
- strcmp(szIniName, "paradigm200a_rectifier.ini") == 0 ||
- strcmp(szIniName, "paradigm200a_inverter.ini") == 0 ||
- strcmp(szIniName, "paradigm200b.ini") == 0 ||
- strcmp(szIniName, "hipulseigmnet.ini") == 0 ||
- strcmp(szIniName, "hipulsecdt.ini") == 0 ||
- strcmp(szIniName, "prostar.ini") == 0 ||
- strcmp(szIniName, "joton.ini") == 0 ||
- strcmp(szIniName, "hiross.ini") == 0 ||
- strcmp(szIniName, "upslink.ini") == 0 ||
- strcmp(szIniName, "upsapcsilcon.ini") == 0 ||
- strcmp(szIniName, "ul33.ini") == 0 ||
- strcmp(szIniName, "hipulse_u.ini") == 0 ||
- strcmp(szIniName, "kehua.ini") == 0 ||
- strcmp(szIniName, "secups.ini") == 0 ||
- strcmp(szIniName, "upsuh11.ini") == 0 ||
- strcmp(szIniName, "weibo.ini") == 0 ||
- strcmp(szIniName, "sda_ii.ini") == 0 ||
- strcmp(szIniName, "daikin.ini") == 0 ||
- strcmp(szIniName, "scantak_3c.ini") == 0 ||
- strcmp(szIniName, "delta.ini") == 0 ||
- strcmp(szIniName, "m84c5z.ini") == 0 ||
- strcmp(szIniName, "upsnxr.ini") == 0 ||
- strcmp(szIniName, "batteryadu.ini") == 0 ||
- strcmp(szIniName, "upsmonitorlan.ini") == 0 ||
- strcmp(szIniName, "sk6000.ini") == 0 ||
- strcmp(szIniName, "batteryadu2000.ini") == 0 ||
- strcmp(szIniName, "santak_shiwei.ini") == 0 ||
- strcmp(szIniName, "santak_q4.ini") == 0 ||
- strcmp(szIniName, "ups_nxl.ini") == 0 ||
- strcmp(szIniName, "twoul33.ini") == 0 ||
- strcmp(szIniName, "oumai.ini") == 0 ||
- strcmp(szIniName, "santak_3a3120ks.ini") == 0 ||
- strcmp(szIniName, "tmaster.ini") == 0 ||
- strcmp(szIniName, "st_6c20ks.ini") == 0 ||
- strcmp(szIniName, "ea800.ini") == 0 ||
- strcmp(szIniName, "jb1501a64p.ini") == 0||
- strcmp(szIniName, "st_3c340ks.ini") == 0||
- strcmp(szIniName, "delta_v1.54.ini") == 0||
- strcmp(szIniName, "icp_i7017.ini") == 0 ||
- strcmp(szIniName, "fad.ini") == 0 ||
- strcmp(szIniName, "itrustadapt.ini" ) == 0 ||
- strcmp(szIniName, "uha3r_0200l.ini") == 0)
- {
- //LOG4C((LOG_NOTICE, "Enter InitMostDeviceComm szIniName = %s", szIniName));
- if (!InitMostDeviceComm(g_strDirectory, szIniName, pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d lost!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- LOG4C((LOG_NOTICE, "device name:%s open com%d success!", pDev->m_strDeviceName,pDev->m_iPort));
- pDev->m_bCommStatus = TRUE;
- }
- //LOG4C((LOG_NOTICE, "Leave InitMostDeviceComm szIniName = %s", szIniName));
- CString strPort;
- strPort.Format("%d", pDev->m_iPort);
- if( FALSE == FindMostDeviceCommPort(strPort) )
- {
- g_strPort[g_nMostDeviceIndex].Format("%d", pDev->m_iPort);
- if( pDev->m_Vars.GetSize() >= 1 )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hRequestDataThread[g_nMostDeviceIndex] =
- CreateThread(
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE)RequestDataThreadProc,
- (char *)(LPCTSTR)g_strPort[g_nMostDeviceIndex],
- 0,
- &dwThreadId) );
- g_nMostDeviceIndex++;
- }
- }
- }
- else if ( 0 == strcmp(szIniName, "stu2000.dll") )
- {
- }
- }
- }
- LOG4C((LOG_NOTICE, "iVarCount = %d", iVarCount));
- // 每MAX_SINGLE_TCP_VAR_NUM个变量,建立一个监听端口
- #if 0
- int nSocketIndex = 1;
- if( iVarCount > MAX_SINGLE_TCP_VAR_NUM )
- {
- while( iVarCount / (nSocketIndex * MAX_SINGLE_TCP_VAR_NUM) != 0 )
- {
- if( NULL == g_pServerSocket[nSocketIndex] )
- {
- g_pServerSocket[nSocketIndex] = new CServerSocket();
- CString strPort;
- strPort.Format("%d", SOCKET_SERVER_PORT + nSocketIndex);
- LOG4C((LOG_NOTICE, "Create Port %s success", strPort));
- g_pServerSocket[nSocketIndex]->SvrStart(strPort);
- nSocketIndex++;
- }
- }
- }
- #else
- int nSocketIndex = 1;
-
- if( NULL == g_pServerSocket[nSocketIndex] )
- {
- g_pServerSocket[nSocketIndex] = new CServerSocket();
- CString strPort;
- strPort.Format("%d", SOCKET_SERVER_PORT + nSocketIndex);
- LOG4C((LOG_NOTICE, "Create Port %s success", strPort));
- g_pServerSocket[nSocketIndex]->SvrStart(strPort);
- }
- #endif
- // 实时监控设备是否在线;
- if( g_hDevOnlineThread == NULL )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hDevOnlineThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)DevOnlineThreadProc, 0, 0, &dwThreadId) );
- }
- // 实时监控,超时值外设备断开进行重连;
- if( g_hReConnectCommThread == NULL )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hReConnectCommThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ReConnectCommThreadProc, NULL, 0, &dwThreadId) );
- }
- // 定时发送系统正常运行短信;
- if( g_hTimingSendSmsThread == NULL )
- {
- DWORD dwThreadId;
- if( g_nSendSms==1 || g_nSendNotice==1 )
- {
- MTVERIFY( g_hTimingSendSmsThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)TimingSendSmsThread, NULL, 0, &dwThreadId) );
- }
- }
- // 实时监控报警,发送报警信息;
- if( g_hVoiceNoticeThread == NULL )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hVoiceNoticeThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)VoiceNoticeThreadProc, NULL, 0, &dwThreadId) );
- }
- // 对外输出,供第三方使用;
- if( g_hOutputThread == NULL )
- {
- if( 1 == g_nOutputEnable )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hOutputThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)OutputThreadProc, NULL, 0, &dwThreadId) );
- }
- }
- // 时间计划;
- if( g_hGetDatePlanThread == NULL )
- {
- DWORD dwThreadId;
- MTVERIFY( g_hGetDatePlanThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)GetDatePlanThreadProc, NULL, 0, &dwThreadId) );
- }
- return 0;
- }
- void EndMain()
- {
- #if IS_USER_MUL_THREAD_REQUEST
- for( int i = 0; i < MAX_DLL_TYPE; i++ )
- {
- if (NULL != g_hRequestDataThread[i])
- {
- MTVERIFY( WaitForSingleObject( g_hRequestDataThread[i], INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle( g_hRequestDataThread[i] ) );
- g_hRequestDataThread[i] = NULL;
- }
- }
- #else
- if (NULL != g_hRequestDataThread)
- {
- MTVERIFY( WaitForSingleObject( g_hRequestDataThread, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle( g_hRequestDataThread ) );
- g_hRequestDataThread = NULL;
- }
- #endif
- if( NULL != g_hDevOnlineThread )
- {
- MTVERIFY( WaitForSingleObject( g_hDevOnlineThread, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle( g_hDevOnlineThread ) );
- g_hDevOnlineThread = NULL;
- }
- if( NULL != g_hReConnectCommThread )
- {
- MTVERIFY( WaitForSingleObject( g_hReConnectCommThread, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle( g_hReConnectCommThread ) );
- g_hReConnectCommThread = NULL;
- }
- if( g_hTimingSendSmsThread != NULL )
- {
- MTVERIFY( WaitForSingleObject( g_hTimingSendSmsThread, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle( g_hTimingSendSmsThread ) );
- g_hTimingSendSmsThread = NULL;
- }
- if( g_hVoiceNoticeThread != NULL )
- {
- MTVERIFY( WaitForSingleObject( g_hVoiceNoticeThread, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle( g_hVoiceNoticeThread ) );
- g_hVoiceNoticeThread = NULL;
- }
- if( 1 == g_nOutputEnable )
- {
- if( NULL != g_hOutputThread )
- {
- MTVERIFY( WaitForSingleObject( g_hOutputThread, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle( g_hOutputThread ) );
- g_hOutputThread = NULL;
- }
- }
- if( NULL != g_hGetDatePlanThread )
- {
- MTVERIFY( WaitForSingleObject( g_hGetDatePlanThread, INFINITE ) != WAIT_FAILED );
- MTVERIFY( CloseHandle( g_hGetDatePlanThread ) );
- g_hGetDatePlanThread = NULL;
- }
- DeleteCriticalSection( &g_csDevOnlineReadOneData );
- }
- //
- // 以下12个动态库重连函数,均由线程ReConnectCommThreadProc调用;
- // 参数是单个设备 ,当设备状态 = 断开时,以下重连函数执行;;
- // 该函数是按变量进行采集.
- BOOL ModbusRtuReConnectProc(CDevice *pDev)
- {
- BOOL bResult = FALSE; // 返回结果;
- char chMsg[80] = {0};
- SETBASEPARAM SetBasePara = {0};
- SetBasePara.nAddr = pDev->m_iDevideaddr;
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- nVarSize = nVarSize<10 ? nVarSize : 10;
- for( int j = 0; j < nVarSize; j++ )
- {
- //if( j > 0 ) break;
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue; // 变量 == 1 只写;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- SetBasePara.nRegNum = pBaseVar->m_iRegisterNum;
- SetBasePara.nStartAddr = pBaseVar->m_nRegStartAddr;
- SetBasePara.FuncCode = pBaseVar->m_iFuncID;
- if( pBaseVar->m_nVarTypeID >= SPECIAL_VAR_TYPE_MIN_ID && pBaseVar->m_nVarTypeID <= SPECIAL_VAR_TYPE_MAX_ID ) // 特殊变量
- {
- // RtuRequestSpecData不属于动态接口函数,是本服务的函数处理特殊变量;
- if (RtuRequestSpecData(SetBasePara, pBaseVar->m_iDataLen, pDev->m_iPort, pDev->m_iDevideaddr,
- (char *)(LPCTSTR)pBaseVar->m_strVarUID, pBaseVar->m_nVarID, pBaseVar->m_nVarTypeID) == 0)
- {
- bResult = TRUE;
- break;
- }
- }
- else
- {
- // 动态库接口函数,处理一般变量;
- if (pRTU_DLLInit(pDev->m_iPort, pDev->m_iDevideaddr, SetBasePara, pBaseVar->m_iDataLen, chMsg)==0)//初始化设备DLL
- {
- bResult = TRUE;
- break;
- }
- }
- }
- return bResult;
- }
- BOOL ModbusAscReConnectProc(CDevice *pDev)
- {
- BOOL bResult = FALSE;
- char chMsg[80] = {0};
- SETBASEPARAM SetBasePara = {0};
- SetBasePara.nAddr = pDev->m_iDevideaddr;
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- nVarSize = nVarSize<10 ? nVarSize : 10;
- for( int j = 0; j < nVarSize; j++ )
- {
- //if( j > 0 ) break;
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- SetBasePara.nRegNum = pBaseVar->m_iRegisterNum;
- SetBasePara.nStartAddr = pBaseVar->m_nRegStartAddr;
- SetBasePara.FuncCode = pBaseVar->m_iFuncID;
- if( pBaseVar->m_nVarTypeID >= SPECIAL_VAR_TYPE_MIN_ID && pBaseVar->m_nVarTypeID <= SPECIAL_VAR_TYPE_MAX_ID ) // 特殊变量
- {
- if (AscRequestSpecData((char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID, pBaseVar->m_nVarTypeID) == 0)
- {
- bResult = TRUE;
- break;
- }
- }
- else
- {
- if(pASCDLLInit(pDev->m_iPort, pDev->m_iDevideaddr, SetBasePara, pBaseVar->m_iDataLen, chMsg)==0)//初始化设备DLL
- {
- bResult = TRUE;
- break;
- }
- }
- }
- return bResult;
- }
- BOOL SnmpReConnectProc(CDevice *pDev)
- {
- BOOL bResult = FALSE;
- char chMsg[80] = {0};
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- nVarSize = nVarSize<10 ? nVarSize : 10;
- for( int j = 0; j < nVarSize; j++ )
- {
- //if( j > 0 ) break;
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- if( pSnmpDllGetValue )
- {
- //TRACE("变量值id=%d\r\n", pBaseVar->m_nVarID);
- int nRet = pSnmpDllGetValue((char *)(LPCTSTR)pDev->m_strIp,
- (char *)(LPCTSTR)pBaseVar->m_strFields,
- (char *)(LPCTSTR)pBaseVar->m_strSnmpoi,
- chMsg);
- if( nRet == 0 )
- {
- bResult = TRUE;
- break;
- }
- }
- }
- return bResult;
- }
- BOOL IcpdasReConnectProc(CDevice *pDev)
- {
- BOOL bResult = FALSE;
- char chMsg[80] = {0};
- SETBASEPARAM SetBasePara = {0};
- SetBasePara.nAddr = pDev->m_iDevideaddr;
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- nVarSize = nVarSize<10 ? nVarSize : 10;
- for( int j = 0; j < nVarSize; j++ )
- {
- //if( j > 0 ) break;
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- SetBasePara.nRegNum = pBaseVar->m_iRegisterNum;
- SetBasePara.nStartAddr = pBaseVar->m_nRegStartAddr;
- SetBasePara.FuncCode = pBaseVar->m_iFuncID;
- if (IcpdasRequestData(j, SetBasePara, pBaseVar->m_iDataLen, pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID, (char *)(LPCTSTR)pBaseVar->m_strRs232cmd) == 0)
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL ParadigmReConnectProc(CDevice *pDev)
- {
- BOOL bResult = FALSE;
- char chMsg[80] = {0};
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- nVarSize = nVarSize<10 ? nVarSize : 10;
- for( int j = 0; j < nVarSize; j++ )
- {
- //if( j > 0 ) break;
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- if (ParadigmRequestData(pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID, (char*)(LPCTSTR)pBaseVar->m_strRs232cmd) == 0)
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL StulzReConnectProc(CDevice *pDev)
- {
- BOOL bResult = FALSE;
- char chMsg[80] = {0};
- SETBASEPARAM SetBasePara = {0};
- SetBasePara.nAddr = pDev->m_iDevideaddr;
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- nVarSize = nVarSize<10 ? nVarSize : 10;
- for( int j = 0; j < nVarSize; j++ )
- {
- //if( j > 0 ) break;
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- SetBasePara.nRegNum = pBaseVar->m_iRegisterNum;
- SetBasePara.nStartAddr = pBaseVar->m_nRegStartAddr;
- SetBasePara.FuncCode = pBaseVar->m_iFuncID;
- if (StulzRequestData(SetBasePara, pBaseVar->m_iDataLen, pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID, (char*)(LPCTSTR)pBaseVar->m_strRs232cmd) == 0)
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL DaiKinReConnectProc(CDevice *pDev)
- {
- BOOL bResult = FALSE;
- char chMsg[80] = {0};
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- nVarSize = nVarSize<10 ? nVarSize : 10;
- for( int j = 0; j < nVarSize; j++ )
- {
- //if( j > 0 ) break;
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- if (DaiKinRequestData(pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID, (char*)(LPCTSTR)pBaseVar->m_strRs232cmd) == 0)
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL PowerwareReConnectProc(CDevice *pDev)
- {
- BOOL bResult = FALSE;
- char chMsg[80] = {0};
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- nVarSize = nVarSize<10 ? nVarSize : 10;
- for( int j = 0; j < nVarSize; j++ )
- {
- //if( j > 0 ) break;
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- if (PowerwareRequestData(pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID, (char*)(LPCTSTR)pBaseVar->m_strRs232cmd) == 0)
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL GreeReConnectProc(CDevice *pDev)
- {
- BOOL bResult = FALSE;
- char chMsg[80] = {0};
- SETBASEPARAM SetBasePara = {0};
- SetBasePara.nAddr = pDev->m_iDevideaddr;
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- nVarSize = nVarSize<10 ? nVarSize : 10;
- for( int j = 0; j < nVarSize; j++ )
- {
- //if( j > 0 ) break;
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- SetBasePara.nRegNum = pBaseVar->m_iRegisterNum;
- SetBasePara.nStartAddr = pBaseVar->m_nRegStartAddr;
- SetBasePara.FuncCode = pBaseVar->m_iFuncID;
- if (GreeRequestData(SetBasePara, pBaseVar->m_iDataLen, pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID, (char*)(LPCTSTR)pBaseVar->m_strRs232cmd) == 0)
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL CarelReConnectProc(CDevice *pDev)
- {
- BOOL bResult = FALSE;
- char chMsg[80] = {0};
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- nVarSize = nVarSize<10 ? nVarSize : 10;
- for( int j = 0; j < nVarSize; j++ )
- {
- //if( j > 0 ) break;
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- if (CarelRequestData(pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID,
- (char*)(LPCTSTR)pBaseVar->m_strRs232cmd) == 0)
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL SeparateReConnectProc(CDevice *pDev)
- {
- BOOL bResult = FALSE;
- char chMsg[80] = {0};
- char szIniName[MAX_PATH] = {0};
- strcpy(szIniName, (char *)(LPCTSTR)pDev->m_strIniName);
- StrLower(szIniName, szIniName);
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- nVarSize = nVarSize<10 ? nVarSize : 10;
- for( int j = 0; j < nVarSize; j++ )
- {
- //if( j > 0 ) break;
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- if (SeparateRequestData(pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID,
- (char*)(LPCTSTR)pBaseVar->m_strRs232cmd,
- szIniName) == 0)
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL MostDeviceReConnectProc(CDevice *pDev)
- {
- BOOL bResult = FALSE;
- char chMsg[80] = {0};
- char szIniName[MAX_PATH] = {0};
- strcpy(szIniName, (char *)(LPCTSTR)pDev->m_strIniName);
- StrLower(szIniName, szIniName);
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- nVarSize = nVarSize<10 ? nVarSize : 10;
- for( int j = 0; j < nVarSize; j++ )
- {
- //if( j > 1 ) break;
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- if (MostDeviceRequestData(pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID,
- (char*)(LPCTSTR)pBaseVar->m_strRs232cmd,
- szIniName) == 0)
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- //
- int GetTcpThreadStructIndex(CString strUid)
- {
- int nRet = -1;
- for( int i = 0; i < MAX_TCP_THREAD; i++ )
- {
- if( g_tcpThreadStruct[i].strUid.Compare(strUid) == 0 )
- {
- nRet = i;
- break;
- }
- }
- return nRet;
- }
- //
- //以上13个函数,均由线程重连串口ReConnectCommThreadProc调用 ;
- // 功能如下:
- // 0.判断是否设备是否掉线,掉线则重连串口并采集;
- // 1.每个类型设备,首先初始化.判断是否打开了该串口;
- // 2.串口打开成功,进行数据采集,存储到变量和设备里;
- DWORD WINAPI ReConnectCommThreadProc(void *Para)
- {
- do
- {
- int iSize = (int)g_pDevicesManager->m_Devices.GetSize();
- int nBaudRate, nDataBit;
- for( int i = 0; i < iSize; i++ )
- {
- CDevice *pDev = g_pDevicesManager->m_Devices[i];
- char chDllName[MAX_PATH] = {0};
- char szIniName[MAX_PATH] = {0};
- strcpy(chDllName, (char *)(LPCTSTR)pDev->m_strProtocoldllname);
- strcpy(szIniName, (char *)(LPCTSTR)pDev->m_strIniName);
- StrLower(chDllName,chDllName);
- StrLower(szIniName, szIniName);
- nBaudRate = GetCommRate( pDev->m_iBaudrate );
- nDataBit = GetCommDataBit( pDev->m_iDatabit );
- if( pDev->m_bySpecialdevice == 0 )
- {
- // 设备连接状态 = FALSE 断开,进行重连串口;
- if( pDev->m_bCommStatus == FALSE )
- {
- // InitRtuComm初始串口函数 ,调用动态库接口函数进行初始化;
- if (!InitRtuComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate, nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- // 初始化失败,继续标识为断线;
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- // 成功初始化串口,进行数据采集操作;
- EnterCriticalSection( &g_csRtuReadOneData );
- // 进行数据的采集;抽取动态函数;
- pDev->m_bCommStatus = ModbusRtuReConnectProc(pDev);
- if( pDev->m_bCommStatus == TRUE )
- {
- LOG4C((LOG_NOTICE, "device name:%s open com success!", pDev->m_strDeviceName));
- pDev->m_dwOnlineTick = GetTickCount();
- }
- LeaveCriticalSection( &g_csRtuReadOneData );
- }
- }
- }
- else if( pDev->m_bySpecialdevice == 1 )
- {
- if( pDev->m_bCommStatus == FALSE )
- {
- if (!InitAscComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- EnterCriticalSection( &g_csAscReadOneData );
- pDev->m_bCommStatus = ModbusAscReConnectProc(pDev);
- if( pDev->m_bCommStatus == TRUE )
- {
- LOG4C((LOG_NOTICE, "device name:%s open com success!", pDev->m_strDeviceName));
- pDev->m_dwOnlineTick = GetTickCount();
- }
- LeaveCriticalSection( &g_csAscReadOneData );
- }
- }
- }
- else if( pDev->m_bySpecialdevice == 2 )
- {
- if( pDev->m_bCommStatus == FALSE )
- {
- int iPingResult = 0;
- // ping 10 次,如果都是timeout, 认为设备已断线
- for( int iPingIndex = 0; iPingIndex < 10; iPingIndex++ )
- {
- if( Ping(2000, pDev->m_strIp) == 0 )
- {
- iPingResult = 0;
- break;
- }
- else
- {
- iPingResult = 1;
- }
- }
- if( 1 == iPingResult ) // 设备已断线
- {
-
- }
- else
- {
- if (!InitTcpNet(pDev->m_iDevideaddr, pDev->m_iIpport, (char *)(LPCTSTR)pDev->m_strIp))
- {
- EnterCriticalSection( &g_csTcpReadOneData );
- pDev->m_bCommStatus = FALSE;
- LeaveCriticalSection( &g_csTcpReadOneData );
- }
- else
- {
- EnterCriticalSection( &g_csTcpReadOneData );
- pDev->m_dwOnlineTick = GetTickCount();
- pDev->m_bCommStatus = TRUE;
- LeaveCriticalSection( &g_csTcpReadOneData );
- int nIndex = GetTcpThreadStructIndex( pDev->m_strUid );
- if( nIndex != -1 )
- {
- if( g_hRequestDataThread[ g_tcpThreadStruct[nIndex].nTcpTheadIndex ] != NULL )
- {
- ResumeThread( g_hRequestDataThread[ g_tcpThreadStruct[nIndex].nTcpTheadIndex ] );
- }
- }
- }
- }
- }
- }
- else if( pDev->m_bySpecialdevice == 3 )
- {
- // 循环所有变量
- if( pDev->m_bCommStatus == FALSE )
- {
- int iPingResult = 0;
- // ping 10 次,如果都是timeout, 认为设备已断线
- for( int iPingIndex = 0; iPingIndex < 10; iPingIndex++ )
- {
- if( Ping(2000, pDev->m_strIp) == 0 )
- {
- iPingResult = 0;
- break;
- }
- else
- {
- iPingResult = 1;
- }
- }
- if( 1 == iPingResult ) // 设备已断线
- {
-
- }
- else
- {
- EnterCriticalSection( &g_csIcpdasReadOneData );
- pDev->m_dwOnlineTick = GetTickCount();
- pDev->m_bCommStatus = TRUE;
- LeaveCriticalSection( &g_csIcpdasReadOneData );
- }
- }
- }
- else if( pDev->m_bySpecialdevice == 4 )
- {
- if ( strcmp(chDllName, "icpdas.dll") == 0 )
- {
- if( pDev->m_bCommStatus == FALSE )
- {
- if (!InitIcpdasComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- EnterCriticalSection( &g_csIcpdasReadOneData );
- pDev->m_bCommStatus = IcpdasReConnectProc(pDev);
- if( pDev->m_bCommStatus == TRUE )
- {
- LOG4C((LOG_NOTICE, "device name:%s open com success!", pDev->m_strDeviceName));
- pDev->m_dwOnlineTick = GetTickCount();
- }
- LeaveCriticalSection( &g_csIcpdasReadOneData );
- }
- }
- }
- else if ( strcmp(chDllName, "upsparadigm.dll") == 0 )
- {
- if( pDev->m_bCommStatus == FALSE )
- {
- if (!InitParadigmComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- EnterCriticalSection( &g_csParadigmReadOneData );
- pDev->m_bCommStatus = ParadigmReConnectProc(pDev);
- if( pDev->m_bCommStatus == TRUE )
- {
- LOG4C((LOG_NOTICE, "device name:%s open com success!", pDev->m_strDeviceName));
- pDev->m_dwOnlineTick = GetTickCount();
- }
- LeaveCriticalSection( &g_csParadigmReadOneData );
- }
- }
- }
- else if ( strcmp(chDllName, "stulz.dll") == 0 )
- {
- if( pDev->m_bCommStatus == FALSE )
- {
- if (!InitStulzComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- EnterCriticalSection( &g_csStulzReadOneData );
- pDev->m_bCommStatus = StulzReConnectProc(pDev);
- if( pDev->m_bCommStatus == TRUE )
- {
- LOG4C((LOG_NOTICE, "device name:%s open com success!", pDev->m_strDeviceName));
- pDev->m_dwOnlineTick = GetTickCount();
- }
- LeaveCriticalSection( &g_csStulzReadOneData );
- }
- }
- }
- else if ( strcmp(chDllName, "daikin.dll") == 0 )
- {
- if( pDev->m_bCommStatus == FALSE )
- {
- if( !InitDaiKinComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000) )
- {
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- EnterCriticalSection( &g_csDaiKinReadOneData );
- pDev->m_bCommStatus = DaiKinReConnectProc(pDev);
- if( pDev->m_bCommStatus == TRUE )
- {
- LOG4C((LOG_NOTICE, "device name:%s open com success!", pDev->m_strDeviceName));
- pDev->m_dwOnlineTick = GetTickCount();
- }
- LeaveCriticalSection( &g_csDaiKinReadOneData );
- }
- }
- }
- else if ( strcmp(chDllName, "powerware.dll") == 0 )
- {
- if( pDev->m_bCommStatus == FALSE )
- {
- if( !InitPowerwareComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000) )
- {
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- EnterCriticalSection( &g_csPowerwareReadOneData );
- pDev->m_bCommStatus = PowerwareReConnectProc(pDev);
- if( pDev->m_bCommStatus == TRUE )
- {
- LOG4C((LOG_NOTICE, "device name:%s open com success!", pDev->m_strDeviceName));
- pDev->m_dwOnlineTick = GetTickCount();
- }
- LeaveCriticalSection( &g_csPowerwareReadOneData );
- }
- }
- }
- else if ( strcmp(chDllName, "gree.dll") == 0 )
- {
- if (pDev->m_bCommStatus == FALSE)
- {
- if (!InitGreeComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- EnterCriticalSection(&g_csGreeReadOneData);
- pDev->m_bCommStatus = GreeReConnectProc(pDev);
- if( pDev->m_bCommStatus == TRUE )
- {
- LOG4C((LOG_NOTICE, "device name:%s open com success!", pDev->m_strDeviceName));
- pDev->m_dwOnlineTick = GetTickCount();
- }
- LeaveCriticalSection(&g_csGreeReadOneData);
- }
- }
- }
- else if ( strcmp(chDllName, "carel.dll") == 0 )
- {
- if (pDev->m_bCommStatus == FALSE)
- {
- if (!InitCarelComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- EnterCriticalSection(&g_csCarelReadOneData);
- pDev->m_bCommStatus = CarelReConnectProc(pDev);
- if( pDev->m_bCommStatus == TRUE )
- {
- LOG4C((LOG_NOTICE, "device name:%s open com success!", pDev->m_strDeviceName));
- pDev->m_dwOnlineTick = GetTickCount();
- }
- LeaveCriticalSection(&g_csCarelReadOneData);
- }
- }
- }
- else if ( strcmp(chDllName, "scantak_3c.dll") == 0 )
- {
- if (pDev->m_bCommStatus == FALSE)
- {
- if (!InitSeparateComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- EnterCriticalSection(&g_csSeparateReadOneData);
- pDev->m_bCommStatus = SeparateReConnectProc(pDev);
- if( pDev->m_bCommStatus == TRUE )
- {
- LOG4C((LOG_NOTICE, "device name:%s open com success!", pDev->m_strDeviceName));
- pDev->m_dwOnlineTick = GetTickCount();
- }
- LeaveCriticalSection(&g_csSeparateReadOneData);
- }
- }
- }
- else if ( strcmp(chDllName, "delta.dll") == 0 )
- {
- if (pDev->m_bCommStatus == FALSE)
- {
- if (!InitSeparateComm(pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- EnterCriticalSection(&g_csSeparateReadOneData);
- pDev->m_bCommStatus = SeparateReConnectProc(pDev);
- if( pDev->m_bCommStatus == TRUE )
- {
- LOG4C((LOG_NOTICE, "device name:%s open com success!", pDev->m_strDeviceName));
- pDev->m_dwOnlineTick = GetTickCount();
- }
- LeaveCriticalSection(&g_csSeparateReadOneData);
- }
- }
- }
- else if ( strcmp(szIniName, "upsuh31.ini") == 0 ||
- strcmp(szIniName, "emerson_cm.ini") == 0 ||
- strcmp(szIniName, "dme3000.ini") == 0 ||
- strcmp(szIniName, "paradigm200a_rectifier.ini") == 0 ||
- strcmp(szIniName, "paradigm200a_inverter.ini") == 0 ||
- strcmp(szIniName, "paradigm200b.ini") == 0 ||
- strcmp(szIniName, "hipulseigmnet.ini") == 0 ||
- strcmp(szIniName, "hipulsecdt.ini") == 0 ||
- strcmp(szIniName, "prostar.ini") == 0 ||
- strcmp(szIniName, "joton.ini") == 0 ||
- strcmp(szIniName, "hiross.ini") == 0 ||
- strcmp(szIniName, "upslink.ini") == 0 ||
- strcmp(szIniName, "upsapcsilcon.ini") == 0 ||
- strcmp(szIniName, "ul33.ini") == 0 ||
- strcmp(szIniName, "hipulse_u.ini") == 0 ||
- strcmp(szIniName, "kehua.ini") == 0 ||
- strcmp(szIniName, "secups.ini") == 0 ||
- strcmp(szIniName, "upsuh11.ini") == 0 ||
- strcmp(szIniName, "weibo.ini") == 0 ||
- strcmp(szIniName, "sda_ii.ini") == 0 ||
- strcmp(szIniName, "daikin.ini") == 0 ||
- strcmp(szIniName, "scantak_3c.ini") == 0 ||
- strcmp(szIniName, "delta.ini") == 0 ||
- strcmp(szIniName, "m84c5z.ini") == 0 ||
- strcmp(szIniName, "upsnxr.ini") == 0 ||
- strcmp(szIniName, "batteryadu.ini") == 0 ||
- strcmp(szIniName, "upsmonitorlan.ini") == 0 ||
- strcmp(szIniName, "sk6000.ini") == 0 ||
- strcmp(szIniName, "batteryadu2000.ini") == 0 ||
- strcmp(szIniName, "santak_shiwei.ini") == 0 ||
- strcmp(szIniName, "santak_q4.ini") == 0 ||
- strcmp(szIniName, "ups_nxl.ini") == 0 ||
- strcmp(szIniName, "twoul33.ini") == 0 ||
- strcmp(szIniName, "oumai.ini") == 0 ||
- strcmp(szIniName, "santak_3a3120ks.ini") == 0 ||
- strcmp(szIniName, "tmaster.ini") == 0 ||
- strcmp(szIniName, "st_6c20ks.ini") == 0||
- strcmp(szIniName, "ea800.ini") == 0 ||
- strcmp(szIniName, "jb1501a64p.ini") == 0||
- strcmp(szIniName, "st_3c340ks.ini") == 0||
- strcmp(szIniName, "delta_v1.54.ini") == 0||
- strcmp(szIniName, "icp_i7017.ini") == 0 ||
- strcmp(szIniName, "fad.ini") == 0 ||
- strcmp(szIniName, "itrustadapt.ini" ) == 0 ||
- strcmp(szIniName, "uha3r_0200l.ini") == 0)
- {
- if (pDev->m_bCommStatus == FALSE)
- {
- if (!InitMostDeviceComm(g_strDirectory, szIniName, pDev->m_iDevideaddr, pDev->m_iPort, nBaudRate,
- nDataBit, pDev->m_iStopbit, pDev->m_iParitybit, 1000))
- {
- pDev->m_bCommStatus = FALSE;
- }
- else
- {
- EnterCriticalSection(&g_csMostDeviceReadOneData);
- pDev->m_bCommStatus = MostDeviceReConnectProc(pDev);
- if( pDev->m_bCommStatus == TRUE )
- {
- LOG4C((LOG_NOTICE, "device name:%s open com success!", pDev->m_strDeviceName));
- pDev->m_dwOnlineTick = GetTickCount();
- }
- LeaveCriticalSection(&g_csMostDeviceReadOneData);
- }
- }
- }
- }
- }
- Sleep(100); //chn add
- }while( WaitForSingleObject( g_hRunObject, 1250L ) == WAIT_TIMEOUT );
- return 0;
- }
- //
- // 设备是否在线判断线程;
- // 1.网络设备通过ping函数来判断是否在线;
- // 2.串口设备通过采集数据的超时值来判断是否在线(每个设备都一个超时变量);
- DWORD WINAPI DevOnlineThreadProc(void *pPara)
- {
- do
- {
- // 1.循环所有设备
- int nDeviceSize = g_pDevicesManager->m_Devices.GetSize();
- for( int i = 0; i < nDeviceSize; i++ )
- {
- CDevice *pDev = g_pDevicesManager->m_Devices[i];
- // 2.循环该设备变量
- int nVarSize = pDev->m_Vars.GetSize();
- for( int j = 0; j < nVarSize; j++ )
- {
- // 3.只判断设备变量中的内存变量(即设备通讯状态变量);
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID ) // 内存变量,判断设备是否在线
- {
- // 4.分别对网络和串口设备进行处理,设定条件成立则设备定义为通讯断线;
- if( pDev->m_bySpecialdevice == 2 || pDev->m_bySpecialdevice == 3 ) // 网络设备
- {
- int iPingResult = 0;
- // 4.1 网络设备ping 10 次,如果都是timeout, 认为设备已断线
- for( int iPingIndex = 0; iPingIndex < 10; iPingIndex++ )
- {
- if( Ping(2000, pDev->m_strIp) == 0 )
- {
- iPingResult = 0;
- break;
- }
- else
- {
- iPingResult = 1;
- }
- }
- // 4.2 对网络设备断线和在线处理;
- if( 1 == iPingResult ) // 设备已断线
- {
- if( pDev->m_bySpecialdevice == 2 )
- {
- // 通过uid获取网络设备线程ID索引;
- int nIndex = GetTcpThreadStructIndex( pDev->m_strUid );
- if( nIndex != -1 )
- {
- // 通过已知线程ID索引,挂起线程;
- if( g_hRequestDataThread[ g_tcpThreadStruct[nIndex].nTcpTheadIndex ] != NULL )
- {
- //LOG4C((LOG_NOTICE, "Enter SuspendThread."));
- SuspendThread( g_hRequestDataThread[ g_tcpThreadStruct[nIndex].nTcpTheadIndex ] );
- //LOG4C((LOG_NOTICE, "Leave SuspendThread."));
- }
- }
- // 关闭该线程所使用的网络资源(如:套接字);
- //LOG4C((LOG_NOTICE, "Enter CloseTcpNet."));
- CloseTcpNet(pDev->m_iDevideaddr, pDev->m_iIpport, (char *)(LPCTSTR)pDev->m_strIp);
- //LOG4C((LOG_NOTICE, "Leave CloseTcpNet."));
- }
- // 设备该设备在线变量;
- //if( pDev->m_bCommStatus == TRUE )
- {
- //LOG4C((LOG_NOTICE, "devname = %s ping timeout", pDev->m_strDeviceName));
- EnterCriticalSection( &g_csDevOnlineReadOneData );
- pBaseVar->m_dbData = 1;
- pBaseVar->m_nStatus = 1;
- pDev->m_bCommStatus = FALSE;
- LeaveCriticalSection( &g_csDevOnlineReadOneData );
- }
- }
- else
- {
- EnterCriticalSection( &g_csDevOnlineReadOneData );
- pBaseVar->m_dbData = 0;
- pBaseVar->m_nStatus = 0;
- pDev->m_bCommStatus = TRUE;
- LeaveCriticalSection( &g_csDevOnlineReadOneData );//g_csRtuReadOneData
- }
- }
- else // 串口设备
- {
- if( pDev->m_dwOnlineTick <= 0 )
- {
- pDev->m_dwOnlineTick = GetTickCount();
- }
-
- // 1.判断变量超时值是否超过设定值,超过则设备判定为掉线;
- if( GetTickCount() - pDev->m_dwOnlineTick > 3 * 60 * 1000 && pDev->m_dwOnlineTick > 0 )
- {
- //LOG4C((LOG_NOTICE, "%s %d, 串口通信故障!", pDev->m_strDeviceName,pDev->m_bySpecialdevice));
- //if( pDev->m_bCommStatus == TRUE )
- {
- EnterCriticalSection( &g_csDevOnlineReadOneData );
- pBaseVar->m_dbData = 1;
- pBaseVar->m_nStatus = 1;
- pDev->m_bCommStatus = FALSE;
- LeaveCriticalSection( &g_csDevOnlineReadOneData );
- }
- }
- else if( GetTickCount() - pDev->m_dwOnlineTick < 3 * 60 * 1000 && pDev->m_dwOnlineTick > 0 )
- {
- //LOG4C((LOG_NOTICE, "%s, 串口通信正常!", pDev->m_strDeviceName));
- EnterCriticalSection( &g_csDevOnlineReadOneData );
- pBaseVar->m_dbData = 0;
- pBaseVar->m_nStatus = 0;
- pDev->m_bCommStatus = TRUE;
- LeaveCriticalSection( &g_csDevOnlineReadOneData );
- }
- }
- break;
- }
- }
- Sleep(10); // 每个设备之间,延时10ms
- }
- }while( WaitForSingleObject( g_hRunObject, 100L ) == WAIT_TIMEOUT );
- return 0;
- }
- //
- // 以下13个动态库采集函数,均由采集线程RequestDataThreadProc调用;
- int ModbusRtuProcessProc(CDevice *pDev)
- {
- char chMsg[80] = {0};
- SETBASEPARAM SetBasePara = {0};
- SetBasePara.nAddr = pDev->m_iDevideaddr;
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- for( int j = 0; j < nVarSize; j++ )
- {
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- // 记住上一次读到的数值
- pBaseVar->m_dbLastData = pBaseVar->m_dbData;
- SetBasePara.nRegNum = pBaseVar->m_iRegisterNum;
- SetBasePara.nStartAddr = pBaseVar->m_nRegStartAddr;
- SetBasePara.FuncCode = pBaseVar->m_iFuncID;
- if( pBaseVar->m_nVarTypeID >= SPECIAL_VAR_TYPE_MIN_ID && pBaseVar->m_nVarTypeID <= SPECIAL_VAR_TYPE_MAX_ID ) // 特殊变量
- {
- //TRACE("变量值id=%d\r\n", pBaseVar->m_nVarID);
- int nRet = RtuRequestSpecData(SetBasePara, pBaseVar->m_iDataLen, pDev->m_iPort, pDev->m_iDevideaddr,
- (char *)(LPCTSTR)pBaseVar->m_strVarUID, pBaseVar->m_nVarID, pBaseVar->m_nVarTypeID);
- if (nRet == 0)
- {
- }
- else if (nRet == 30005)//Modbus rtu设备lrc校验失败
- {
- // 22:41 2012-6-6 tryto:当采集不到数据时,读取变量的初始值为当前值;
- pBaseVar->m_dbData = pBaseVar->m_nReserved1;
- pDev->m_dwOnlineTick = GetTickCount();
- }
- else
- {
- //Sleep(200);
- // 22:41 2012-6-6 tryto:当采集不到数据时,读取变量的初始值为当前值;
- pBaseVar->m_dbData = pBaseVar->m_nReserved1;
- continue;
- }
- }
- else
- {
- int nRet = pRTU_DLLInit(pDev->m_iPort, pDev->m_iDevideaddr, SetBasePara, pBaseVar->m_iDataLen, chMsg);
- if (nRet == 0)//初始化设备DLL
- {
- RtuSingleResponseData((char *)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID, chMsg );
- }
- else if (nRet == 30005)//Modbus rtu设备lrc校验失败
- {
- pDev->m_dwOnlineTick = GetTickCount();
- }
- else
- {
- //LOG4C((LOG_NOTICE, "变量(%s),请求失败,错误代码=%d\n", pBaseVar->m_strDesc, nRet));
- }
- }
- if( abs(pBaseVar->m_dbData - pBaseVar->m_dbLastData) < DATA_CHANGE_FLAG )
- {
- }
- else
- {
- pBaseVar->m_bIsChange = TRUE;
- }
- Sleep(1);
- }
- return 0;
- }
- int ModbusAscProcessProc(CDevice *pDev)
- {
- char chMsg[80] = {0};
- SETBASEPARAM SetBasePara = {0};
- SetBasePara.nAddr = pDev->m_iDevideaddr;
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- for( int j = 0; j < nVarSize; j++ )
- {
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- // 记住上一次读到的数值
- pBaseVar->m_dbLastData = pBaseVar->m_dbData;
- SetBasePara.nRegNum = pBaseVar->m_iRegisterNum;
- SetBasePara.nStartAddr = pBaseVar->m_nRegStartAddr;
- SetBasePara.FuncCode = pBaseVar->m_iFuncID;
- if( pBaseVar->m_nVarTypeID >= SPECIAL_VAR_TYPE_MIN_ID && pBaseVar->m_nVarTypeID <= SPECIAL_VAR_TYPE_MAX_ID ) // 特殊变量
- {
- //TRACE("变量值id=%d\r\n", pBaseVar->m_nVarID);
- int nRet = AscRequestSpecData((char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID, pBaseVar->m_nVarTypeID);
- if( nRet==0 )
- {
- }
- else if (nRet == 20005)//Modbus asc设备lrc校验失败
- {
- pDev->m_dwOnlineTick = GetTickCount();
- }
- else
- {
- continue;
- }
- }
- else
- {
- int nRet = pASCDLLInit(pDev->m_iPort, pDev->m_iDevideaddr, SetBasePara, pBaseVar->m_iDataLen, chMsg);//初始化设备DLL
- if( nRet==0 )
- {
- //TRACE("变量值id=%d\r\n", pBaseVar->m_nVarID);
- AscSingleResponseData((char *)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID, chMsg);
- }
- else if (nRet == 20005)//Modbus asc设备lrc校验失败
- {
- pDev->m_dwOnlineTick = GetTickCount();
- }
- else if (nRet == 30005)//Modbus rtu设备lrc校验失败
- {
- pDev->m_dwOnlineTick = GetTickCount();
- }
- }
- //if( pBaseVar->m_strName=="Leak2_Alarm" )
- //{
- // CString s;
- // s.Format( "Leak2_Alarm=%d",pBaseVar->m_dbData );
- // LOG4C((LOG_NOTICE, s));
- //}
- //if( pBaseVar->m_strName=="Leak2_Pos" )
- //{
- // CString s;
- // s.Format( "Leak2_Pos=%d",pBaseVar->m_dbData );
- // LOG4C((LOG_NOTICE, s));
- //}
- if( abs(pBaseVar->m_dbData - pBaseVar->m_dbLastData) < DATA_CHANGE_FLAG )
- {
- }
- else
- {
- pBaseVar->m_bIsChange = TRUE;
- }
- Sleep(1);
- }
- return 0;
- }
- int ModbusTcpProcessProc(CDevice *pDev)
- {
- char chMsg[80] = {0};
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- for( int j = 0; j < nVarSize; j++ )
- {
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- // 记住上一次读到的数值
- pBaseVar->m_dbLastData = pBaseVar->m_dbData;
- if( WaitForSingleObject( g_hRunObject, 5L ) == WAIT_OBJECT_0 )
- {
- MTVERIFY( SetEvent(pDev->m_hSemNet) );
- }
- #if 0
- if( WaitForSingleObject(g_hSemNet, 0) == WAIT_OBJECT_0 ) // 有信号才发送数据
- {
- char chRegNum[4] = {0};
- char chStartAddr[4] = {0};
- char chFuncCode[4] = {0};
- if (TcpRequestData(pDev->m_iIpport,
- pDev->m_iDevideaddr,
- (char *)(LPCTSTR)pDev->m_strIp,
- pBaseVar->m_iRegisterNum,
- pBaseVar->m_nRegStartAddr,
- pBaseVar->m_iFuncID) == 0)
- {
- //TRACE("变量值id=%d\r\n", pBaseVar->m_nVarID);
- int nRet = TcpSingleResponseData((char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID);
- if( nRet == 0 )
- {
- g_nIndex--;
- if( g_nIndex != 0 )
- {
- //TRACE("ModbusTcp数据不同步!\r\n");
- }
- //TRACE(">>>>>>>>>>结束请求一次数据\r\n");
- SetEvent( g_hSemNet );
- //TRACE("变量ID=%d, 请求寄存器地址:%d, 变量值=%.1f\r\n", pReadSnVar->iVarid, atoi(chStartAddr), g_TcpReadOneData.dbData);
- //
- }
- else
- {
- g_nIndex--;
- //TRACE("ModbusTcp响应数据错误!\r\n");
- SetEvent( g_hSemNet );
- }
- }
- else
- {
- //TRACE("没有读到数据\r\n");
- }
- }
- #else
- #if 0
- char chRegNum[4] = {0};
- char chStartAddr[4] = {0};
- char chFuncCode[4] = {0};
- if( WaitForSingleObject(pDev->m_hSemNet, 0) == WAIT_OBJECT_0 ) // 有信号才发送数据
- {
- if (TcpRequestData(pDev->m_iIpport,
- pDev->m_iDevideaddr,
- (char *)(LPCTSTR)pDev->m_strIp,
- pBaseVar->m_iRegisterNum,
- pBaseVar->m_nRegStartAddr,
- pBaseVar->m_iFuncID) == 0)
- {
- int nRet = TcpSingleResponseData((char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID);
- }
- }
- #else
- char chRegNum[4] = {0};
- char chStartAddr[4] = {0};
- char chFuncCode[4] = {0};
- if( WaitForSingleObject(pDev->m_hSemNet, 0) == WAIT_OBJECT_0 ) // 有信号才发送数据
- {
- g_nIndex++;
- ResetEvent( pDev->m_hSemNet );
- if (TcpRequestData(pDev->m_iIpport,
- pDev->m_iDevideaddr,
- (char *)(LPCTSTR)pDev->m_strIp,
- pBaseVar->m_iRegisterNum,
- pBaseVar->m_nRegStartAddr,
- pBaseVar->m_iFuncID) == 0)
- {
- int nRet = TcpSingleResponseData((char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID);
- if( nRet == 0 )
- {
- g_nIndex--;
- if( g_nIndex != 0 )
- {
- //TRACE("ModbusTcp数据不同步!\r\n");
- }
- //TRACE(">>>>>>>>>>结束请求一次数据\r\n");
- SetEvent( pDev->m_hSemNet );
- //TRACE("变量ID=%d, 请求寄存器地址:%d, 变量值=%.1f\r\n", pReadSnVar->iVarid, atoi(chStartAddr), g_TcpReadOneData.dbData);
- //
- }
- else if( nRet == 20405 )
- {
- pDev->m_dwOnlineTick = GetTickCount();
- }
- else
- {
- g_nIndex--;
- //TRACE("ModbusTcp响应数据错误!\r\n");
- SetEvent( pDev->m_hSemNet );
- }
- }
- else
- {
- SetEvent( pDev->m_hSemNet );
- }
- }
- #endif
- #endif
- if( abs(pBaseVar->m_dbData - pBaseVar->m_dbLastData) < DATA_CHANGE_FLAG )
- {
- //LOG4C((LOG_NOTICE, "var desc = %s IsChange = false", pBaseVar->m_strDesc));
- }
- else
- {
- //LOG4C((LOG_NOTICE, "var desc = %s IsChange = true", pBaseVar->m_strDesc));
- pBaseVar->m_bIsChange = TRUE;
- }
- Sleep(1);
- }
- return 0;
- }
- int SnmpProcessProc(CDevice *pDev)
- {
- char chMsg[1024] = {0};
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- for( int j = 0; j < nVarSize; j++ )
- {
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- // 记住上一次读到的数值
- pBaseVar->m_dbLastData = pBaseVar->m_dbData;
- if( pSnmpDllGetValue )
- {
- //TRACE("变量值id=%d\r\n", pBaseVar->m_nVarID);
- int nRet = pSnmpDllGetValue((char *)(LPCTSTR)pDev->m_strIp,
- (char *)(LPCTSTR)pBaseVar->m_strFields,
- (char *)(LPCTSTR)pBaseVar->m_strSnmpoi,
- chMsg);
- if( nRet == 0 )
- {
- ParseSnmpData(
- (char *)(LPCTSTR)pDev->m_strUid,
- pBaseVar->m_nVarID,
- chMsg);
- }
- }
- if( abs(pBaseVar->m_dbData - pBaseVar->m_dbLastData) < DATA_CHANGE_FLAG )
- {
- }
- else
- {
- pBaseVar->m_bIsChange = TRUE;
- }
- Sleep(1);
- }
- return 0;
- }
- int IcpdasProcessProc(CDevice *pDev)
- {
- char chMsg[80] = {0};
- SETBASEPARAM SetBasePara = {0};
- SetBasePara.nAddr = pDev->m_iDevideaddr;
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- for( int j = 0; j < nVarSize; j++ )
- {
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- // 记住上一次读到的数值
- pBaseVar->m_dbLastData = pBaseVar->m_dbData;
- SetBasePara.nRegNum = pBaseVar->m_iRegisterNum;
- SetBasePara.nStartAddr = pBaseVar->m_nRegStartAddr;
- SetBasePara.FuncCode = pBaseVar->m_iFuncID;
- int nRet = IcpdasRequestData(j, SetBasePara, pBaseVar->m_iDataLen, pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID, (char *)(LPCTSTR)pBaseVar->m_strRs232cmd);
- if( nRet==0 )
- {
- }
- else if( nRet == 20805 )
- {
- pDev->m_dwOnlineTick = GetTickCount();
- }
- else
- {
- continue;
- }
- if( abs(pBaseVar->m_dbData - pBaseVar->m_dbLastData) < DATA_CHANGE_FLAG )
- {
- }
- else
- {
- pBaseVar->m_bIsChange = TRUE;
- }
- Sleep(1);
- }
- return 0;
- }
- int ParadigmProcessProc(CDevice *pDev)
- {
- char chMsg[80] = {0};
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- for( int j = 0; j < nVarSize; j++ )
- {
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- // 记住上一次读到的数值
- pBaseVar->m_dbLastData = pBaseVar->m_dbData;
- int nRet = ParadigmRequestData(pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID, (char*)(LPCTSTR)pBaseVar->m_strRs232cmd);
- if( nRet == 0)
- {
-
- }
- else
- {
- continue;
- }
- if( abs(pBaseVar->m_dbData - pBaseVar->m_dbLastData) < DATA_CHANGE_FLAG )
- {
- }
- else
- {
- pBaseVar->m_bIsChange = TRUE;
- }
- Sleep(1);
- }
- return 0;
- }
- int StulzProcessProc(CDevice *pDev)
- {
- char chMsg[80] = {0};
- SETBASEPARAM SetBasePara = {0};
- SetBasePara.nAddr = pDev->m_iDevideaddr;
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- for( int j = 0; j < nVarSize; j++ )
- {
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- // 记住上一次读到的数值
- pBaseVar->m_dbLastData = pBaseVar->m_dbData;
- SetBasePara.nRegNum = pBaseVar->m_iRegisterNum;
- SetBasePara.nStartAddr = pBaseVar->m_nRegStartAddr;
- SetBasePara.FuncCode = pBaseVar->m_iFuncID;
- int nRet = StulzRequestData(SetBasePara, pBaseVar->m_iDataLen, pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID, (char*)(LPCTSTR)pBaseVar->m_strRs232cmd);
- if( nRet==0 )
- {
-
- }
- else if( nRet == 20805 )
- {
- pDev->m_dwOnlineTick = GetTickCount();
- }
- else
- {
- continue;
- }
- if( abs(pBaseVar->m_dbData - pBaseVar->m_dbLastData) < DATA_CHANGE_FLAG )
- {
- }
- else
- {
- pBaseVar->m_bIsChange = TRUE;
- }
- Sleep(1);
- }
- return 0;
- }
- int DaiKinProcessProc(CDevice *pDev)
- {
- char chMsg[80] = {0};
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- for( int j = 0; j < nVarSize; j++ )
- {
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- // 记住上一次读到的数值
- pBaseVar->m_dbLastData = pBaseVar->m_dbData;
- int nRet = DaiKinRequestData(pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID, (char*)(LPCTSTR)pBaseVar->m_strRs232cmd);
- if( nRet == 0)
- {
-
- }
- else if( nRet == 21405 )
- {
- pDev->m_dwOnlineTick = GetTickCount();
- }
- else
- {
- continue;
- }
- if( abs(pBaseVar->m_dbData - pBaseVar->m_dbLastData) < DATA_CHANGE_FLAG )
- {
- }
- else
- {
- pBaseVar->m_bIsChange = TRUE;
- }
- Sleep(1);
- }
- return 0;
- }
- int PowerwareProcessProc(CDevice *pDev)
- {
- char chMsg[80] = {0};
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- for( int j = 0; j < nVarSize; j++ )
- {
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- // 记住上一次读到的数值
- pBaseVar->m_dbLastData = pBaseVar->m_dbData;
- int nRet = PowerwareRequestData(pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID, (char*)(LPCTSTR)pBaseVar->m_strRs232cmd);
- if( nRet == 0)
- {
-
- }
- else if( nRet == 21605 )
- {
- pDev->m_dwOnlineTick = GetTickCount();
- }
- else
- {
- continue;
- }
- if( abs(pBaseVar->m_dbData - pBaseVar->m_dbLastData) < DATA_CHANGE_FLAG )
- {
- }
- else
- {
- pBaseVar->m_bIsChange = TRUE;
- }
- Sleep(1);
- }
- return 0;
- }
- int GreeProcessProc(CDevice *pDev)
- {
- char chMsg[80] = {0};
- SETBASEPARAM SetBasePara = {0};
- SetBasePara.nAddr = pDev->m_iDevideaddr;
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- for( int j = 0; j < nVarSize; j++ )
- {
- if( WaitForSingleObject( g_hRunObject, 5L ) == WAIT_OBJECT_0 ) return 0;
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- // 记住上一次读到的数值
- pBaseVar->m_dbLastData = pBaseVar->m_dbData;
- SetBasePara.nRegNum = pBaseVar->m_iRegisterNum;
- SetBasePara.nStartAddr = pBaseVar->m_nRegStartAddr;
- SetBasePara.FuncCode = pBaseVar->m_iFuncID;
- int nRet = GreeRequestData(SetBasePara, pBaseVar->m_iDataLen, pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID, (char*)(LPCTSTR)pBaseVar->m_strRs232cmd);
- if( nRet == 0)
- {
-
- }
- else if( nRet == 21805 )
- {
- pDev->m_dwOnlineTick = GetTickCount();
- }
- else
- {
- continue;
- }
- if( abs(pBaseVar->m_dbData - pBaseVar->m_dbLastData) < DATA_CHANGE_FLAG )
- {
- }
- else
- {
- pBaseVar->m_bIsChange = TRUE;
- }
- Sleep(1);
- }
- return 0;
- }
- int CarelProcessProc(CDevice *pDev)
- {
- char chMsg[80] = {0};
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- for( int j = 0; j < nVarSize; j++ )
- {
- if( WaitForSingleObject( g_hRunObject, 5L ) == WAIT_OBJECT_0 ) return 0;
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- // 记住上一次读到的数值
- pBaseVar->m_dbLastData = pBaseVar->m_dbData;
- int nRet = CarelRequestData(pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID,
- (char*)(LPCTSTR)pBaseVar->m_strRs232cmd);
- if( nRet == 0)
- {
-
- }
- else if( nRet == 22205 )
- {
- pDev->m_dwOnlineTick = GetTickCount();
- }
- else
- {
- continue;
- }
- if( abs(pBaseVar->m_dbData - pBaseVar->m_dbLastData) < DATA_CHANGE_FLAG )
- {
- }
- else
- {
- pBaseVar->m_bIsChange = TRUE;
- }
- Sleep(1);
- }
- return 0;
- }
- int SeparateProcessProc(CDevice *pDev)
- {
- char chMsg[80] = {0};
- char szIniName[MAX_PATH] = {0};
- strcpy(szIniName, (char *)(LPCTSTR)pDev->m_strIniName);
- StrLower(szIniName, szIniName);
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- for( int j = 0; j < nVarSize; j++ )
- {
- if( WaitForSingleObject( g_hRunObject, 5L ) == WAIT_OBJECT_0 ) return 0;
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- // 记住上一次读到的数值
- pBaseVar->m_dbLastData = pBaseVar->m_dbData;
- int nRet = SeparateRequestData(pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID,
- (char*)(LPCTSTR)pBaseVar->m_strRs232cmd,
- szIniName);
- if( nRet == 0)
- {
-
- }
- else if( nRet == 50205 )
- {
- pDev->m_dwOnlineTick = GetTickCount();
- }
- else
- {
- continue;
- }
- if( abs(pBaseVar->m_dbData - pBaseVar->m_dbLastData) < DATA_CHANGE_FLAG )
- {
- }
- else
- {
- pBaseVar->m_bIsChange = TRUE;
- }
- Sleep(1);
- }
- return 0;
- }
- int MostDeviceProcessProc(CDevice *pDev)
- {
- char chMsg[80] = {0};
- char szIniName[MAX_PATH] = {0};
- strcpy(szIniName, (char *)(LPCTSTR)pDev->m_strIniName);
- StrLower(szIniName, szIniName);
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- for( int j = 0; j < nVarSize; j++ )
- {
- if( WaitForSingleObject( g_hRunObject, 0 ) == WAIT_OBJECT_0 ) return 0;
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- // m_bReadOnly == 0只读; == 1只写 ; == :读写;
- if( pBaseVar->m_bReadOnly == 1 ) continue;
- if( pBaseVar->m_nVarTypeID == ONLINE_VAR_ID || HIGH_PRIORITY_ONLINE_ID == pBaseVar->m_nVarTypeID ) continue; // 内存变量,在DevOnlineThread处理
- // 记住上一次读到的数值
- pBaseVar->m_dbLastData = pBaseVar->m_dbData;
- int nRet = MostDeviceRequestData(pDev->m_iPort, pDev->m_iDevideaddr,
- (char*)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID,
- (char*)(LPCTSTR)pBaseVar->m_strRs232cmd,
- szIniName);
- if( nRet == 0)
- {
- }
- else if( nRet == 50205 )
- {
- pDev->m_dwOnlineTick = GetTickCount();
- }
- else
- {
- Sleep(1);
- continue;
- }
- // abs(int ) :将参数转为绝对值.
- if( abs(pBaseVar->m_dbData - pBaseVar->m_dbLastData) < DATA_CHANGE_FLAG )
- {
- }
- else
- {
- pBaseVar->m_bIsChange = TRUE;
- }
- Sleep(1);
- }
- return 0;
- }
- //
- // 以上13个采集函数均由采集线程RequestDataThreadProc调用;
- // 该线程的参数是外部指定的串口号;
- DWORD WINAPI RequestDataThreadProc(void *pPara)
- {
- #if IS_USER_MUL_THREAD_REQUEST
- CString strName;
- strName = CString((char *)pPara);
- strName.MakeLower();
- #endif
- do
- {
- // 循环所有设备
- int nDeviceSize = g_pDevicesManager->m_Devices.GetSize();
- for( int i = 0; i < nDeviceSize; i++ )
- {
- CDevice *pDev = g_pDevicesManager->m_Devices[i];
- char chDllName[MAX_PATH] = {0};
- strcpy(chDllName, (char *)(LPCTSTR)pDev->m_strProtocoldllname);
- StrLower(chDllName,chDllName);
- char szIniName[MAX_PATH] = {0};
- strcpy(szIniName, (char *)(LPCTSTR)pDev->m_strIniName);
- StrLower(szIniName, szIniName);
- char szUid[MAX_PATH] = {0};
- strcpy(szUid, (char *)(LPCTSTR)pDev->m_strUid);
- StrLower(szUid, szUid);
-
- char szPort[MAX_PATH] = {0};
- CString strPort;
- strPort.Format("%d", pDev->m_iPort);
- strcpy(szPort, (char *)(LPCTSTR)strPort);
- StrLower(szPort, szPort);
- #if 0
- if( pDev->m_bCommStatus == FALSE )
- {
- Sleep(1);
- continue;
- }
- #endif
- if( pDev->m_bySpecialdevice == 0 )
- {
- #if IS_USER_MUL_THREAD_REQUEST
- if( strName.Compare(szPort) != 0 ) continue;
- #endif
- ModbusRtuProcessProc(pDev);
- }
- else if( pDev->m_bySpecialdevice == 1 )
- {
- #if IS_USER_MUL_THREAD_REQUEST
- if( strName.Compare(szPort) != 0 ) continue;
- #endif
- ModbusAscProcessProc(pDev);
- }
- else if( pDev->m_bySpecialdevice == 2 )
- {
- #if IS_USER_MUL_THREAD_REQUEST
- if( strName.Compare(szUid) ) continue;
- #endif
- ModbusTcpProcessProc(pDev);
- }
- else if( pDev->m_bySpecialdevice == 3 )
- {
- #if IS_USER_MUL_THREAD_REQUEST
- if( strName.Compare(szUid) ) continue;
- #endif
- SnmpProcessProc(pDev);
- }
- else if( pDev->m_bySpecialdevice == 4 )
- {
- if ( strcmp(chDllName, "icpdas.dll") == 0 )
- {
- #if IS_USER_MUL_THREAD_REQUEST
- if( strName.Compare(szPort) != 0 ) continue;
- #endif
- IcpdasProcessProc(pDev);
- }
- else if ( strcmp(chDllName, "upsparadigm.dll") == 0 )
- {
- #if IS_USER_MUL_THREAD_REQUEST
- if( strName.Compare(szPort) != 0 ) continue;
- #endif
- ParadigmProcessProc(pDev);
- }
- else if ( strcmp(chDllName, "stulz.dll") == 0 )
- {
- #if IS_USER_MUL_THREAD_REQUEST
- if( strName.Compare(szPort) != 0 ) continue;
- #endif
- StulzProcessProc(pDev);
- }
- else if ( strcmp(chDllName, "daikin.dll") == 0 )
- {
- #if IS_USER_MUL_THREAD_REQUEST
- if( strName.Compare(szPort) != 0 ) continue;
- #endif
- DaiKinProcessProc(pDev);
- }
- else if ( strcmp(chDllName, "powerware.dll") == 0 )
- {
- #if IS_USER_MUL_THREAD_REQUEST
- if( strName.Compare(szPort) != 0 ) continue;
- #endif
- PowerwareProcessProc(pDev);
- }
- else if ( strcmp(chDllName, "gree.dll") == 0 )
- {
- #if IS_USER_MUL_THREAD_REQUEST
- if( strName.Compare(szPort) != 0 ) continue;
- #endif
- GreeProcessProc(pDev);
- }
- else if ( strcmp(chDllName, "carel.dll") == 0 )
- {
- #if IS_USER_MUL_THREAD_REQUEST
- if( strName.Compare(szPort) != 0 ) continue;
- #endif
- CarelProcessProc(pDev);
- }
- else if ( strcmp(chDllName, "scantak_3c.dll") == 0 )
- {
- #if IS_USER_MUL_THREAD_REQUEST
- if( strName.Compare(szPort) != 0 ) continue;
- #endif
- SeparateProcessProc(pDev);
- }
- else if ( strcmp(chDllName, "delta.dll") == 0 )
- {
- #if IS_USER_MUL_THREAD_REQUEST
- if( strName.Compare(szPort) != 0 ) continue;
- #endif
- //TRACE("变量值id=%d\r\n", pBaseVar->m_nVarID);
- SeparateProcessProc(pDev);
- }
- else if ( strcmp(szIniName, "upsuh31.ini") == 0 ||
- strcmp(szIniName, "emerson_cm.ini") == 0 ||
- strcmp(szIniName, "dme3000.ini") == 0 ||
- strcmp(szIniName, "paradigm200a_rectifier.ini") == 0 ||
- strcmp(szIniName, "paradigm200a_inverter.ini") == 0 ||
- strcmp(szIniName, "paradigm200b.ini") == 0 ||
- strcmp(szIniName, "hipulseigmnet.ini") == 0 ||
- strcmp(szIniName, "hipulsecdt.ini") == 0 ||
- strcmp(szIniName, "prostar.ini") == 0 ||
- strcmp(szIniName, "joton.ini") == 0 ||
- strcmp(szIniName, "hiross.ini") == 0 ||
- strcmp(szIniName, "upslink.ini") == 0 ||
- strcmp(szIniName, "upsapcsilcon.ini") == 0 ||
- strcmp(szIniName, "ul33.ini") == 0 ||
- strcmp(szIniName, "hipulse_u.ini") == 0 ||
- strcmp(szIniName, "kehua.ini") == 0 ||
- strcmp(szIniName, "secups.ini") == 0 ||
- strcmp(szIniName, "upsuh11.ini") == 0 ||
- strcmp(szIniName, "weibo.ini") == 0 ||
- strcmp(szIniName, "sda_ii.ini") == 0 ||
- strcmp(szIniName, "daikin.ini") == 0 ||
- strcmp(szIniName, "scantak_3c.ini") == 0 ||
- strcmp(szIniName, "delta.ini") == 0 ||
- strcmp(szIniName, "m84c5z.ini") == 0 ||
- strcmp(szIniName, "upsnxr.ini") == 0 ||
- strcmp(szIniName, "batteryadu.ini") == 0 ||
- strcmp(szIniName, "upsmonitorlan.ini") == 0 ||
- strcmp(szIniName, "sk6000.ini") == 0 ||
- strcmp(szIniName, "batteryadu2000.ini") == 0 ||
- strcmp(szIniName, "santak_shiwei.ini") == 0 ||
- strcmp(szIniName, "santak_q4.ini") == 0 ||
- strcmp(szIniName, "ups_nxl.ini") == 0 ||
- strcmp(szIniName, "twoul33.ini") == 0 ||
- strcmp(szIniName, "oumai.ini") == 0 ||
- strcmp(szIniName, "santak_3a3120ks.ini") == 0 ||
- strcmp(szIniName, "tmaster.ini") == 0 ||
- strcmp(szIniName, "st_6c20ks.ini") == 0 ||
- strcmp(szIniName, "ea800.ini") == 0 ||
- strcmp(szIniName, "jb1501a64p.ini") == 0||
- strcmp(szIniName, "st_3c340ks.ini") == 0||
- strcmp(szIniName, "delta_v1.54.ini") == 0 ||
- strcmp(szIniName, "icp_i7017.ini") == 0 ||
- strcmp(szIniName, "fad.ini") == 0 ||
- strcmp(szIniName, "itrustadapt.ini" ) == 0 ||
- strcmp(szIniName, "uha3r_0200l.ini") == 0)
- {
- #if IS_USER_MUL_THREAD_REQUEST
- if( strName.Compare(szPort) != 0 ) continue;
- #endif
- //LOG4C((LOG_NOTICE, "Enter MostDeviceProcessProc szIniName = %s", szIniName));
- MostDeviceProcessProc(pDev);
- //LOG4C((LOG_NOTICE, "Leave MostDeviceProcessProc szIniName = %s", szIniName));
- }
- }
- }
- }while( WaitForSingleObject( g_hRunObject, 5L ) == WAIT_TIMEOUT );
- return 0;
- }
- //
- // 定时发送系统运行通知 短信/电话/邮件/传真 线程;
- // 应添加如下功能:
- // 1.选择按天发送系统信息;
- // 2.选择按星期发送系统信息;
- // 3.选择按月发送系统信息;
- DWORD WINAPI TimingSendSmsThread(void *pPara)
- {
- char chTel[MAX_TEL_LENGTH] = {0}; // 电话;
- char chMobile[MAX_TEL_LENGTH] = {0}; // 手机;
- char chFax[MAX_TEL_LENGTH] = {0}; // 传真;
- char chEmail[MAX_EMAIL_LENGTH] = {0}; // 邮件;
- // 创建容器(最后使用完要释放内存空间);
- list<string> list_tel, list_mobile, list_fax, list_email;
- list<string>::iterator it_tel, it_mobile, it_fax, it_email;
- // 从数据库中获取用户信息;
- int nUserCount = CDBInterface::GetInstancePtr()->GetUserInfoList(list_tel, list_mobile, list_fax, list_email);
- // 无用户,返回;
- if( 0 == nUserCount )
- return 0;
- // 有用户,但用户无电话等信息,返回;
- if( 0 == list_tel.size() )
- return 0;
- do
- {
- // 时刻获取当前时间,对比已设定好的时间;
- CTime ctNow = CTime::GetCurrentTime();
- int nWeek, nHour, nMinute;
- nWeek = ctNow.GetDayOfWeek();
- nHour = ctNow.GetHour();
- nMinute = ctNow.GetMinute();
- #if 0 //每天发一次
- if( nHour == g_nTimingHours && nMinute == g_nTimingMinutes && g_nTimingEnable == 1 && g_nTimingSendFinished == 0 )
- {
- g_nTimingSendFinished = 1;
- char szResultMsg[MAX_EQUIP_DESC + 1] = {0};
- int nResult = -1;
- memset(szResultMsg, 0, sizeof(szResultMsg));
- for( it_tel = list_tel.begin(), it_mobile = list_mobile.begin(), it_fax = list_fax.begin(), it_email = list_email.begin();
- it_tel != list_tel.end(), it_mobile != list_mobile.end(), it_fax != list_fax.end(), it_email != list_email.end(); )
- {
- strcpy(chTel, (*it_tel++).c_str());
- strcpy(chMobile, (*it_mobile++).c_str());
- strcpy(chFax, (*it_fax++).c_str());
- strcpy(chEmail, (*it_email++).c_str());
- // 是否启用短信模块功能;
- if( g_nSendSms==1 ) // g_nSendSms;
- {
- if( strcmp(chMobile, "") != 0 )
- {
- CString strMobileTel;
- strMobileTel.Format("%s",chMobile );
- if( strMobileTel.GetLength()!=11 ) continue; //判断是不是手机号码 只根据长度
- if (pSmsDllSendSms && g_bSuccesOpen)
- {
- nResult = pSmsDllSendSms(chMobile, (char *)(LPCTSTR)g_strHintSysRun, szResultMsg);
- }
-
- if( nResult != 0 ) // 发送失败
- {
- }
- }
- }
- // 是否启用语音模块功能;
- if( g_nSendNotice == 1 )
- {
- //LOG4C((LOG_NOTICE, "nWeek = %d, nHour = %d, nMinute = %d", nWeek, nHour, nMinute));
- if( strcmp(chTel, "") != 0 )
- {
- LOG4C((LOG_NOTICE, "nWeek = %d, nHour = %d, nMinute = %d, g_strHintSysRun = %s", nWeek, nHour, nMinute, g_strHintSysRun));
- // 继续加入语音发送list
- EnterCriticalSection( &g_csVarNotice );
- InsertSendNoticeList("0.0.0.0", 1, chTel, (char *)(LPCTSTR)g_strHintSysRun);
- LeaveCriticalSection( &g_csVarNotice );
- }
- #if 0 //移动电话 不打电话
- if( strcmp(chMobile, "") != 0 )
- {
- //LOG4C((LOG_NOTICE, "nWeek = %d, nHour = %d, nMinute = %d, g_strHintSysRun = %s", nWeek, nHour, nMinute, g_strHintSysRun));
- // 继续加入语音发送list
- EnterCriticalSection( &g_csVarNotice );
- InsertSendNoticeList("0.0.0.0", 1, chMobile, (char *)(LPCTSTR)g_strHintSysRun);
- LeaveCriticalSection( &g_csVarNotice );
- }
- #endif
- }
- }
- }
- else
- {
- if( !( nHour == g_nTimingHours && nMinute == g_nTimingMinutes ) )
- {
- g_nTimingSendFinished = 0;
- }
- }
- #else //每星期发一次
- if( nWeek == g_nTimingWeeks && nHour == g_nTimingHours && nMinute == g_nTimingMinutes && g_nTimingEnable == 1 && g_nTimingSendFinished == 0 )
- {
- g_nTimingSendFinished = 1;
- char szResultMsg[MAX_EQUIP_DESC + 1] = {0};
- int nResult = -1;
- memset(szResultMsg, 0, sizeof(szResultMsg));
- for( it_tel = list_tel.begin(), it_mobile = list_mobile.begin(), it_fax = list_fax.begin(), it_email = list_email.begin();
- it_tel != list_tel.end(), it_mobile != list_mobile.end(), it_fax != list_fax.end(), it_email != list_email.end(); )
- {
- strcpy(chTel, (*it_tel++).c_str());
- strcpy(chMobile, (*it_mobile++).c_str());
- strcpy(chFax, (*it_fax++).c_str());
- strcpy(chEmail, (*it_email++).c_str());
- // 发送短信;
- if( g_nSendSms==1 )
- {
- if( strcmp(chMobile, "") != 0 )
- {
- CString strMobileTel;
- strMobileTel.Format("%s",chMobile );
- if( strMobileTel.GetLength()!=11 ) continue; //判断是不是手机号码 只根据长度
- if (pSmsDllSendSms && g_bSuccesOpen)
- {
- nResult = pSmsDllSendSms(chMobile, (char *)(LPCTSTR)g_strHintSysRun, szResultMsg);
- }
-
- if( nResult != 0 ) // 发送失败
- {
- }
- }
- }
- // 发送电话语音;
- if( g_nSendNotice == 1 )
- {
- //LOG4C((LOG_NOTICE, "nWeek = %d, nHour = %d, nMinute = %d", nWeek, nHour, nMinute));
- if( strcmp(chTel, "") != 0 )
- {
- LOG4C((LOG_NOTICE, "nWeek = %d, nHour = %d, nMinute = %d, g_strHintSysRun = %s", nWeek, nHour, nMinute, g_strHintSysRun));
- // 继续加入语音发送list
- EnterCriticalSection( &g_csVarNotice );
- InsertSendNoticeList("0.0.0.0", 1, chTel, (char *)(LPCTSTR)g_strHintSysRun,0);
- LeaveCriticalSection( &g_csVarNotice );
- }
- #if 0 //移动电话 不打电话
- if( strcmp(chMobile, "") != 0 )
- {
- //LOG4C((LOG_NOTICE, "nWeek = %d, nHour = %d, nMinute = %d, g_strHintSysRun = %s", nWeek, nHour, nMinute, g_strHintSysRun));
- // 继续加入语音发送list
- EnterCriticalSection( &g_csVarNotice );
- InsertSendNoticeList("0.0.0.0", 1, chMobile, (char *)(LPCTSTR)g_strHintSysRun);
- LeaveCriticalSection( &g_csVarNotice );
- }
- #endif
- }
- }
- }
- else
- {
- if( !( nWeek == g_nTimingWeeks && nHour == g_nTimingHours && nMinute == g_nTimingMinutes ) )
- {
- g_nTimingSendFinished = 0;
- }
- }
- #endif
- }while( WaitForSingleObject( g_hRunObject, 1250L ) == WAIT_TIMEOUT );
- // 作内存释放;
- for( it_tel = list_tel.begin(), it_mobile = list_mobile.begin(), it_fax = list_fax.begin(), it_email = list_email.begin();
- it_tel != list_tel.end(), it_mobile != list_mobile.end(), it_fax != list_fax.end(), it_email != list_email.end(); )
- {
- list_tel.erase(it_tel++);
- list_mobile.erase(it_mobile++);
- list_fax.erase(it_fax++);
- list_email.erase(it_email++);
- }
- return 0;
- }
- //
- // 语音报警线程;
- // 该线程功能如下:
- // 1.判断变量值是否改变,改变则将变量发送到所有客户端,并写入数据库sumlog表里,以及写入txt日志文件中;
- // 2.判断变量采集是否超时,如果超时,写入变量值到数据库sumlog表里,并写入txt日志文件中;
- // 3.判断变量是否有报警选项,有投递到函数VarAlarmNotice进行报警处理过滤;
- DWORD WINAPI VoiceNoticeThreadProc(void *pPara)
- {
- do
- {
- // 循环所有设备
- int nDeviceSize = g_pDevicesManager->m_Devices.GetSize();
- for( int i = 0; i < nDeviceSize; i++ )
- {
- CDevice *pDev = g_pDevicesManager->m_Devices[i];
- char chDllName[MAX_PATH] = {0};
- strcpy(chDllName, (char *)(LPCTSTR)pDev->m_strProtocoldllname);
- StrLower(chDllName,chDllName);
- char szIniName[MAX_PATH] = {0};
- strcpy(szIniName, (char *)(LPCTSTR)pDev->m_strIniName);
- StrLower(szIniName, szIniName);
- char szUid[MAX_PATH] = {0};
- strcpy(szUid, (char *)(LPCTSTR)pDev->m_strUid);
- StrLower(szUid, szUid);
-
- char szPort[MAX_PATH] = {0};
- CString strPort;
- strPort.Format("%d", pDev->m_iPort);
- strcpy(szPort, (char *)(LPCTSTR)strPort);
- StrLower(szPort, szPort);
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- for( int j = 0; j < nVarSize; j++ )
- {
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- CString strTime;
- CTime tm;
- tm = CTime::GetCurrentTime();
- strTime = tm.Format("%Y-%m-%d %H:%M:%S");
- int iIndex = 0;
- // 变量的值是否在正常范围
- if( pBaseVar->m_nVarTypeID != SNMP_NPM_TYPE && pBaseVar->m_nVarTypeID != SNMP_STRING_ID )
- {
- if( (int)pBaseVar->m_dbData < pBaseVar->m_nReserved2 || (int)pBaseVar->m_dbData > pBaseVar->m_nReserved3 )
- {
- Sleep(1);
- continue;
- }
- }
- #if 0
- if( 1 == g_nSnmpEnable )
- {
- if( 0 == pBaseVar->m_dwCollectTick )
- {
- CString strSetValue;
- strSetValue.Format("%.1f", pBaseVar->m_dbData);
- CString strObjID;
- strObjID.Format("%s.%d", g_strSnmpObjOid, pBaseVar->m_nVarID);
- pSnmpDllSetValue(
- g_strSnmpIP,
- g_strSnmpField,
- (char *)(LPCTSTR)strObjID,
- "str",
- 1,
- 300,
- (char *)(LPCTSTR)strSetValue
- );
- }
- }
- #endif
- DWORD iTickCount = GetTickCount();
- // 变量值改变;
- if( TRUE == pBaseVar->m_bIsChange )
- {
- // 发送值改变了的变量到所有客户端里?
- g_pServerSocket[1]->AutoSendDataToAllClient( pBaseVar );
- // 变量实时采集,则写入数据库summlog里;
- if( TRUE == pBaseVar->m_bRealTimeflag )
- {
- // 写数据库数据日志表;
- CDBInterface::GetInstancePtr()->EditSummaryRecord(
- (char *)(LPCTSTR)pDev->m_strDeviceName, // 设备名称
- (char *)(LPCTSTR)strTime, // 发生时间
- "", // 备注
- (char *)(LPCTSTR)pBaseVar->m_strDesc, // 变量描述
- pBaseVar->m_dbData, // 变量值
- (char *)(LPCTSTR)pDev->m_strUid, // 设备Uid
- (char *)(LPCTSTR)pBaseVar->m_strName); // 变量名称
-
- EnterCriticalSection( &g_csRtuReadOneData );
- pBaseVar->m_bIsChange = FALSE;
- LeaveCriticalSection( &g_csRtuReadOneData );
- }
- // 变量实时保存,则保存日志到log.txt文件中;
- if( TRUE == pBaseVar->m_bIsSave )
- {
- WriteSummaryLog(
- (char *)(LPCTSTR)pDev->m_strDeviceName, // 设备名称
- (char *)(LPCTSTR)strTime, // 发生时间
- "", // 备注
- 0, // 现没有用到
- (char *)(LPCTSTR)pBaseVar->m_strDesc, // 变量描述
- pBaseVar->m_dbData, // 变量值
- (char *)(LPCTSTR)pDev->m_strUid, // 设备Uid
- (char *)(LPCTSTR)pBaseVar->m_strName); // 变量名称
- }
- }
- // 变量值没有改变,假如超过了采集频率,且变量有保存选项,同样上一步操作;
- else if ((( iTickCount - pBaseVar->m_dwCollectTick) > pBaseVar->m_nCollectFreq * 1000) && pBaseVar->m_bIsSave )
- {
- // 是否实时采集;
- if( TRUE == pBaseVar->m_bRealTimeflag )
- {
- CDBInterface::GetInstancePtr()->EditSummaryRecord(
- (char *)(LPCTSTR)pDev->m_strDeviceName, // 设备名称
- (char *)(LPCTSTR)strTime, // 发生时间
- "", // 备注
- (char *)(LPCTSTR)pBaseVar->m_strDesc, // 变量描述
- pBaseVar->m_dbData, // 变量值
- (char *)(LPCTSTR)pDev->m_strUid, // 设备Uid
- (char *)(LPCTSTR)pBaseVar->m_strName); // 变量名称
- }
- // 是否保存;
- if( TRUE == pBaseVar->m_bIsSave )
- {
- WriteSummaryLog(
- (char *)(LPCTSTR)pDev->m_strDeviceName, // 设备名称
- (char *)(LPCTSTR)strTime, // 发生时间
- "", // 备注
- 0, // 现没有用到
- (char *)(LPCTSTR)pBaseVar->m_strDesc, // 变量描述
- pBaseVar->m_dbData, // 变量值
- (char *)(LPCTSTR)pDev->m_strUid, // 设备Uid
- (char *)(LPCTSTR)pBaseVar->m_strName); // 变量名称
- EnterCriticalSection(&g_csRtuReadOneData);
- pBaseVar->m_dwCollectTick = GetTickCount();
- LeaveCriticalSection(&g_csRtuReadOneData);
- }
- }
- // m_bReserved2 预留2 是否触发远程报警
- // 是否触发远程报警(在函数VarAlarmNotice进行报警内容组合);
- if( pBaseVar->m_bReserved2 == TRUE )
- {
- VarAlarmNotice(pDev, pBaseVar);
- }
- }
- }
- }while( WaitForSingleObject( g_hRunObject, 5L ) == WAIT_TIMEOUT );
- return 0;
- }
- //
- // 变量输出 == 专为上海烟草局设计 ????
- DWORD WINAPI OutputThreadProc(void *pPara)
- {
- CString strClock, strTh;
- strClock.Format("%s", g_strOutputClock);
- strTh.Format("%s", g_strOutputFileName);
- //LOG4C((LOG_NOTICE, "%s", strClock));
- //LOG4C((LOG_NOTICE, "%s", strTh));
- CStdioFile fClock;
- CStdioFile fTh;
- bool bfClockResult = false;
- bool bfThResult = false;
- bfClockResult = fClock.Open(strClock, CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite);
- bfThResult = fTh.Open(strTh, CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite);
- do
- {
- CString strTime;
- CTime tm;
- tm = CTime::GetCurrentTime();
- strTime = tm.Format("%H:%M");
- strTime += "\n";
- if( bfClockResult )
- {
- //fClock.SetLength(0);
- fClock.SeekToBegin();
- fClock.Write(strTime.GetBuffer(), strTime.GetLength());
- }
- if( false == bfThResult )
- {
- Sleep(10);
- continue;
- }
- int iDeviceIndex = -1, iVarIndex = -1;
- char szVarName[MAX_UID + 1] = {0};
-
- int iSeekPos = 0;
- fTh.SeekToBegin();
- for( int iLineIndex1 = 0; iLineIndex1 < g_nOutputLineCount1; iLineIndex1++ )
- {
- // 获取输出行里的变量名;
- SplitStr(g_strOutputLine1, ',', iLineIndex1, szVarName);
- // 根据变量名,uid查找变量;
- BOOL bFind = FindVar( g_strOutputLineUid1, szVarName, iDeviceIndex, iVarIndex );
- if( bFind )
- {
- CDevice *pDev = g_pDevicesManager->m_Devices[iDeviceIndex];
- CBaseVar *pBaseVar = pDev->m_Vars[iVarIndex];
- CString strVarData;
- if( 0 == iLineIndex1 )
- {
- strVarData.Format("%.1f ", pBaseVar->m_dbData);
- fTh.Write(strVarData, strVarData.GetLength());
- }
- else if( 1 == iLineIndex1 )
- {
- strVarData.Format("%.1f%s \r\n", pBaseVar->m_dbData, pBaseVar->m_strUnit);
- fTh.Write(strVarData, strVarData.GetLength());
- }
- iSeekPos += strVarData.GetLength();
- }
- }
- for( int iLineIndex2 = 0; iLineIndex2 < g_nOutputLineCount2; iLineIndex2++ )
- {
- SplitStr(g_strOutputLine2, ',', iLineIndex2, szVarName);
- BOOL bFind = FindVar( g_strOutputLineUid2, szVarName, iDeviceIndex, iVarIndex );
- if( bFind )
- {
- CDevice *pDev = g_pDevicesManager->m_Devices[iDeviceIndex];
- CBaseVar *pBaseVar = pDev->m_Vars[iVarIndex];
- CString strVarData;
- if( 0 == iLineIndex2 )
- {
- strVarData.Format("%.1f ", pBaseVar->m_dbData);
- fTh.Write(strVarData, strVarData.GetLength());
- }
- else if( 1 == iLineIndex2 )
- {
- strVarData.Format("%.1f%s \r\n", pBaseVar->m_dbData, pBaseVar->m_strUnit);
- fTh.Write(strVarData, strVarData.GetLength());
- }
- iSeekPos += strVarData.GetLength();
- }
- }
- for( int iLineIndex3 = 0; iLineIndex3 < g_nOutputLineCount3; iLineIndex3++ )
- {
- SplitStr(g_strOutputLine3, ',', iLineIndex3, szVarName);
- BOOL bFind = FindVar( g_strOutputLineUid3, szVarName, iDeviceIndex, iVarIndex );
- if( bFind )
- {
- CDevice *pDev = g_pDevicesManager->m_Devices[iDeviceIndex];
- CBaseVar *pBaseVar = pDev->m_Vars[iVarIndex];
- CString strVarData;
- if( 0 == iLineIndex3 )
- {
- strVarData.Format("%.1f ", pBaseVar->m_dbData);
- fTh.Write(strVarData, strVarData.GetLength());
- }
- else if( 1 == iLineIndex3 )
- {
- strVarData.Format("%.1f%s \r\n", pBaseVar->m_dbData, pBaseVar->m_strUnit);
- fTh.Write(strVarData, strVarData.GetLength());
- }
- iSeekPos += strVarData.GetLength();
- }
- }
- }while( WaitForSingleObject( g_hRunObject, 100L ) == WAIT_TIMEOUT );
- // 内存释放;
- if( bfClockResult )
- {
- fClock.Close();
- }
- // 内存释放;
- if( bfThResult )
- {
- fTh.Close();
- }
- return 0;
- }
- //
- // 变量时间计划线程;
- DWORD WINAPI GetDatePlanThreadProc(void *pPara)
- {
- do
- {
- static int nStaticHours = -1;
- CTime time = CTime::GetCurrentTime();
- int nHours = time.GetHour();
- if( nStaticHours!=nHours )
- {
- LOG4C((LOG_NOTICE, _T("GetDatePlanThreadProc")));
- nStaticHours = nHours;
- // 循环所有设备
- int nDeviceSize = g_pDevicesManager->m_Devices.GetSize();
- for( int i = 0; i < nDeviceSize; i++ )
- {
- CDevice *pDev = g_pDevicesManager->m_Devices[i];
- // 循环所有变量
- int nVarSize = pDev->m_Vars.GetSize();
- for( int j = 0; j < nVarSize; j++ )
- {
- CBaseVar *pBaseVar = pDev->m_Vars[j];
- EnterCriticalSection(&g_csRtuReadOneData);
- // 从数据库中获取时间计划???
- pBaseVar->m_bExistDatePlan = CDBInterface::GetInstancePtr()->IsExistDatePlan((char *)(LPCTSTR)pDev->m_strUid, pBaseVar->m_nVarID);
- LeaveCriticalSection(&g_csRtuReadOneData);
- }
- }
- }
- }while( WaitForSingleObject( g_hRunObject, 10 * 1000L ) == WAIT_TIMEOUT );
- return 0;
- }
- //
- // 以下13个查找 串口是否使用 函数,均由主函数StartMain调用;
- BOOL FindRtuCommPort(CString strPort)
- {
- BOOL bResult = FALSE;
- for( int i = RTU_THREAD_START; i < g_nRtuThreadIndex; i++ )
- {
- if( g_strPort[i].Compare(strPort) == 0 )
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL FindAscCommPort(CString strPort)
- {
- BOOL bResult = FALSE;
- for( int i = ASC_THREAD_START; i < g_nAscThreadIndex; i++ )
- {
- if( g_strPort[i].Compare(strPort) == 0 )
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL FindTcpCommPort(CString strPort)
- {
- BOOL bResult = FALSE;
- for( int i = TCP_THREAD_START; i < g_nTcpThreadIndex; i++ )
- {
- if( g_strPort[i].Compare(strPort) == 0 )
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL FindMostDeviceCommPort(CString strPort)
- {
- BOOL bResult = FALSE;
- for( int i = MOSTDEVICE_THREAD_START; i < g_nMostDeviceIndex; i++ )
- {
- if( g_strPort[i].Compare(strPort) == 0 )
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL FindIcpdasCommPort(CString strPort)
- {
- BOOL bResult = FALSE;
- for( int i = ICPDAS_THREAD_START; i < g_nIcpdasIndex; i++ )
- {
- if( g_strPort[i].Compare(strPort) == 0 )
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL FindParadigmCommPort(CString strPort)
- {
- BOOL bResult = FALSE;
- for( int i = PARADIGM_THREAD_START; i < g_nParadigmIndex; i++ )
- {
- if( g_strPort[i].Compare(strPort) == 0 )
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL FindStulzCommPort(CString strPort)
- {
- BOOL bResult = FALSE;
- for( int i = STULZ_THREAD_START; i < g_nStulzIndex; i++ )
- {
- if( g_strPort[i].Compare(strPort) == 0 )
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL FindDaiKinCommPort(CString strPort)
- {
- BOOL bResult = FALSE;
- for( int i = DAIKIN_THREAD_START; i < g_nDaiKinIndex; i++ )
- {
- if( g_strPort[i].Compare(strPort) == 0 )
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL FindPowerwareCommPort(CString strPort)
- {
- BOOL bResult = FALSE;
- for( int i = POWERWARE_THREAD_START; i < g_nPowerwareIndex; i++ )
- {
- if( g_strPort[i].Compare(strPort) == 0 )
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL FindGreeCommPort(CString strPort)
- {
- BOOL bResult = FALSE;
- for( int i = GREE_THREAD_START; i < g_nGreeIndex; i++ )
- {
- if( g_strPort[i].Compare(strPort) == 0 )
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL FindCarelCommPort(CString strPort)
- {
- BOOL bResult = FALSE;
- for( int i = CAREL_THREAD_START; i < g_nCarelIndex; i++ )
- {
- if( g_strPort[i].Compare(strPort) == 0 )
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL FindScanTakCommPort(CString strPort)
- {
- BOOL bResult = FALSE;
- for( int i = SCANTAK_THREAD_START; i < g_nScantakIndex; i++ )
- {
- if( g_strPort[i].Compare(strPort) == 0 )
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- BOOL FindDeltaCommPort(CString strPort)
- {
- BOOL bResult = FALSE;
- for( int i = DELTA_THREAD_START; i < g_nDeltaIndex; i++ )
- {
- if( g_strPort[i].Compare(strPort) == 0 )
- {
- bResult = TRUE;
- break;
- }
- }
- return bResult;
- }
- // 获取实际波特率
- INT GetCommRate(int nRate)
- {
- int nBaudRate = 9600;
- switch( nRate )
- {
- case 0:
- nBaudRate = 1200;
- break;
- case 1:
- nBaudRate = 2400;
- break;
- case 2:
- nBaudRate = 4800;
- break;
- case 3:
- nBaudRate = 9600;
- break;
- case 4:
- nBaudRate = 14400;
- break;
- case 5:
- nBaudRate = 19200;
- break;
- case 6:
- nBaudRate = 38400;
- break;
- case 7:
- nBaudRate = 57600;
- break;
- case 8:
- nBaudRate = 115200;
- break;
- case 9:
- nBaudRate = 128000;
- break;
- case 10:
- nBaudRate = 256000;
- break;
- }
- return nBaudRate;
- }
- // 获取实际数据位
- INT GetCommDataBit(int nDataBitIndex)
- {
- int nDataBit = 8;
- switch( nDataBitIndex )
- {
- case 0:
- nDataBit = 7;
- break;
- case 1:
- nDataBit = 8;
- break;
- }
- return nDataBit;
- }
|