Home > Software engineering >  MFC com control after receiving data real-time processing
MFC com control after receiving data real-time processing

Time:09-25

I am using VS2013
I need to add in the MFC MSCom controls to receive the data returned by the equipment,
I ask is I need to press the BUTTON I interface in a certain period of time after every 0.05 seconds to send equipment current data read instructions, will read the data that I set before the critical value of comparison, more than the critical value is sent to suspend signal, not more than you will need to set until the end of the time,
The question now is I don't know how to read cache the data, and then to do data comparison, the personal god, please help, thank you,
My code:
Com control function:
Void CautotestHFDlg: : OnOncommMscomm1 ()
{
//TODO: add message handler code here
The VARIANT variant_inp;
COleSafeArray safearray_inp;
Byte rxdata [1024].
//m_recv1="";
//the UpdateData (FALSE);//update the content of the edit box
Cstrings strtemp;
If (m_com1 get_CommEvent ()==2)
{
//m_recv1="";
Variant_inp=m_com1. Get_Input ();
Safearray_inp=variant_inp;
Len=safearray_inp. GetOneDimSize ();
For (k=0; K{
Safearray_inp. GetElement (& amp; K, rxdata + k);
}
For (k=0; K{
BYTE bt=* (char *) (rxdata + k);//character
Strtemp. The Format (_T (" % c "), bt);//the character into temporary variables strtemp store
M_recv1 +=strtemp;//add receive corresponding string edit box
M_recv2 +=strtemp;//add receive corresponding string edit box
}
//m_com1 put_InputLen (0);//empty buffer content
}
The UpdateData (FALSE);//update the content of the edit box
}
The button com button Settings:
Void CautotestHFDlg: : OnBnClickedComnet ()
{
//TODO: add the control notification handler code
Cstrings STR.
GetDlgItemText (IDC_COMNET, STR);
The CWnd * h1.
H1=GetDlgItem (IDC_COMNET);
if (! M_com1. Get_PortOpen ())
{
M_com1. Put_CommPort (com);//com
M_com1. Put_InputMode (1);
M_com1. Put_Settings (_T (" 9600, e, 7, 1 "));
M_com1. Put_RThreshold (1);
//m_com1. Put_RThreshold (1);
M_com1. Put_InputLen (0);
M_com1. Put_PortOpen (true);
If (m_com1 get_PortOpen ())
{
STR=_T (" metering COM off ");
The UpdateData (true);
H1 - & gt; SetWindowText (STR);
}
}
The else
{
M_com1. Put_PortOpen (false);
If (STR!=_T (" open measurement COM "))
{
STR=_T (" open measurement COM ");
The UpdateData (true);
H1 - & gt; SetWindowText (STR);
}
}
}
Buttom read equipment storage function:
Void CautotestHFDlg: : OnBnClickedStart ()
{
For (size_t I=0; i <20; I++)//intervals of 0.1 seconds sends read instructions
{
RETR ();//read equipment data of instructions
1: how to monitor if there is a data buffer here, no words, waiting, until there are data in 2: read any, if not wait
3: read to compare the data, less than just continue,
How to add a program in here wait for com if there is a data buffer and comparing after read
Sleep (100)
}}

CodePudding user response:

Direct and member variables or global variables, storage is a critical value

CodePudding user response:


Off the plane on the communication protocol is behind each set of data with a/r/n as the end, my question now is how to determine a set of data I read finished, have a great god to help me see

CodePudding user response:

"Compiler principle" reference of lexical analysis and the finite state automata,
  • Related