我在linux下和vc下都写写了串口程序,若是两边都是linux则两者通信正常,若是一边是linux一边是windows则windows下无法接受到我linux下程序发的数据!然而,若在linux下用minicom发送,则可以正常接收!不知道哪里的参数设置错误了!请指教,还有我的windows下采用的是winapi的串口函数! 就是CreateFile这类的!

解决方案 »

  1.   

    不知道你的windows代码怎么写的
      

  2.   

    BOOL serial_ctrl::open_set_serial_port(LPCTSTR serial_port, DCB dcb)
    {
    serial_handle = CreateFile( serial_port,
    GENERIC_READ | GENERIC_WRITE,
    0,
    NULL,
    OPEN_EXISTING,
    0,
    NULL); if( serial_handle == (HANDLE)0xFFFFFFFF)
    {
    AfxMessageBox("Open the serial port wrong");
    return FALSE;
    } if( GetCommState(serial_handle, &config) == 0)
    {
    AfxMessageBox(_T("Wrong in get configuration port."));
    return FALSE;
    } //set new configuration
    //以后添加修改波特率的bottom
    /*
    config.BaudRate = dcb.BaudRate;
    config.StopBits = dcb.StopBits;
    config.Parity = dcb.Parity;
    config.ByteSize = dcb.ByteSize;
    */ if( SetCommState(serial_handle, &config) == 0)
    {
    AfxMessageBox(_T("Wrong in set config of serial port"));
    return FALSE;
    } //set the buffer of sending and reciving
    SetupComm(serial_handle, 1024, 1024);
    PurgeComm(serial_handle, PURGE_TXCLEAR);

    //set the time out parity
    COMMTIMEOUTS com_time_out;
    memset(&com_time_out, 0, sizeof(com_time_out));
    GetCommTimeouts(serial_handle, &com_time_out);//get the time out set now //set the read time out
    //return at once while get one charater
    com_time_out.ReadIntervalTimeout = MAXDWORD;
    com_time_out.ReadTotalTimeoutConstant = 0;
    com_time_out.ReadTotalTimeoutMultiplier = 0; //set the write time out
    com_time_out.WriteTotalTimeoutConstant = 2;
    com_time_out.WriteTotalTimeoutMultiplier = 3; //set the time out parity SetCommTimeouts(serial_handle, &com_time_out); return TRUE;
    }
    我vc下的参数设置如上?不知道哪里错了~