Home > Software engineering > Using the SerialPort class implements a serial port communication, serial port two serial number and
Using the SerialPort class implements a serial port communication, serial port two serial number and
Time:11-12
I try to weave a two serial port to send and receive the number of software at the same time, using the SerialPort class implements the serial port, now send separately for each serial number has been completed, but the two serial ports open at the same time, send them separately with the com wizard number, there will be a serial port 1 received the number 2, the serial port will receive a number 1, 2, excuse me, what is the problem that how to change? This is a serial port 1 open Void CComTestToolDlg: : OnBnClickedButtonCom4open () { //TODO: Add your the control notification handler code here Cstrings STR. GetDlgItemText (IDC_BUTTON_Com4Open, STR); The CWnd * h1. H1=GetDlgItem (IDC_BUTTON_Com4Open);
If (STR==_T (" open the serial port 4 ")) {
M_Ports [0]. InitPort (this, 1115, 200); M_Ports [0]. StartMonitoring (); STR=_T (" close a serial port 4 "); The UpdateData (true); H1 - & gt; SetWindowText (STR); } The else { If (STR==_T (" close a serial port 4 ")) { STR=_T (" open the serial port 4 "); UpdateData(TRUE); H1 - & gt; SetWindowText (STR); } M_Ports [0]. StopMonitoring (); M_Ports [0]. ClosePort (); }
} This is a serial port 2 open Void CComTestToolDlg: : OnBnClickedButtonCom6open () { //TODO: Add your the control notification handler code here Cstrings STR. GetDlgItemText (IDC_BUTTON_Com6Open, STR); The CWnd * h1. H1=GetDlgItem (IDC_BUTTON_Com6Open);
If (STR==_T (" opens a serial port 6 ")) {
M_Ports [1]. InitPort (this, 3115, 200); M_Ports [1]. The StartMonitoring (); STR=_T (" close a serial port 6 "); The UpdateData (true); H1 - & gt; SetWindowText (STR); } The else { If (STR==_T (" close a serial port 6 ")) { STR=_T (" to open a serial port 6 "); UpdateData(TRUE); H1 - & gt; SetWindowText (STR); } M_Ports [1]. StopMonitoring (); M_Ports [1]. ClosePort (); } } This is to run screenshot
CodePudding user response:
On the physical serial port connection is? Is independent of the four serial ports two connections? If only open a set of serial port to send and receive is normal?