標(biāo)題: QT上位機(jī)程序問(wèn)題求助(已解決附記錄) [打印本頁(yè)]

作者: heicc    時(shí)間: 2015-1-5 15:43
標(biāo)題: QT上位機(jī)程序問(wèn)題求助(已解決附記錄)
1,單片機(jī)發(fā)送數(shù)據(jù)在串口助手的顯示效果如圖   
2,在我寫(xiě)的qt中的顯示效果

  
數(shù)據(jù)出來(lái)的有點(diǎn)亂,修改半天不知道,哪里有錯(cuò)誤。
3,涉及數(shù)據(jù)處理的代碼

void MainWidget::readMyCom()//讀串口函數(shù)
{
    QByteArray temp;
    temp = myCom->readAll();
    if(!((temp.isEmpty())|(temp.isNull())))
    {
        strReBuf.append(QString(temp));
        //if(strReBuf.contains("�"))
        strReBuf.remove(QString("�"), Qt::CaseInsensitive);
        strReBuf.remove(QChar('\n'), Qt::CaseInsensitive);
        //strReBuf.re
        /*while(1)
        {
            if(strReBuf.startsWith("S"))break;
            if(strReBuf.isEmpty())break;
            strReBuf.remove(0,1);
        }
        */

        if(strReBuf.length()>=longth)emit comOver();
        //connect(this,SIGNAL(comOver()),this,SLOT(writeSheet()));
    }
}

void MainWidget::writeSheet()
{
    QString str = strReBuf.left(longth);
    strReBuf.remove(1,longth);
    textBrowser->append(str);
}

問(wèn)題解決記錄1:
原代碼中,數(shù)據(jù)傳輸終止靠最后一位結(jié)束符號(hào),修改數(shù)組后刪除結(jié)束符導(dǎo)致數(shù)組讀取越界。其實(shí)qt和stcisp讀出的數(shù)據(jù)都是錯(cuò)的,只是一直沒(méi)有注意到而已。
//電腦通信
void ClearUsbUart(void);
void SendUsbBeg(void);
void SendUSB(void);   //電腦通信

//開(kāi)門(mén)記錄樣表打印
//S Y2014 M01 D15 T11:19 Y2014 M01 D15 T11:30 U3 E
char code recode_tabel1[]={"S 2011 01 15 11:19 2016 01 15 11:30 3 E"};
char code recode_tabel2[]={"S 2012 01 15 12:30 2017 01 15 12:30 4 E"};
char code recode_tabel3[]={"S 2013 01 15 13:19 2018 01 15 13:30 5 E"};
char code recode_tabel4[]={"S 2014 01 15 14:19 2019 01 15 14:30 6 E"};
char code recode_tabel5[]={"S 2015 01 15 11:19 201a 01 15 15:30 7 E"};
void main(void)
{
    uchar i;
IoInit();
BuzzerBeed();
UartInit();
RTimeBeg(0,1);
RTimeDis();
for(i=0;i<39;i++)
  {
   TI=0;
   SBUF=recode_tabel1[ i];
   while(TI==0);
   //delay(2000);
  }
  //delay(20000);

  for(i=0;i<39;i++)
  {
   TI=0;
   SBUF=recode_tabel2[ i];
   while(TI==0);
   //delay(2000);
  }
  //delay(20000);

  for(i=0;i<39;i++)
  {
   TI=0;
   SBUF=recode_tabel3[ i];
   while(TI==0);
   //delay(2000);
  }
  //delay(20000);

  for(i=0;i<39;i++)
  {
   TI=0;
   SBUF=recode_tabel4[ i];
   while(TI==0);
   //delay(2000);
  }
  //delay(20000);

  for(i=0;i<39;i++)
  {
   TI=0;
   SBUF=recode_tabel5[ i];
   while(TI==0);
   //delay(2000);
  }

  //delay(20000);
for(;;);

目前的效果展示:








歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1