Example #1
0
void CMyCommView::OnBtSend() 
{
    // TODO: Add your control notification handler code here
    if (!GetDocument()->m_ComAction) 
    {
        return;
    }
    UpdateData(TRUE);
    
    int i;

    
    if(m_ctrlSendScript.GetCheck())
    {
        CString mycommand;
        CString myscript;
        char myc;
        mycommand.Empty();
        myscript = this->m_strSendData;
        for(i=0;i<myscript.GetLength();i++)
        {
            myc = myscript[i];
            if (myc==';')
            {
                DoRunScript(mycommand);
                mycommand.Empty();
            }    
            else{
                if ((myc != '\n') && (myc != '\r')) {mycommand += myc;}
            }
        } 
    }
    else if (m_ctrlSendHex.GetCheck())
    {
        char data[512];
        int len=DoStr2Hex(m_strSendData,data);
        GetDocument()->m_Comm.WriteToPort(data,len);
        GetDocument()->m_RXCount+=(long)((m_strSendData.GetLength()+1)/3);
        CMyCommApp * myApp = (CMyCommApp *)AfxGetApp();
        CString str;
        str.Format("TX:%d",GetDocument()->m_RXCount);
        myApp->DoSetStautsBarText(SBSTX,str);
    }
    else 
    {
        GetDocument()->m_Comm.WriteToPort((LPCTSTR)m_strSendData);    //发送数据
        GetDocument()->m_RXCount+=m_strSendData.GetLength();
        CMyCommApp * myApp = (CMyCommApp *)AfxGetApp();
        CString str;
        str.Format("TX:%d",GetDocument()->m_RXCount);
        myApp->DoSetStautsBarText(SBSTX,str);
    }
    
    CommCommand myCommand;
    myCommand.m_IsHex = m_ctrlSendHex.GetCheck();
    myCommand.m_isScript = m_ctrlSendScript.GetCheck();
    myCommand.m_strCommand = m_strSendData;
    m_CurrenthistoryIndex = GetDocument()->AddHistory(myCommand);
}
Example #2
0
LONG CMyCommView::OnCommunication(WPARAM ch, LPARAM port)
{
    if (m_IsViewReceiveData)
    {
        CString str;
        if (m_ctrlReceiveHex.GetCheck()) {
            str.Format("%02X ",ch);
            //m_EditLogger.AddText(str);
        } else {
            str.Format("%c",ch);
            //m_EditLogger.AddText(str);
        }

        CEdit *edit = (CEdit*)GetDlgItem(IDC_EDRECDATA);
        int nLength=edit->SendMessage(WM_GETTEXTLENGTH);  
        edit->SetSel(nLength, nLength);  
        edit->ReplaceSel(str);

        UpdateData(FALSE);
    }

    GetDocument()->m_RXCount++;
    CMyCommApp * myApp = (CMyCommApp *)AfxGetApp();
    CString str;
    str.Format("RX:%d",GetDocument()->m_RXCount);
    myApp->DoSetStautsBarText(SBSRX,str);
    m_ctrlReciveData.LineScroll(m_ctrlReciveData.GetLineCount());

    uart_on_recv_char((unsigned char)ch);

    return 0;
}
Example #3
0
void CMyCommView::OnSendkeyShiftenter() 
{
    // TODO: Add your command handler code here
    CMyCommApp * myApp = (CMyCommApp *)AfxGetApp();
    myApp->m_SendkeyType = SKSHIFTENTER;
    CButton * mybt = (CButton *) GetDlgItem(IDC_BTSEND);
    mybt->SetWindowText(_T("发送 S"));
    myApp->DoSetStautsBarText(SBSSENDKEY,"S");
}
Example #4
0
void CMyCommView::OnBtclearrxtx() 
{
    // TODO: Add your control notification handler code here
    GetDocument()->m_RXCount = 0;
    GetDocument()->m_TXCount = 0;
    CMyCommApp * myApp = (CMyCommApp *)AfxGetApp();
    myApp->DoSetStautsBarText(SBSRX,"RX:");
    myApp->DoSetStautsBarText(SBSTX,"TX:");
    
}
Example #5
0
static void fxSend(unsigned char c)
{
    currDoc->m_Comm.WriteToPort((BYTE*)&c, 1);
    currDoc->m_RXCount += 1;
    CMyCommApp * myApp = (CMyCommApp *)AfxGetApp();
    CString str;
    str.Format("TX:%d",currDoc->m_RXCount);
    myApp->DoSetStautsBarText(SBSTX,str);
    appendSentHex(&c, 1);
}
Example #6
0
void CMyCommView::DoRunScript(const CString str)
{
    CString Commandstr;
    CString Paramsstr,SendStr;
    char data[512];
    int myindex;
    int commandindex;

    if (str.GetLength()==0){return;}
    if (str[0]=='#'){return;}  //注释行不处理。
    myindex = str.Find('=',0);
    if (myindex == -1) 
    {
        //有可能是无参数的命令
        Commandstr = str;
        Commandstr.MakeUpper();
        if ((Commandstr=="CLEAR") || (Commandstr=="DATE") || (Commandstr=="HELP"))    
        {
            Paramsstr.Empty();
        } 
        else
        {
            CString ErrorStr;
            ErrorStr.Format("\n\r语法出错1 %s\n\r",str);
            m_EditLogger.AddText(_T(ErrorStr));
            return;
        }
        
    }    
    else{
        Commandstr = str.Left(myindex);
        Paramsstr  = str.Right(str.GetLength()-myindex-1);
        Commandstr.MakeUpper();
    }    
    

    if (Commandstr=="SEND")
    {
        //内容可能有#1的情况
        if ((Paramsstr.GetLength()>0) && (Paramsstr[0]=='%'))
        {
            commandindex = atoi(Paramsstr.Right(Paramsstr.GetLength()-1))-1;
            if (GetDocument()->m_Command[commandindex].m_isScript)
            {
                CString ErrorStr;
                ErrorStr.Format("\n\r语法出错,脚本不能做SEND的参数。 %s\n\r",str);
                m_EditLogger.AddText(_T(ErrorStr));
                return;    
            }
            SendStr=GetDocument()->m_Command[commandindex].m_strCommand;    
        }    
        else{
            SendStr = Paramsstr;
        }
        
        if(m_ctrlSendHex.GetCheck())
        {
            int len=DoStr2Hex(SendStr,data);
            GetDocument()->m_Comm.WriteToPort(data,len);
            GetDocument()->m_RXCount+=(long)((SendStr.GetLength()+1)/3);
            CMyCommApp * myApp = (CMyCommApp *)AfxGetApp();
            CString str;
            str.Format("TX:%d",GetDocument()->m_RXCount);
            myApp->DoSetStautsBarText(SBSTX,str);
        }
        else{
            GetDocument()->m_Comm.WriteToPort((LPCTSTR)SendStr);    //发送数据
            GetDocument()->m_RXCount+=SendStr.GetLength();
            CMyCommApp * myApp = (CMyCommApp *)AfxGetApp();
            CString str;
            str.Format("TX:%d",GetDocument()->m_RXCount);
            myApp->DoSetStautsBarText(SBSTX,str);
        }
        CEdit *edit = (CEdit*)GetDlgItem(IDC_EDRECDATAVALUE);
        int nLength=edit->SendMessage(WM_GETTEXTLENGTH);  
        edit->SetSel(nLength, nLength);  
        edit->ReplaceSel(SendStr);
    }
    else if (Commandstr=="SLEEP")
    {
        Sleep(atoi(Paramsstr));
    }
    else if (Commandstr=="OUT")
    {
        //char   re[3]   =   {VK_RETURN,   0x0a};
        SendStr = Paramsstr;
        //SendStr.Replace("\n\r","abc");
        m_EditLogger.AddText(_T(SendStr));
    }
    else if (Commandstr =="DATE")
    {
        CTime time=CTime::GetCurrentTime(); 
        CString s;
        if (Paramsstr.IsEmpty())
            s = time.Format("%Y-%m-%d %H:%M:%S");
        else    
            s = time.Format(Paramsstr);
        m_EditLogger.AddText(s);
    }    
    else if (Commandstr == "CLEAR")
    {
        OnBtclearreceivedata();
    }
    else if (Commandstr == "HELP")
    {
        CMyCommApp * myApp = (CMyCommApp *)AfxGetApp();
        m_EditLogger.AddText(myApp->m_ScriptHelp);
    }
    else{
        CString ErrorStr;
        ErrorStr.Format("\n\r语法出错2 %s\n\r",str);
        m_EditLogger.AddText(_T(ErrorStr));
    }
        
}
Example #7
0
void CMyCommView::OnBtopencomm() 
{
    // TODO: Add your control notification handler code here
    if (GetDocument()->m_ComAction) 
    {
        GetDocument()->CloseComm();

        m_ctrlOpenComm.SetWindowText(_T(" 打开串口"));
        GetDocument()->m_ComAction = FALSE;
        CMyCommApp * myApp = (CMyCommApp *)AfxGetApp();
        myApp->DoSetStautsBarText(SBSCOMM,_T("串口:×"));
    }
    else{
        
        CString mystr;
        char myc;        

        if (m_ctrlCOM.GetCurSel()<0) 
        {
            AfxMessageBox(_T("请选择串口"));
            return ;
        }    
        GetDocument()->m_intPort = m_ctrlCOM.GetCurSel()+1;
        m_ctrlBaudRate.GetWindowText(mystr);
        if (!DoIsNumeric(mystr)) 
        {    
            AfxMessageBox(_T("请选择波特率"));
            return;
        }    
        GetDocument()->m_intBaudRate = atoi(mystr);
        m_ctrlDataBits.GetWindowText(mystr);
        if (!DoIsNumeric(mystr)) 
        {
            AfxMessageBox(_T("请选择数据位"));
            return;
        }    
        GetDocument()->m_intDataBits = atoi(mystr);
        
        myc = 'N';
        int i=m_ctrlParity.GetCurSel();
        switch(i)
        {
        case 0:
            myc='N';
            break;
        case 1:
            myc='O';
            break;
        case 2:
            myc='E';
            break;
        case 3:
            myc='M';
            break;
        case 4:
            myc='S';
            break;
        }
        GetDocument()->m_cParity=myc;
        
        if (m_ctrlStopBits.GetCurSel()<0) 
        {
            AfxMessageBox(_T("请选择停止位"));
            return;
        }    
        GetDocument()->m_intStopBits = m_ctrlStopBits.GetCurSel();  //index 表示
        
        if (GetDocument()->OpenComm(this))
        {    
            CBitmap myBitmap;
            myBitmap.LoadBitmap(IDB_BITMAPOPENCOM);
            m_ctrlOpenComm.SetBitmap(myBitmap);
            m_ctrlOpenComm.SetWindowText(_T("关闭串口"));
            GetDocument()->m_ComAction = TRUE;
            CEdit * myedit = (CEdit *)GetDlgItem(IDC_EDSENDDATA);
            myedit->SetFocus();
            CMyCommApp * myApp = (CMyCommApp *)AfxGetApp();
            myApp->DoSetStautsBarText(SBSCOMM,_T("串口:√"));
        }
        else
            AfxMessageBox(_T("串口被占用!"));
    }

    // send botton
    BOOL myAction = GetDocument()->m_ComAction;
    GetDlgItem(IDC_BTSEND)->EnableWindow(myAction);
    
    // com param
    GetDlgItem(IDC_CBCOM)->EnableWindow(!myAction);
    GetDlgItem(IDC_CBBANDRATE)->EnableWindow(!myAction);
    GetDlgItem(IDC_CBDATABITS)->EnableWindow(!myAction);
    GetDlgItem(IDC_CBPARITY)->EnableWindow(!myAction);
    GetDlgItem(IDC_CBSTOPBITS)->EnableWindow(!myAction);
    GetDlgItem(IDC_BTADVANCED)->EnableWindow(!myAction);
    
}