要用计算机取数,手头有一份提供的接口(源码),但是是针对3KG写的。现在还需要在3Kg以上的秤上使用同一接口,波特率等参数不同,现在的接口是把参数定义成const了,要想这两种秤都能用该怎么写代码呢?该怎么判断应该用哪种参数呢?

解决方案 »

  1.   

    pchaos(无言,独上西楼):怎么做呢具体?我想在程序里判断当前连的是哪种秤
      

  2.   

    用mscomm控件取数。mscomm控件的几个重要属性如下:
    settings:=1200,e,7,1;
    rthresthord:=40;
    inputlength:=0;具体的取数方式有两种:1.定时方式 2.用mscomm控件的oncomm事件取数.
    下面的一种是用oncomm事件取数,程序已经在现场使用,完全没有问题.procedure Tjiao_form.MSComm1Comm(Sender: TObject);
    var
    n,i:integer;
    begin
    if mscomm1.CommEvent =comevreceive then
    begin
        s:='';
        s:=mscomm1.Input ;
        n:=length(s);
        s:=copy(s,n-40,41);
        n:=0;
        n:=pos(#2,s);
        s:=trim(copy(s,n+4,6));
        if  s=''  then
            s:='0'
        else
            for i:=1 to length(s) do
                if copy(s,i,1)=' ' then
                    begin
                        s:='0';
                        exit;
                    end;
    end;
    end;