10-21-2011 02:42 AM
Dear all:
I want to change the buadrate of serial com without closing the serial com, but it failed when I use the function "SetCommConfig(m_hCom, &Com_cfg, Com_cfg_S) " to reset the buadrate ,baudrate is no change when use GetCommConfig to read back the value.
Appreciated all of your advice . TKS!
Code with WINAPI as beloow:
//
CreateFile(..) ;
GetCommState(..);
dcb.BaudRate= 1000000 ;
SetCommState(..);
//......do other things
//change baudrate to normal without closing port .
GetCommConfig(m_hCom, &Com_cfg, &Com_cfg_S);
Com_cfg.wVersion = 0X100;
Com_cfg.dwProviderSubType = 1;
Com_cfg.dcb.BaudRate =9600 ;
Com_cfg.dcb.StopBits =1 ;
SetCommConfig(m_hCom, &Com_cfg, Com_cfg_S);
GetCommConfig(m_hCom, &Com_cfg, &Com_cfg_S);
Solved! Go to Solution.
10-21-2011 03:03 AM
You can set individual attributes using the VISA library functions, e.g. viSetAttribute (, VI_ATTR_ASRL_BAUD, ).
However, I have not tried changing attributes of open ports...
10-21-2011 04:43 AM
This topic has been discussed some years ago: see here. Please note that even if I made that sample program which changes the baud rate without closing the port, I never used it in a real situation: you'll need to made your tests and check if this solution can satisfy your needs in the short and long term.