ItemConnection::ItemConnection(ItemModule* source, ItemModule* target, size_t socket, QGraphicsScene* scene)
	: QGraphicsItemGroup(0, scene), mSource(source), mTarget(target), mSockets(), mChildrens()
{
	mSockets.push_back(socket);

	// set z value
	setZValue(5.0);
	// set identification data
	setData(0, Identification);

	// create connection lines
	CreateConnection();
	UpdateConnection();
}
BOOL CSerialServer::Connect(char *pszDevice, DWORD dwBaudRate, int nParity, int nDataBit, int nStopBit, BOOL bFlowControl)
{
#ifdef WINCE
	CString	strDevice;
#endif
	if (IsConnected())
		return FALSE;

	if (!pszDevice || !*pszDevice)
		return FALSE;

	m_bUseFlowControl = bFlowControl;
	if (!InitializeVariable())
		return FALSE;

	strcpy(m_szDevice, pszDevice);
    m_dwBaudRate		= dwBaudRate;
	m_nByteSize			= nDataBit;
	m_nParity			= nParity;
	m_nStopBits			= nStopBit;
	m_dwOldModemStatus	= 0;
	m_dwModemStatus		= 0;
	m_dwErrorsOld		= 0;
	m_dwErrors			= 0;
	m_nKeepAliveTime	= INFINITE;
	m_bPassiveMode		= FALSE;
	m_bDisconnectPending= FALSE;
	memset(&m_ComStatOld, 0, sizeof(COMSTAT));
	memset(&m_ComStatNew, 0, sizeof(COMSTAT));

#ifdef WINCE
	strDevice = pszDevice;
	m_hComPort = CreateFile(strDevice,
							GENERIC_READ | GENERIC_WRITE, 
							0, 
							0,
							OPEN_EXISTING,
							FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
							0);
#else
	m_hComPort = CreateFile(pszDevice,
							GENERIC_READ | GENERIC_WRITE, 
							0, 
							0,
							OPEN_EXISTING,
							FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
							0);
#endif

	if (m_hComPort == INVALID_HANDLE_VALUE)
    {
        XDEBUG("[CSerialServer] Invalid Handle Value\r\n");
		return FALSE;
    }

    // Save original comm timeouts and set new ones
    if (!GetCommTimeouts(m_hComPort, &m_timeoutOld))
		XDEBUG("[CSerialServer] GetCommTimeouts.\r\n");

    // Set Port State
    UpdateConnection();

    // Set comm buffer sizes
    SetupComm(m_hComPort, MAX_READ_BUFFER, MAX_WRITE_BUFFER);

    // Raise DTR
    if (!EscapeCommFunction(m_hComPort, SETDTR))
        XDEBUG("[CSerialServer] EscapeCommFunction (SETDTR).\r\n");

	StartThread();
	m_bConnected = TRUE;
	return TRUE;
}