// Crate.cpp : Implementation of CCrate #include "stdafx.h" #include "Crate.h" extern CHAR SLI6_ErrorString[1024]; void intf(int CN,PVOID param); // функция обработки прерываний // CCrate STDMETHODIMP CCrate::WriteWord(int posN, int subA, short data) { if(CrateId != 0) { //MessageBox(NULL,"Niger2","Niger2",MB_OK); // TODO: Add your implementation code here if( (this->status = cam16write(CrateId,posN,subA,(unsigned short*)&data)) == -1) error = true; else error = false; //MessageBox(NULL,"Niger3","Niger3",MB_OK); } return S_OK; } STDMETHODIMP CCrate::Open(int CardN, int CrateN) { // TODO: Add your implementation code here if(CrateId != 0) { if( (CloseCrate(CrateId)) == -1) error = true; else error = false; } if( (CrateId = OpenCrate((unsigned int)CardN,(unsigned int)CrateN)) == -1) { error = true; CrateId = 0; } else error = false; return S_OK; } STDMETHODIMP CCrate::Close() { // TODO: Add your implementation code here if(CrateId != 0) { if( (CloseCrate(CrateId)) == -1) error = true; else{ error = false; CrateId = 0; } } return S_OK; } STDMETHODIMP CCrate::ReadWord(int posN, int subA, short* data) { // TODO: Add your implementation code here if(CrateId != 0) { if( (this->status = cam16read(CrateId,posN,subA,(unsigned short*)&data)) == -1) error = true; else error = false; } return S_OK; } STDMETHODIMP CCrate::get_status(short *pVal) { // TODO: Add your implementation code here *pVal = status; return S_OK; } STDMETHODIMP CCrate::get_X(BOOL *pVal) { // TODO: Add your implementation code here *pVal = ((~status)>>7)&1; return S_OK; } STDMETHODIMP CCrate::get_Q(BOOL *pVal) { // TODO: Add your implementation code here *pVal = ((~status)>>6)&1; return S_OK; } STDMETHODIMP CCrate::get_LAMEnabled(BOOL* pVal) { // TODO: Add your implementation code here if(CrateId != 0) { *pVal = LamEnabled; } return S_OK; } STDMETHODIMP CCrate::put_LAMEnabled(BOOL newVal) { // TODO: Add your implementation code here if(CrateId != 0) { if(newVal) { // установка функции обработчика if( (SetIntOnLAMfunc(this->CrateId,intf)) == -1) error = true; // влючение прерываний if( (LAMIntEnable(this->CrateId,(PVOID)this)) == -1) error = true; else error = false; } else{ if( (LAMIntDisable(this->CrateId)) == -1) error = true; else error = false; } } return S_OK; } void intf(int CN,PVOID param) { CCrate* c = (CCrate*)param; BOOL en; c->get_LAMEnabled(&en); if(en) c->Fire_Lam(); } STDMETHODIMP CCrate::get_error(BOOL* pVal) { // TODO: Add your implementation code here *pVal = error; return S_OK; } STDMETHODIMP CCrate::get_str_error(BSTR* pVal) { // TODO: Add your implementation code here USES_CONVERSION; SysReAllocString(pVal,T2OLE(SLI6_ErrorString)); return S_OK; }