解决方案 »

  1.   

    你用新点版本的Delphi开发下吧,比如Delphi XE2以上,它修复了很多内在bug。
      

  2.   

     ED 1C 24 代表什么?周期性的出现还是就这一条呢,觉得像设备端口重启或者初始化的初始值,下面也好像有类似的数据,还有 22 B1 4C 这个。像是一次传上来8组数据。
      

  3.   


    ED 1C 24 代表图片的位置(x,y)0,0的rgb数据,为红绿蓝,上面的FF 00 00 是正确的
      

  4.   

    每次取8个点的rgb数据上传,通信协议如下:
    //通信协议: 始码2  +  sin   +   列数   +   数据24   +   校验1   +   尾码  = 31字节 (累加和校验)
    //通信协议: $ @    +  0~11      0~127      数据24       校验1        * #
      

  5.   


    您分析的有这个可能,我有空测试一下。主要对delphi7情有独钟,瘦小的身材、强大的功能...以后的版本太臃肿了。难道D7真的不行吗?只要有可能,还是希望用D7做这个项目
      

  6.   

    一直用DELPHI做串口软件,没觉得版本会影响数据返回的,觉得跟内在BUG关系不大。
    你可以找个第三方串口软件试下,看看有没delphi7上面一样的数据返回。
    而且数据都有校验,就算是你觉得是错误的数据,它的校验又没错,说明是真真实实你接收到的反馈数据,不是delphi的BUG数据啊。
      

  7.   

    用spcomm、ComPort这两个组件都是这个情况,最后删除串口组件(上传的源码),直接在窗口显示数据,发现采集的rgb三基色数据还是是错误的(如图)。看来,和串口组件没有关系。
      

  8.   

    将程序移植到 Delphi XE5,第1个问题(sin1数据错乱)得到解决;第2个问题(发到 0x24 0x40 0x05 0x67 ...  时,程序瘫痪)还是不行,好像是程序占用到几M内存后,就崩溃了!
      

  9.   

    不像是delphi的问题,最好用串口测试程序测试一下。
      

  10.   

    #8 已确定是D7的bug,以下是XE5代码。现在的问题是,启动更新就不停增加内存占用,占用到几M内存后,就崩溃了!怎么释放内存呢?procedure TFormMain.Timer1Timer(Sender: TObject);
    var
      c: TColor;
      s1 : string;
      w_count : Integer;
      //pt: TPoint;
      newstr1,he,oldstr:string;  //校验和
      tj:boolean;
      i:integer;
    begin
      Timer1.Enabled := False;
      //GetCursorPos(pt);   //获取光标
      //Label1.Caption := inttostr(pt.X - Fl);
      //Label2.Caption := inttostr(pt.Y - Ft);
      uart_rx_sign := True;
      if uart_rx_sign = True then
      begin
        uart_err_columns := 0;
        w_count := 0;
            rgb_str := '';
            while (w_count < 8) do  //每次取8个点
            begin
              //c := GetPixel(GetDC(0), Fl+14+tu_x, Ft+70+tu_y); //xp    +4 +40
              c := GetPixel(GetDC(0), Fl+18+tu_x, Ft+132+tu_y);   //win7   +8 +32
              s1 := Format('%.6x', [c]); // B G R    MidStr
              rgb_str := rgb_str + MidStr(s1,5,2);
              rgb_str := rgb_str + MidStr(s1,3,2);
              rgb_str := rgb_str + MidStr(s1,1,2);
              //rgb_str := rgb_str + inttohex(c,6);
              //int r = (c & 0xFF);//转换R
              //int g = (c & 0xFF00) / 256;//转换G
              //int b = (c & 0xFF0000) / 65536;//转换B
              //FrmMain.Canvas.Pixels[138+10+tu_x, 30+tu_y]   :=   c;//同步画图
              if tu_y < 95 then inc(tu_y)
              else
              begin
                tu_y := 0;
                if tu_x < 127 then inc(tu_x)
                else tu_x := 0;
              end;          inc(w_count);
            end;
            //Label1.Caption := 'S1: ' + s1;
              //Label2.Caption := 'RGB: ' + rgb_str;
            i:=1;    //校验和-------------------------------
            he:='';
            tj:=true;
            oldstr:=copy(rgb_str,1,length(rgb_str));
            while tj=true do
            begin
              newstr1:=copy(oldstr,i,2);
              oldstr:=copy(oldstr,i+2,length(oldstr)-2);
              //开始计算校验和并给he变量
              if he='' then
                begin
                  he:=inttohex(strtointdef('$'+newstr1,16)+ strtointdef('$'+'00',16),2);
                  he:=rightstr(he,2);
                end
              else
                begin
                  he:=inttohex(strtointdef('$'+newstr1,16)+ strtointdef('$'+he,16),2);
                  he:=rightstr(he,2);
                end;
              if  length(oldstr) =0 then tj:=false;
            end;
            rgb_str := rgb_str + he;
            uart_str := '$@' + HexStrToStr(IntToHex(led_sin,2)) + HexStrToStr(IntToHex(led_columns,2)) + HexStrToStr(rgb_str) + '*#';
            //SendString(uart_str);
            //Edit2.Text := StrToHexStr(uart_str);
            mmoSend.Lines.Add(StrToHexStr(uart_str));
            uart_rx_sign := False;
          if led_sin < 11 then Inc(led_sin)
          else
          begin
            led_sin := 0;
            if led_columns < 127 then  inc(led_columns)
            else
            begin
              led_columns := 0;
              Timer1.Enabled := False;
              Button1.Caption := '更新';
            end;
          end;
          Edit1.Text := IntToStr(led_sin);
            Edit2.Text := IntToStr(led_columns);
            Edit3.Text := IntToStr(tu_x);
            Edit4.Text := IntToStr(tu_y);
       // FlatProgressBar1.Position := trunc((led_sin + led_columns*12)/15); //进度条
      end
      else   //出错处理----------------------
      begin
        Inc(uart_err_columns);
        //Label1.Caption := '状态: ' + IntTostr(uart_err_columns) + ' 错误计数';
        if uart_err_columns > 100 then
        begin
          uart_err_columns := 0;
          //Label1.Caption := '状态: ' + HexStrToStr(IntToHex(led_sin,2)) + ' ' + HexStrToStr(IntToHex(led_columns,2)) + ' 故障';
          Label1.Caption := '状态: ' + IntToHex(led_sin,2) + ' ' + IntToHex(led_columns,2) + ' 故障';
          Timer1.Enabled := False;
            Button1.Caption := '更新';
        end
        else if uart_err_columns = 20 then
        begin
         //SendString(uart_str);
            //Edit2.Text := StrToHexStr(uart_str);
        end
        else if uart_err_columns = 40 then
        begin
          //SendString(uart_str);
            //Edit2.Text := StrToHexStr(uart_str);
        end
        else if uart_err_columns = 60 then
        begin
          //SendString(uart_str);
            //Edit2.Text := StrToHexStr(uart_str);
        end;
      end;
      if Button1.Caption = '更新中...' then Timer1.Enabled := True;
    end;
      

  11.   

    将程序移植到 Delphi XE5,还是不行,好像是程序占用到几M内存后,就崩溃了! 
    无奈地放弃 可爱的“Delphi ”,转c#了。谢谢朋友们的支持!