일본 Contec 사의 GPIB 카드 제어 클래스 C++
Software/C++ Builder2023. 3. 23. 10:56
반응형
1. Device : GP-IB(PCI)FL
2. 제조사 : 일본 Contec (https://www.contec.com/)
3. 국내 판매 : (주)엔씨텍크놀로지(http://www.da-view.com/)
4. 사용용도 : GPIB 통신 카드
5. 제어 클래스
typedef enum {NONE, CRLF, CR, LF} Delimiters ;
typedef enum {WITHOUT_EOI, WITH_EOI} EOI ;
class TgpibPort
{
private :
protected :
int FTimeout ;
virtual void __fastcall setTimeout(const int Timeout) { FTimeout = Timeout ; } ;
public :
virtual bool __fastcall Initialize(void) = 0 ;
virtual int __fastcall gpibPrint(int Address, AnsiString Command) = 0 ;
virtual int __fastcall gpibInput(int Address, char* Buffer, int* Count) = 0 ;
__property int Timeout = {read=FTimeout, write=setTimeout} ;
};
#include "gpibac.h" // 헤더파일은 드라이버를 설치하면 찾을 수 있습니다.
class TContecGpib : public TgpibPort
{
private :
void __fastcall setTimeout(const int Timeout) override final ;
public :
TContecGpib() ;
~TContecGpib() ;
bool __fastcall Initialize(void) override final ;
int __fastcall gpibSetup(Delimiters delim, EOI eoi) ;
int __fastcall gpibPrint(int Address, AnsiString Command) override final ;
int __fastcall gpibInput(int Address, char* Buffer, int* Count) override final ;
};
TContecGpib::TContecGpib()
{
}
//---------------------------------------------------------------------------
TContecGpib::~TContecGpib()
{
GpExit();
}
//---------------------------------------------------------------------------
bool __fastcall TContecGpib::Initialize(void)
{
bool result = false ;
int Ifctime ;
DWORD Ret, mode ;
Ret = GpExit(); // Keep off initialize repeat
Ret = GpIni(); // GP-IB initialize
if((Ret & 0x00FF) == 0) // Check of GpIni
{
GpBoardsts(0x0a, &mode); // Read Master/Slave mode
if(mode == 0) // mode == 0 (master), mode == 1 (slove)
{
Ifctime = 1; // Default
Ret = GpIfc(Ifctime); // Interface Clear
if((Ret & 0x00FF) == 0) // Check of GpIfc
{
Ret = GpRen(); // Sets REN (Remote Enable) to true.
if((Ret & 0x00FF) == 0) result = true ; // Check of GpRen
}
}
}
return result ;
}
//---------------------------------------------------------------------------
void __fastcall TContecGpib::setTimeout(const int Timeout)
{
DWORD Ret ;
Ret = GpTimeout(Timeout); // Default(10000ms)
if((Ret & 0x00FF) != 0)
{
FTimeout = Timeout ;
}
}
//---------------------------------------------------------------------------
int __fastcall TContecGpib::gpibSetup(Delimiters Delim, EOI Eoi)
{
DWORD Ret ;
int result = 0 ;
Ret = GpDelim(Delim, Eoi); // default delim = 1, Eoi = 1
if((Ret & 0x00FF) != 0) result = -1 ;
return result ;
}
//---------------------------------------------------------------------------
int __fastcall TContecGpib::gpibPrint(int Address, AnsiString Command)
{
int result = 0, srlen ;
char* srbuf ;
DWORD MyAddr, Cmd[16], Ret;
Ret = GpBoardsts(0x08, &MyAddr); // Read MyAddress
if((Ret & 0x00FF) != 0) result = -1 ;
else
{
try
{
Cmd[0] = 2 ; // Number of talkers and listeners ( = Number of listeners + 1)
Cmd[1] = MyAddr ; // Talker address
Cmd[2] = Address ; // Listener address
srlen = Command.Length() ;
srbuf = new char(srlen + 10) ;
strcpy(srbuf, Command.c_str()) ;
Ret = GpTalk(Cmd, srlen, (UCHAR*)srbuf) ;
}
__finally
{
delete[] srbuf ;
}
if(Ret != 0) result = -2 ;
}
return result ;
}
//---------------------------------------------------------------------------
int __fastcall TContecGpib::gpibInput(int Address, char* Buffer, int* Count)
{
int result = 0 ;
DWORD MyAddr, srlen, Cmd[16], Ret ;
Ret = GpBoardsts(0x08, &MyAddr); // Read MyAddress
if((Ret & 0x00FF) != 0) result = -1 ;
else
{
Cmd[0] = 2;
Cmd[1] = Address;
Cmd[2] = MyAddr;
memset(Buffer, '\0', strlen(Buffer));
srlen = *Count ;
Ret = GpListen(Cmd, &srlen, (UCHAR*)Buffer);
*Count = srlen ;
if (Ret >= 3) result = -2 ; // 0,1,2 : Normal completion
}
return result ;
}
//---------------------------------------------------------------------------
반응형
'Software > C++ Builder' 카테고리의 다른 글
c++ Builder 외부 에디터 연결 사용방법 (0) | 2023.03.31 |
---|---|
Excel 설치없이 Excel 파일로 데이타 저장 C++ (0) | 2023.03.23 |
Gradation 기능 구현 C++ (0) | 2023.03.23 |
uSec 딜레이 구현 함수 C++ (0) | 2023.03.21 |
원의 중심과 반지름을 이용한 원 그리기 C++ (0) | 2023.03.21 |
댓글()