123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- #ifndef LIBFRAMEWORK_GPIO_IMPL_H
- #define LIBFRAMEWORK_GPIO_IMPL_H
- #include "GpioClass.h"
- #include "IOSignalCtrBoardDev.h"
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <cassert>
- #include <string>
- #include <iostream>
- //bhj
- #include "ExactTick.h"
- #if (defined _WIN32 || defined _WIN64)
- #include "windows.h"
- #ifndef AFX_ODEVBASE_H__8BBC195A_112D_11D4_B865_5254AB1A7D30__INCLUDED_COM_
- #define AFX_ODEVBASE_H__8BBC195A_112D_11D4_B865_5254AB1A7D30__INCLUDED_COM_
- #pragma pack(push, 1)
- // typedef struct tDevReturn
- // {
- // int iLogicCode;
- // int iPhyCode;
- // int iHandle;
- // int iType;
-
- // char acDevReturn[128];
- // char acReserve[128];
- // } tDevReturn;
- #pragma pack(pop)
- #define SUCCESS 0
- #define FAIL 1
- #define ERRORFLAG_CLEAR 0
- #endif // AFX_ODEVBASE_H__8BBC195A_112D_11D4_B865_5254AB1A7D30__INCLUDED_COM_
- #define snprintf _snprintf
- #else //
- #include <unistd.h>
- #include <dlfcn.h>
- #include <cwchar>
- typedef void* HMODULE;
- //typedef void* HANDLE;
- typedef unsigned int UINT;
- HMODULE LoadLibraryA(const char* lpLibFileName)
- {
- std::string l_szLibFileName = lpLibFileName;
- l_szLibFileName = "lib"+l_szLibFileName.substr(0, l_szLibFileName.rfind(".dll", l_szLibFileName.length()))+".so";
- void* h = dlopen(l_szLibFileName.c_str(), RTLD_NOW);
- printf("LoadLibrary %s = %p \r\n", l_szLibFileName.c_str(), h);
- return (HMODULE)h;
- }
- void* GetProcAddress(HMODULE hModule, const char* lpProcName)
- {
- return (void*)dlsym(hModule, lpProcName);
- }
- int FreeLibrary(HMODULE hLibModule)
- {
- if (NULL==hLibModule)
- {
- return 0;
- }
- int l_bRet = 0==dlclose(hLibModule);
- printf("FreeLibrary %p \r\n", hLibModule);
- return l_bRet;
- }
- #define NOERROR 0
- #define UNREFERENCED_PARAMETER(p) if ((p)!=NULL)assert(p)
- #define WINAPI
- #define LoadLibrary LoadLibraryA
- typedef unsigned int WPARAM;
- typedef unsigned char BYTE;
- #ifndef GRGDEVBASE_H
- #define GRGDEVBASE_H
- #pragma pack(push, 1)
- typedef struct tDevReturn
- {
- int iLogicCode;
- int iPhyCode;
- int iHandle;
- int iType;
-
- char acDevReturn[128];
- char acReserve[128];
- } tDevReturn;
- #pragma pack(pop)
- #define SUCCESS 0
- #define FAIL 1
- #define ERRORFLAG_CLEAR 0
- #endif // GRGDEVBASE_H
- #endif // _WIN32
- #pragma pack(push, 1)
- #include "IOExtendDev.h"
- #pragma pack(pop)
- #define DEVCLASSNAME IOExtendDev
- #define DEVCLASSPARA "grgIOExtendDev.dll"
- #define SAVETRACE(sz) printf("%s,%s,%d:%s\n", __FILE__, __FUNCTION__, __LINE__, (sz));
- DEVCLASSNAME* g_pDev = NULL;
- //////////////////////////////////////////////////////////////////////////
- class GPIOClassImpl : public GpioClass
- {
- public:
- GPIOClassImpl();
- ~GPIOClassImpl();
- //DeviceBaseClass
- ErrorCodeEnum GetDevCategory(DevCategoryInfo &devCategory);
- ErrorCodeEnum Reset();
- ErrorCodeEnum DevClose();
- ErrorCodeEnum GetLastErr(DevErrorInfo &devErrInfo);
- //
- // Device initialization.
- // Configure port input/output direction.
- //
- virtual ErrorCodeEnum DevOpen(GpioInitParam initParam);
- //
- // Set ports output.
- // Arguments:
- // - dwPort:port serial number,0~MAX_PORT_NUM-1
- // - btData:output value
- // bit value 1/0 means voltage high or low
- // ex.dwPort=0 btData=10001010 means set port 0's the 2nd,4th,8th pin output high
- //
- virtual ErrorCodeEnum WritePort(DWORD dwPort, BYTE btData);
- //
- // Get port input.
- // Arguments:
- // - dwPort:port serial number,0~MAX_PORT_NUM-1
- // - btStatus:input value
- // ex.dwPort=0 btStatus=10001010 means port 0's the 2nd,4th,8th pin with high level
- //
- virtual ErrorCodeEnum ReadPort(DWORD dwPort, BYTE& btStatus);
- private:
-
- int m_mode;
- void* m_pHandle;
- DevErrorInfo m_DevErrorInfo;
- GpioInitParam m_GpioParm;
- void ZeroDevErrorInfo();
- void FormatDevErrorInfo(const char* funcname, int line, int errCode,const char* errStr);
- //light
- bool vChangeTable(int &p_iGrg, int &p_iZS, bool p_bToZS = true);
- void vGetLightStatus(BYTE *p_pbtStatus, tDevReturn *p_ptDevReturn);
- int iGetLightStatus(int p_piLightNum, tDevReturn *p_psStatus);
- //IO in
- int iGetIOInStatus(int p_piLightNum, tDevReturn *p_psStatus);
- void vGetIOInStatus(BYTE *p_pbtStatus, tDevReturn *p_ptDevReturn);
- bool vChangeTableIOIn(int &p_iGrg, int &p_iZS, bool p_bToZS = true);
- //IO扩展板接口
- int ExiSetCommPara(const char* funcname, int line);
- int ExiCloseComm(const char* funcname, int line);
- int ExiInit(const char* funcname, int line);
- int ExiGetVersion(const char* funcname, int line);
- int ExiGetDevVersion(const char* funcname, int line);
- int ExiGetSerialNumber(const char* funcname, int line);
- int ExiGetLightStatus(const char* funcname, int line);
- int ExiSetLightStatus(int p_piLightNum, int p_piStatus,const char* funcname, int line);
- };
- #endif //LIBFRAMEWORK_GPIO_IMPL_H
|