//////////////////////////////////////////////////////////////// // CFGSocket 2004 (c) SofTech di Germinara Francesco 2000,2004 // www.germinara.it info@germinara.it // // Story: First Release 29/04/2004 // //////////////////////////////////////////////////////////////// // Checked Version: 29/4/2004 //////////////////////////////////////////////////////////////// //Use Sample : /* in MainFrm.cpp ... #include "CFGSocket.h" void CMainFrame::OnTestTest() { CString ipAddr; UINT nPorta=0; ipAddr="192.168.3.207"; nPorta=6001; BOOL sts=0; CFGSocket* pSocket=new CFGSocket(); pSocket->CreateSocket(ipAddr,nPorta); if(pSocket!=NULL){ AfxMessageBox("Ok, Dispositivo presente"); pSocket->ReadStatus(); CString msgStsInp; pSocket->ShowInputStatus(msgStsInp); AfxMessageBox(msgStsInp); pSocket->ShowOutputStatus(msgStsInp); AfxMessageBox(msgStsInp); pSocket->SetAllOutputStatus(outBit_ON); pSocket->SetOutput(); pSocket->ReadStatus(); pSocket->ShowOutputStatus(msgStsInp); AfxMessageBox(msgStsInp); pSocket->SetAllOutputStatus(outBit_OFF); pSocket->ReadStatus(); pSocket->ShowOutputStatus(msgStsInp); AfxMessageBox(msgStsInp); for(int i=0; i<16; i++){ pSocket->SetOutputStatus(i,outBit_ON); pSocket->SetOutput(); msgStsInp.Format("Set Bit: %d",i); AfxMessageBox(msgStsInp); } if(pSocket->GetInputStatus(0)==inpBit_ON){ pSocket->SetAllOutputStatus(outBit_OFF); } delete pSocket; }else AfxMessageBox("Errore. Impossibile comunicare con il dispositivo"); } */ #if !defined(AFX_CFGSocket_H__EFF53F01_FDFC_11D4_B48A_B065456AA632__INCLUDED_) #define AFX_CFGSocket_H__EFF53F01_FDFC_11D4_B48A_B065456AA632__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 // CFGSocket.h : header file // // TCP I/O command definition #define IOGet 0x75 #define IOSet 0x76 #define outBit_ON 1 #define outBit_OFF 0 #define inpBit_ON 0 #define inpBit_OFF 1 ///////////////////////////////////////////////////////////////////////////// // CCFGSocket command target class CFGSocket : public CSocket { // Attributes public: /* Utilizzata per Convertire i dati da Byte in Bits e Viceversa */ union{ struct{ unsigned char low:4; unsigned char high:4; }nibble; struct{ unsigned char b0:1; unsigned char b1:1; unsigned char b2:1; unsigned char b3:1; unsigned char b4:1; unsigned char b5:1; unsigned char b6:1; unsigned char b7:1; }bit; unsigned char byte; }dato; /* Utilizzata per Convertire i dati da Byte a Bits e Viceversa */ union udataword{ struct dataword{ unsigned char lsb; unsigned char msb; }byte; WORD dw; }word; typedef union udataword DWStatus; struct sockaddr_in addr ; // My IP address struct sockaddr_in clientAddr; // HelloDevice IP address unsigned int ipAddr; // IP address input int clientLenght; //Primi 2 bytes Input (0,1) i successivi (2,3) Output union{ BYTE IOStatus[4]; struct{ DWStatus input; DWStatus output; }porta; }StatoIO; // Operations public: CFGSocket(); virtual ~CFGSocket(); BOOL m_OpenConnection; //TRUE=A connection is open CFGSocket* CreateSocket(CString IP, UINT nPort); //Crea il socket void InitDevice(CString ipAddress,UINT nPort); unsigned int decodeAddress(CString ipAddr); //Decode a ip address BOOL TestConnection(CString IP, UINT nPort);//Test Coonnection bool ReadStatus(); void SetBit(int nBit,BOOL sts); //Setta il bit specificato void SetBit(CString strNBit,BOOL sts); //Setta il bit specificato BOOL GetBit(CString strNBit); //Leggo il Bit Specificato BOOL GetBit(int nBit); //Leggo il Bit Specificato void ShowInputStatus(CString& msgStsInp); //Visualiza stato Input void ShowOutputStatus(CString& msgStsOut);//Visualiza stato Output BOOL SetOutput(); //Scrivo output port BOOL GetInputStatus(int nBit); //Get Input status single bit BOOL GetOutputStatus(int nBit); //Get Output status single bit void SetOutputStatus(int nBit,BOOL status); //Set Output status single bit void SetAllOutputStatus(BOOL status); //Set All output status bits // Overrides public: // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CCFGSocket) public: virtual void OnAccept(int nErrorCode); //}}AFX_VIRTUAL // Generated message map functions //{{AFX_MSG(CCFGSocket) // NOTE - the ClassWizard will add and remove member functions here. //}}AFX_MSG // Implementation protected: }; ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_CFGSocket_H__EFF53F01_FDFC_11D4_B48A_B065456AA632__INCLUDED_)