레이블이 c&cpp인 게시물을 표시합니다. 모든 게시물 표시
레이블이 c&cpp인 게시물을 표시합니다. 모든 게시물 표시

6/07/2013

serial port cts rts checking signal cable. linux and win32



// win32

int IsCTSEnabled(int handle)
{
  int status;

  GetCommModemStatus(handle, (LPDWORD)((void *)&status));

  if(status&MS_CTS_ON) return(1);
  else return(0);
}

// linux.

// ref
/*
TIOCM_LE  DSR (data set ready/line enable)
TIOCM_DTR DTR (data terminal ready)
TIOCM_RTS RTS (request to send)
TIOCM_ST  Secondary TXD (transmit)
TIOCM_SR  Secondary RXD (receive)
TIOCM_CTS CTS (clear to send)
TIOCM_CAR DCD (data carrier detect)
TIOCM_CD  Synonym for TIOCM_CAR
TIOCM_RNG RNG (ring)
TIOCM_RI  Synonym for TIOCM_RNG
TIOCM_DSR DSR (data set ready)
*/
int RS232_IsCTSEnabled(int handle)
{
  int status;

  ioctl((int handle, TIOCMGET, &status);

  if(status&TIOCM_CTS) return(1);
  else return(0);
}








5/17/2013

dynamic allocation 3d c/c++ pointer variable.


// method 1
//
int _objCache[100][200][300];


 // method 2

int ***_objCache;
 

// allocation.

int x;
int y;

_objCache = new int ** [100];

for(x = 0; x < 100; x++)
{
        _objCache[x] = new int * [200];

        for(y = 0; y < 200; y++)
        {
                _objCache[x][y] = new int [300];
        }
}

// deallocation. 

for(x = 0; x < 100; x++)
{
        for(y = 0; y < 200; y++)
        {
                delete [] _objCache[x][y];
        }
}

for(x = 0; x < 100; x++)
{
        delete [] _objCache[x];
}

delete [] _objCache;

//////

11/11/2009

c++ namespace, class print

c++ namespace, class print

#include

namespace A
{
class B
{
public:

B() {}
void print()
{
printf("%s:%d .....\n",
__PRETTY_FUNCTION__, __LINE__);
}
};
};

int main(int argc, char** argv)
{
A::B b;
b.print();
return 0;
}

result

void A::B::print():13