Beispiel #1
0
static void
ser_console_done_wait_handle (struct serial *scb)
{
    struct ser_console_state *state = scb->state;

    if (state == NULL)
        return;

    stop_select_thread (state);
}
SerialInterface::SerialStatus SerialInterface::close_port()
{
        if (in_on_receive_data)
        {
                called_close_port = true;
                return SS_Success;
        }
        
        called_close_port = false;
        
        if (is_open())
        {
                stop_select_thread();
                
                #ifdef __unix__
                
                tcsetattr(port_fd, TCSANOW, &port_termios_saved);
                tcflush(port_fd, TCOFLUSH);
                tcflush(port_fd, TCIFLUSH);
                close(port_fd);
                port_fd = -1;
                
                #elif defined _WIN32
                
                SetCommState(h_port, &dcb_serial_params_saved);
                CloseHandle(h_port);
                CloseHandle(h_overlapped);
                CloseHandle(h_overlapped_thread);
                h_port = INVALID_HANDLE_VALUE;
                h_overlapped = INVALID_HANDLE_VALUE;
                h_overlapped_thread = INVALID_HANDLE_VALUE;
                
                #endif
                
                if (debug)
                        std::cout << "Port closed." << std::endl;
                
                m_port_closed.emit();
        }
        
        return SS_Success;
}