예제 #1
0
/*-----------------------------------------------------------------------------*/
void PopulateCOMSettings(HWND hDlg) {
	char szBuffer[MAXLEN_TEMPSTR];
	WORD wCount, wPosition;

	// Fill baud combo box and make initial selection
	FillComboBox(GetDlgItem(hDlg, IDC_BPS_COMBO),
		szBaud, BaudTable, 
		sizeof(BaudTable) / sizeof(BaudTable[0]),
		BAUDRATE(TTYInfo));

	// Fill data bits combo box and make initial selection
	for (wCount = 5; wCount < 9; wCount++) {
		wsprintf(szBuffer, "%d", wCount);
		wPosition = LOWORD(SendDlgItemMessage(hDlg,
			IDC_DATABITS_COMBO, CB_ADDSTRING, 0, (LPARAM)(LPSTR)szBuffer));
	
		if (wCount == BYTESIZE(TTYInfo)) {
			SendDlgItemMessage(hDlg,
				IDC_DATABITS_COMBO, CB_SETCURSEL, (WPARAM)wPosition, 0L);
		}
	}

	// Fill parity combo box and make initial selection
	FillComboBox(GetDlgItem(hDlg, IDC_PARITY_COMBO),
		szParity, ParityTable, 
		sizeof(ParityTable) / sizeof(ParityTable[0]),
		PARITY(TTYInfo));

	// Fill stop bits combo box and make initial selection
	FillComboBox(GetDlgItem(hDlg, IDC_STOPBITS_COMBO),
		szStopBits, StopBitsTable, 
		sizeof(StopBitsTable) / sizeof(StopBitsTable[0]),
		STOPBITS(TTYInfo));
}
예제 #2
0
/*-----------------------------------------------------------------------------*/
void UpdateTTYInfo(HWND hDlg) {
	GetDlgItemText(hDlg, IDC_COMPORT_COMBO, gszPort, sizeof(gszPort));

	BAUDRATE(TTYInfo) = GetdwTTYITem(hDlg, IDC_BPS_COMBO,
		szBaud, BaudTable, sizeof(BaudTable) / sizeof(BaudTable[0]));

	PARITY(TTYInfo) = GetbTTYITem(hDlg, IDC_PARITY_COMBO,
		szParity, ParityTable, sizeof(ParityTable) / sizeof(ParityTable[0]));

	STOPBITS(TTYInfo) = GetbTTYITem(hDlg, IDC_STOPBITS_COMBO,
		szStopBits, StopBitsTable, sizeof(StopBitsTable) / sizeof(StopBitsTable[0]));

	BYTESIZE(TTYInfo) = GetDlgItemInt(hDlg, IDC_DATABITS_COMBO, NULL, FALSE);
}
예제 #3
0
/*-----------------------------------------------------------------------------*/
void InitTTYInfo() {
	// Initialize general TTY info
	COMDEV(TTYInfo)		= NULL;
	CONNECTED(TTYInfo)	= FALSE;
	PORT(TTYInfo)		= '0';			// setting to 0 since we know nothing about
										// the current COM port configuration
	BAUDRATE(TTYInfo)	= CBR_9600;
	BYTESIZE(TTYInfo)	= 8;
	PARITY(TTYInfo)		= NOPARITY;
	STOPBITS(TTYInfo)	= ONESTOPBIT;

	InitFont();
	ClearTTYContents();
}
예제 #4
0
void GPSDATA::PASER_GPS::startGPS() {
    if(conf.GPS_ENABLE == 0){
        return;
    }
    bool error;
    bool m_ReadingStarted = false;
    // repeating reconnection if problems arise
    do {
        error = false;
        try {
            // create the serial device, note it takes the io service and the port name
            m_Port = new serial_port(m_IO, conf.GPS_SERIAL_PORT);
//            m_Port = new serial_port(m_IO, "/dev/ttyS2");
        } catch (...) {
            error = true;
            PASER_LOG_WRITE_LOG(PASER_LOG_ERROR, "Problem wile trying to access port %s\n", conf.GPS_SERIAL_PORT.c_str());
            boost::xtime xt;
            boost::xtime_get(&xt, boost::TIME_UTC);

            xt.nsec += 1000000000;
            boost::thread::sleep(xt);
            // after some time try to reconnect;
        }
    } while (error);

    // prepare settings
    serial_port_base::baud_rate BAUD(conf.GPS_SERIAL_SPEED); // what baud rate do we communicate at
//    serial_port_base::baud_rate BAUD(4800); // what baud rate do we communicate at
    serial_port_base::character_size CSIZE2(8); // how big is each "packet" of data (default is 8 bits)
    serial_port_base::flow_control FLOW(serial_port_base::flow_control::none); // what flow control is used (default is none)
    serial_port_base::parity PARITY(serial_port_base::parity::none); // what parity is used (default is none)
    serial_port_base::stop_bits STOP(serial_port_base::stop_bits::one); // how many stop bits are used (default is one)

    // go through and set all the options as we need them
    // all of them are listed, but the default values work for most cases
    m_Port->set_option(BAUD);
    m_Port->set_option(CSIZE2);
    m_Port->set_option(FLOW);
    m_Port->set_option(PARITY);
    m_Port->set_option(STOP);

    if (!m_ReadingStarted) {
        boost::thread t(boost::bind(&boost::asio::io_service::run, &m_IO));
        boost::asio::async_read_until(*m_Port, b, '\n',
                boost::bind(&GPSDATA::PASER_GPS::Handler, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
        m_ReadingStarted = true;
    }

}
예제 #5
0
// Connects to, sets up and configures (if virgin) port.
void commConnect() {
	DCB dcb;
	HMENU hMenu;

	// Make sure we're not connected
	if (!CONNECTED(TTYInfo)) {
		// Menu
		hMenu = GetMenu(ghWndMain);	// get the menu handle
		EnableMenuItem(hMenu, ID_FILE_CONNECT, MF_GRAYED | MF_DISABLED); // disable the connect menu
		EnableMenuItem(hMenu, ID_FILE_DISCONNECT, MF_ENABLED); // enable the disconnect menu
		EnableMenuItem(hMenu, ID_EDIT_SETTINGS, MF_GRAYED | MF_DISABLED); // disable the TTY menu

		COMDEV(TTYInfo) = CreateFile(gszPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);

		FillMemory(&dcb, sizeof(dcb), 0);

		dcb.BaudRate = BAUDRATE(TTYInfo);	// set the baud rate
		dcb.ByteSize = BYTESIZE(TTYInfo);	// set the data bits
		dcb.fParity = PARITY(TTYInfo);		// set the parity
		dcb.StopBits = STOPBITS(TTYInfo);	// set the stop bits

		SetCommState(COMDEV(TTYInfo), &dcb);	// update the COM port configuration

		CONNECTED(TTYInfo) = TRUE;	// we are now connected (hopefully)
	}
	// Start reading thread
	TTYInfo.hThread = CreateThread(
		NULL,	// security attributes
		0,		// inital thread stack size, in bytes
		commReadThread,		// address of thread function
		ghWndTerm,	// argument for new thread
		0,		// creation flags
		&TTYInfo.hThread
	);	// address of returned thread ID
	TTYInfo.fConnected = TRUE;
}