LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

In CVI !!!! How to dynamic change BaudRate of RS232 Serial COM Without closing the Port !!!

Solved!
Go to solution

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);   

0 Kudos
Message 1 of 3
(4,119 Views)

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...

 

 

Message 2 of 3
(4,114 Views)
Solution
Accepted by topic author lijie1116@yahoo.com.cn

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 3 of 3
(4,110 Views)