void CSerialPort::Set0WriteTimeout()
{
  COMMTIMEOUTS Timeouts;
  GetTimeouts(Timeouts);
  Timeouts.WriteTotalTimeoutMultiplier = 0;
  Timeouts.WriteTotalTimeoutConstant = 0;
  SetTimeouts(Timeouts);
}
void CSerialPort::Set0ReadTimeout()
{
  COMMTIMEOUTS Timeouts;
  GetTimeouts(Timeouts);
  Timeouts.ReadIntervalTimeout = MAXDWORD;
  Timeouts.ReadTotalTimeoutMultiplier = 0;
  Timeouts.ReadTotalTimeoutConstant = 0;
  SetTimeouts(Timeouts);
}
void CSerialPort::Set0Timeout()
{
  COMMTIMEOUTS Timeouts;
  ZeroMemory(&Timeouts, sizeof(COMMTIMEOUTS));
  Timeouts.ReadIntervalTimeout = MAXDWORD;
  Timeouts.ReadTotalTimeoutMultiplier = 0;
  Timeouts.ReadTotalTimeoutConstant = 0;
  Timeouts.WriteTotalTimeoutMultiplier = 0;
  Timeouts.WriteTotalTimeoutConstant = 0;
  SetTimeouts(Timeouts);
}
Example #4
0
OSD::OSD(MythPlayer *player, QObject *parent, MythPainter *painter)
  : m_parent(player), m_ParentObject(parent), m_CurrentPainter(painter),
    m_Rect(QRect()), m_Effects(true), m_FadeTime(kOSDFadeTime), m_Dialog(NULL),
    m_PulsedDialogText(QString()), m_NextPulseUpdate(QDateTime()),
    m_Refresh(false),   m_UIScaleOverride(false),
    m_SavedWMult(1.0f), m_SavedHMult(1.0f),   m_SavedUIRect(QRect()),
    m_fontStretch(100), m_savedFontStretch(100),
    m_FunctionalType(kOSDFunctionalType_Default), m_FunctionalWindow(QString())
{
    SetTimeouts(3000, 5000, 10000);
}
Example #5
0
int HostIO_CyUSB::OpenEx(CameraID cID)
{
	int		numDevs;
	USHORT	VID;
	USHORT	PID;
	bool	bFoundDevice = false;

	m_log->Write(2, _T("OpenEx name: %s"), cID.SerialToOpen.c_str());
	
	numDevs = cyusb_open();

	for (int i = 0; i < (int)numDevs; i++) 
	{
		h = cyusb_gethandle(i);
		VID = cyusb_getvendor(h);
		PID = cyusb_getproduct(h);

		std::string SerialNum = std::string("None");
		GetSerialNumber(SerialNum);
		std::string SerialToOpen = SerialNum;
		
		std::string Desc = std::string("None");
		GetDesc(Desc);

		m_log->Write(2, _T("Dev %d:"), i);
		m_log->Write(2, _T(" SerialNumber=%s"), SerialNum.c_str());
		m_log->Write(2, _T(" Description=%s"), Desc.c_str());

		if (VID == QSICyVID && PID == QSICyPID && SerialNum == cID.SerialToOpen )
		{
			m_log->Write(2, _T("USB Open found QSI Cy device at index: %d, Serial: %s, Description: %s"), 
							i, SerialNum.c_str(), Desc.c_str());
			bFoundDevice = true;
			break;
		}
	}
	
	if (bFoundDevice && cyusb_kernel_driver_active(h, 0) == 0 && cyusb_claim_interface(h, 0) == 0)
	{
		SetTimeouts(READ_TIMEOUT, WRITE_TIMEOUT);		
	}
	else
	{
		m_log->Write(2, "No devices matched");
	}

	m_log->Write(2, _T("OpenEx Done."));

	return bFoundDevice ? ALL_OK : ERR_USB_OpenFailed;
}
Example #6
0
int HostIO_CyUSB::SetStandardWriteTimeout( int ulTimeout)
{
	m_IOTimeouts.StandardWrite = ulTimeout;
	return SetTimeouts(m_IOTimeouts.StandardRead, m_IOTimeouts.StandardWrite);
}
Example #7
0
int HostIO_TCP::OpenEx(CameraID cID)
{
	int iError;
	u_long IO_NONBLOCK = 1;
	u_long IO_BLOCK = 0;
	struct timeval tv;
	// 5 second timeout
	tv.tv_sec = 5;	
    tv.tv_usec = 0;
	fd_set wfdset;
	fd_set rfdset;

	if (cID.IPv4Addr.s_addr == 0)
	{
		m_log->Write(2, _T("TCP/IP address is zero. Open failed."));
		return ERR_PKT_OpenFailed;
	}

	if (!m_TCP_Stack_OK)
	{
		m_log->Write(2, _T("TCP/IP WSAStartup failed. No stack available. Open failed."));
		return ERR_PKT_OpenFailed;
	}

	// Create a SOCKET for connecting to server
	m_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (m_sock < 0)
	{
		TCPIP_ErrorDecode();		
		m_log->Write(2, _T("TCP/IP: Error at socket(): %d."), m_sock) ;
		return ERR_PKT_OpenFailed;
	}

	iError = ioctl(m_sock, FIONBIO, &IO_NONBLOCK);
	if (iError < 0)
	{
		TCPIP_ErrorDecode();		
		m_log->Write(2, _T("TCP/IP: Error at ioctl(FIONBIO): %d."), m_sock) ;
		return ERR_PKT_OpenFailed;
	}
	
	m_log->Write(2, _T("TCP/IP: socket() is OK.") );
 
	// The sockaddr_in structure specifies the address family,
	// IP address, and port of the server to be connected to.
	sockaddr_in clientService;
	clientService.sin_family = AF_INET;
	clientService.sin_addr.s_addr = htonl(cID.IPv4Addr.s_addr);
	clientService.sin_port = htons(27727);
	// Connect to server.
	if ( connect(m_sock, (sockaddr*)&clientService, sizeof(clientService)) < 0)
	{
		m_log->Write(2, _T("TCP/IP: Failed to connect."));
		return ERR_PKT_OpenFailed;
	}

    FD_ZERO(&rfdset);
    FD_SET(m_sock, &rfdset);

	FD_ZERO(&wfdset);
    FD_SET(m_sock, &wfdset);

	iError = select(m_sock + 1, &rfdset, &wfdset, NULL, &tv);

	if (iError == 0)
	{
		// Select timout with no connection.
		close(m_sock);
		m_log->Write(2, _T("TCP/IP: Failed to connect after select timeout."));
		return ERR_PKT_OpenFailed;
	}

	if (iError == -1 )
	{
        TCPIP_ErrorDecode();
		m_log->Write(2, _T("TCP/IP: Failed to select."));
		close(m_sock);
		return ERR_PKT_OpenFailed;
	}

	ioctl(m_sock, FIONBIO, &IO_BLOCK);
	SetTimeouts(m_IOTimeouts.StandardRead, m_IOTimeouts.StandardWrite);
	m_log->Write(2, _T("TCP/IP: connect() is OK.") );
	
	return 0;
}
Example #8
0
int HostIO_TCP::SetStandardWriteTimeout( int ulTimeout)
{
	m_IOTimeouts.StandardWrite = ulTimeout;
	m_log->Write(2,  _T("TCP/IP SetStandardWriteTimeouts Done."));
	return SetTimeouts(m_IOTimeouts.StandardRead, m_IOTimeouts.StandardWrite);
}
Example #9
0
VOID CATOLECRList::PassCmd(BSTR ID, LPBYTE lpUncodedCmd, DWORD dwCmdLen, 
						   LPBYTE lpDecodedRsp, DWORD &dwRspLen, 
						   LONG *pErrorCode)
{
	BOOL bSuccess = FALSE;
	BYTE nResponse, nEncodedCmd[CMD_LEN], nEncodedRsp[CMD_LEN];
	DWORD dwRetry = 0;
	CECRConnection *pConnection = GetConnection(ID);
	
	if (pConnection == NULL)
	{
		*pErrorCode = E_NOT_FOUND;
		return;
	}

	// подготовка данных команды к отправке
	ZeroMemory(nEncodedRsp, CMD_LEN);
	EncodeCmd(lpUncodedCmd, nEncodedCmd, dwCmdLen);

	// отправка запроса ENQ
	SetTimeouts(pConnection, T_T1, T_TW);
	do
	{
		COMM_OPERATION(ClearError(pConnection, pErrorCode), 100);
		COMM_OPERATION(PurgeComm(pConnection->m_hCommPort, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR), 0);
		COMM_OPERATION(WriteByte(pConnection, ENQ), 1);
		if (ReadByte(pConnection, &nResponse))
		{
			if (nResponse == ACK)
				// приемник готов к установке связи
				break;

			if (nResponse == ENQ)
			{
				// конфликтная ситуация
				Sleep(T_T7);
				SaveDumpString("ENQ Conflict\n");
			}
			else
			{
				// неверный ответ на запрос установки связи
				Sleep(T_T1);
				SaveDumpString("Wrong ENQ answer\n");
			}
		}

		// увеличиваем счетчик попыток
		dwRetry++;
	}
	while (dwRetry < N_ENQ_RETRY);
	CHECK_EQUALS(dwRetry, N_ENQ_RETRY, 3);

	// отправка команды
	dwRetry = 1;
	SetTimeouts(pConnection, T_T3, T_TW);
	do
	{
		COMM_OPERATION(WriteBuffer(pConnection, nEncodedCmd, dwCmdLen), 4);
		COMM_OPERATION(ReadByte(pConnection, &nResponse), 5);
		if (nResponse == ACK)
			break;
		
		// увеличиваем счетчик попыток
		SaveDumpString("NAK received on command\n");
		dwRetry++;
	}
	while (dwRetry < N_CMD_RETRY);
	CHECK_EQUALS(dwRetry, N_CMD_RETRY, 6);

	// закрытие сеанса связи
	COMM_OPERATION(WriteByte(pConnection, EOT), 7);

	// определяем таймаут ожидания ответа
	DWORD dwResponseWaitTimeout = 0;
	switch (nEncodedCmd[3])
	{
		case 0x4A:
		case 0x62:
		case 0xA7:
		case 0xA6:
		case 0x8D:
		case 0x8E:
			dwResponseWaitTimeout = 20000;
			break;
		case 0xA8:
		case 0xA9:
		case 0xAA:
		case 0xAB:
		case 0xAC:
		case 0xAD:
		case 0x5A:
			dwResponseWaitTimeout = 120000;
			break;
		case 0x91:
			dwResponseWaitTimeout = 45000;
			break;
		default:
			dwResponseWaitTimeout = T_T5;
	}

	// ждем ответ
	SetTimeouts(pConnection, dwResponseWaitTimeout, T_TW);
	COMM_OPERATION(ReadByte(pConnection, &nResponse), 8);
	CHECK_NOT_EQUALS(nResponse, ENQ, 80);
	COMM_OPERATION(WriteByte(pConnection, ACK), 9);

	// принимаем ответ
	dwRetry = 1;
	do
	{
		ZeroMemory(nEncodedRsp, CMD_LEN);
		COMM_OPERATION(GetResponse(pConnection, nEncodedRsp, dwRspLen), 10);
		
		// проверяем CRC
		if (IsValidCRC(nEncodedRsp, dwRspLen))
			break;

		// отправляем отказ 
		COMM_OPERATION(WriteByte(pConnection, NAK), 11);

		// увеличиваем счетчик попыток
		SaveDumpString("Response CRC error\n");
		dwRetry++;
	}
	while (dwRetry < N_CMD_RETRY);
	CHECK_EQUALS(dwRetry, N_CMD_RETRY, 12);

	// отправка подтверждения получения ответа
	COMM_OPERATION(WriteByte(pConnection, ACK), 13);
	// завершение сеанса связи
	SetTimeouts(pConnection, T_T4, T_TW);
	COMM_OPERATION(ReadByte(pConnection, &nResponse), 14);

	// декодируем ответ
	DecodeRsp(nEncodedRsp, lpDecodedRsp, dwRspLen);

	// проверяем результат выполнения команды
	((lpDecodedRsp[0] == 'U') && (lpDecodedRsp[1] != 0)) ? 
		*pErrorCode = lpDecodedRsp[1] : *pErrorCode = E_SUCCESS;

	// если команда выполнена с ошибкой
	// и код команды отличен от 0x45 (запрос кода состояния)
	if ((*pErrorCode != E_SUCCESS) && (nEncodedCmd[3] != 0x45))
	{
		// сохраняем дамп команды и дамп ответа
		SaveCommandDump(nEncodedCmd, nEncodedRsp, CMD_LEN, 0xFF);
	}
}
Example #10
0
BOOL CATOLECRList::GetResponse(CECRConnection* pConnection, LPBYTE lpResponse, DWORD &dwSize)
{
	BOOL bEof = FALSE, bMasked = FALSE;
	dwSize = 0;

	// ожидаем STX
	SetTimeouts(pConnection, T_T2, T_TW);
	do
	{
		BOOL bResult = ReadByte(pConnection, lpResponse);
		if (!bResult)
			return FALSE;
	}
	while (lpResponse[dwSize] != STX);
	dwSize++;

	// читаем остальные данные ответа
	SetTimeouts(pConnection, T_T6, T_TW);
	do
	{
		BOOL bResult = ReadByte(pConnection, lpResponse + dwSize);
		if (!bResult)
			return FALSE;

		if (!bEof)
		{
			switch(lpResponse[dwSize]) 
			{
				case DLE:
					bMasked = !bMasked;
					break;
				case ETX:
					bEof = !bMasked;
					bMasked = FALSE;
					break;
				default:
					bMasked = FALSE;
			}
		}

		dwSize++;
	}
	while (!bEof);

	// читаем контрольную сумму
	BOOL bResult = ReadByte(pConnection, lpResponse + dwSize);
	if (!bResult)
		return FALSE;

	dwSize++;
	return TRUE;

	
	

/*
	BYTE nBuffer[CMD_LEN];
	DWORD dwBytesRead, dwStartTick = GetTickCount();
	BOOL bMasked = FALSE, bEof = FALSE, bSuccess = FALSE;

	dwSize = 0;
	ZeroMemory(lpData, CMD_LEN);
	SetTimeouts(pConnection, T_T2, T_TW);

	do 
	{
		dwBytesRead = 0;
		ZeroMemory(nBuffer, CMD_LEN);
		BOOL bResult = ReadFile(hFile, nBuffer, CMD_LEN, &dwBytesRead, NULL);

		for (DWORD i = 0; i < dwBytesRead; i++)
		{
			if ((dwSize == 0) && (nBuffer[i] != STX))
				continue;

			lpData[dwSize] = nBuffer[i];
			dwSize++;

			if (bEof)
				return TRUE;

			switch(nBuffer[i]) 
			{
				case DLE:
					bMasked = !bMasked;
					break;
				case ETX:
					bEof = !bMasked;
					bMasked = FALSE;
					break;
				default:
					bMasked = FALSE;
			}
		}
	} 
	while((GetTickCount() - dwStartTick) < dwTimeout);
	return FALSE;*/
}