⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 djjcom.~pas

📁 用delphi串口技术写成的土工试验自动衡量模块
💻 ~PAS
📖 第 1 页 / 共 5 页
字号:
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  viewstring:string;
  viewstring1:string;
  rbuf,sbuf:array[1..6] of byte;
implementation

{$R *.dfm}

procedure senddata;
var
  i:integer;
  commflg:boolean;
begin
  viewstring:='';
  commflg:=true;
  for i:=1 to 6 do
  begin
    if not form1.comm1.writecommdata(@sbuf[i],1) then
    begin
      commflg:=false;
      break;
    end;
    sleep(2);
    viewstring:=viewstring+inttohex(sbuf[i],2)+' ';
  end;
  if not commflg then messagedlg('发送失败!',mterror,[mbyes],0);
end;

procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
  BufferLength: Word);
var
  i:integer;
  receivedstring:string;
  intval:integer;
  strsinglechr,strASC:string;
  intHighhex,intLowhex:integer;
  strHex:string;
  edit1Text:double;
begin
  viewstring:='';
  setLength(receivedstring,bufferlength);
  move(buffer^,pchar(receivedstring)^,bufferlength);
  move(buffer^,pchar(@rbuf)^,bufferlength);
  for i:=1 to bufferlength do
    viewstring:=viewstring+inttobin(rbuf[i]);
    //viewstring:=viewstring+inttohex(rbuf[i],2)+' ';
  for i:=3 to bufferlength-4 do
  begin
    intval:=rbuf[i-1];
    if (intval<32) or (intval>128) then strsinglechr:=chr(46)
    else strsinglechr:=chr(intval);
    strASC:=strASC+strsinglechr;
  end;
  memo2.Text:=strASC;    //asc码
  //memo1.Text:=viewstring;  //2进制数
  //edit1Text:=strtofloat(trim(strASC));
  //edit1.Text:=floattostr(edit1text);
end;


procedure TForm1.BitBtn1Click(Sender: TObject);
  var
  temp:string;
begin
  if radioButton3.checked=true then
    temp:='COM1'
  else if radioButton4.checked=true then
    temp:='COM2'
    else if radioButton5.checked=true then
      temp:='COM3'
      else temp:='COM4';
  comm1.CommName:=Temp;
  if combobox1.text='9600' then
    comm1.BaudRate:=9600;
  if combobox1.text='4800' then
    comm1.BaudRate:=4800;
  if combobox1.text='2400' then
    comm1.BaudRate:=2400;
  if combobox1.text='1200' then
    comm1.BaudRate:=1200;
  if combobox2.text='否' then
    comm1.Parity:=none;
  if combobox2.text='奇' then
    comm1.Parity:=odd;
  if combobox2.text='偶' then
    comm1.Parity:=even;
  if combobox2.text='空' then
    comm1.Parity:=space;
  if combobox3.text='1' then
    comm1.StopBits:=_1;
  if combobox3.text='2' then
    comm1.StopBits:=_2;
  if combobox3.text='1.5' then
    comm1.StopBits:=_1_5;
  if combobox4.text='5' then
    comm1.Bytesize:=_5;
  if combobox4.text='6' then
    comm1.Bytesize:=_6;
  if combobox4.text='7' then
    comm1.Bytesize:=_7;
  if combobox4.text='8' then
    comm1.Bytesize:=_8;
  comm1.startcomm;
  BitBtn1.Enabled:=false;
  comboBox16.SetFocus;
end;

procedure TForm1.BitBtn3Click(Sender: TObject);
begin
  comm1.StopComm;
  BitBtn1.Enabled:=true;
end;

procedure TForm1.BitBtn7Click(Sender: TObject);
begin
  comm1.StopComm;
  close;
end;

procedure TForm1.Edit4Change(Sender: TObject);
begin
  BitBtn2.Enabled:=true;
end;

procedure TForm1.BitBtn8Click(Sender: TObject);
var
   m1,m2,m3,m4,m5,m6,m7,m8,m9,mm:single;
   j:integer;
begin
  if table1.FieldByName('环刀号1').value=null and checkBox55.checked=true then
  begin
    panel2.Visible:=false;
    with table1 do
    if Locate('室编号;原编号',varArrayof([comboBox16.text,comboBox17.text]),[]) then
    begin
      table1.Edit;
      table1.FieldByName('试验项目').value:='扰动样含水率';
      table1.Post;
    end;
    table1.next;
    combobox16.Text:=table1.fieldbyname('室编号').asstring;
    combobox17.Text:=table1.fieldbyname('原编号').asstring;
    edit4.setfocus;
  end else
  begin
  j:=0;
  BitBtn8.Enabled:=false;
  label34.Visible:=false;
  label35.Visible:=false;
  label36.Visible:=false;
  label37.Visible:=false;
  label38.Visible:=false;
  label39.Visible:=false;
  label40.Visible:=false;
  label41.Visible:=false;
  label42.Visible:=false;
  if panel1.visible=true then panel1.Visible:=false;
  panel2.Visible:=true;
  if table1.FieldByName('环刀号1').value<>null then checkBox46.Visible:=true;
  if pos('*',table1.FieldByName('环刀号1').asstring)>0 then checkBox46.checked:=true
    else checkBox46.checked:=false;
  if table1.FieldByName('环刀号2').value<>null then checkBox47.Visible:=true;
  if pos('*',table1.FieldByName('环刀号2').asstring)>0 then checkBox47.checked:=true
    else checkBox47.checked:=false;
  if table1.FieldByName('环刀号3').value<>null then checkBox48.Visible:=true;
  if pos('*',table1.FieldByName('环刀号3').asstring)>0 then checkBox48.checked:=true
    else checkBox48.checked:=false;
  if table1.FieldByName('环刀号4').value<>null then checkBox49.Visible:=true;
  if pos('*',table1.FieldByName('环刀号4').asstring)>0 then checkBox49.checked:=true
    else checkBox49.checked:=false;
  if table1.FieldByName('环刀号5').value<>null then checkBox50.Visible:=true;
  if pos('*',table1.FieldByName('环刀号5').asstring)>0 then checkBox50.checked:=true
    else checkBox50.checked:=false;
  if table1.FieldByName('环刀号6').value<>null then checkBox51.Visible:=true;
  if pos('*',table1.FieldByName('环刀号6').asstring)>0 then checkBox51.checked:=true
    else checkBox51.checked:=false;
  if table1.FieldByName('环刀号7').value<>null then checkBox52.Visible:=true;
  if pos('*',table1.FieldByName('环刀号7').asstring)>0 then checkBox52.checked:=true
    else checkBox52.checked:=false;
  if table1.FieldByName('环刀号8').value<>null then checkBox53.Visible:=true;
  if pos('*',table1.FieldByName('环刀号8').asstring)>0 then checkBox53.checked:=true
    else checkBox53.checked:=false;
  if table1.FieldByName('环刀号9').value<>null then checkBox54.Visible:=true;
  if pos('*',table1.FieldByName('环刀号9').asstring)>0 then checkBox54.checked:=true
    else checkBox54.checked:=false;

  //此处根据平均密度推荐一块样品作压缩
  if table1.FieldByName('密度1').value<>null then
    begin
      m1:=table1.FieldByName('密度1').value;
      j:=1;
    end else m1:=0;
  if table1.FieldByName('密度2').value<>null then
    begin
      m2:=table1.FieldByName('密度2').value;
      j:=j+1;
    end else m2:=0;
  if table1.FieldByName('密度3').value<>null then
    begin
      m3:=table1.FieldByName('密度3').value;
      j:=j+1;
    end else m3:=0;
  if table1.FieldByName('密度4').value<>null then
    begin
      m4:=table1.FieldByName('密度4').value;
      j:=j+1;
    end else m4:=0;
  if table1.FieldByName('密度5').value<>null then
    begin
      m5:=table1.FieldByName('密度5').value;
      j:=j+1;
    end else m5:=0;
  if table1.FieldByName('密度6').value<>null then
    begin
      m6:=table1.FieldByName('密度6').value;
      j:=j+1;
    end else m6:=0;
  if table1.FieldByName('密度7').value<>null then
    begin
      m7:=table1.FieldByName('密度7').value;
      j:=j+1;
    end else m7:=0;
  if table1.FieldByName('密度8').value<>null then
    begin
      m8:=table1.FieldByName('密度8').value;
      j:=j+1;
    end else m8:=0;
  if table1.FieldByName('密度9').value<>null then
    begin
      m9:=table1.FieldByName('密度9').value;
      j:=j+1;
    end else m9:=0;
  if j<>0 then
  begin
    mm:=(m1+m2+m3+m4+m5+m6+m7+m8+m9)/j;
    if (abs(mm-m1)>0.05) and (m1<>0) then
      mm:=(mm*j-m1)/(j-1);
    if (abs(mm-m2)>0.05) and (m2<>0) then
      mm:=(mm*j-m2)/(j-1);
    if (abs(mm-m3)>0.05) and (m3<>0) then
      mm:=(mm*j-m3)/(j-1);
    if (abs(mm-m4)>0.05) and (m4<>0) then
      mm:=(mm*j-m4)/(j-1);
    if (abs(mm-m5)>0.05) and (m5<>0) then
      mm:=(mm*j-m5)/(j-1);
    if (abs(mm-m6)>0.05) and (m6<>0) then
      mm:=(mm*j-m6)/(j-1);
    if (abs(mm-m7)>0.05) and (m7<>0) then
      mm:=(mm*j-m7)/(j-1);
    if (abs(mm-m8)>0.05) and (m8<>0) then
      mm:=(mm*j-m8)/(j-1);
    if (abs(mm-m9)>0.05) and (m9<>0) then
      mm:=(mm*j-m9)/(j-1);
    m1:=abs(mm-m1);
    m2:=abs(mm-m2);
    m3:=abs(mm-m3);
    m4:=abs(mm-m4);
    m5:=abs(mm-m5);
    m6:=abs(mm-m6);
    m7:=abs(mm-m7);
    m8:=abs(mm-m8);
    m9:=abs(mm-m9);
    if (m1<=m2) and (m1<=m3) and (m1<=m4) and (m1<=m5) and (m1<=m6) and (m1<=m7) and (m1<=m8) and (m1<=m9) then
      label34.Visible:=true;
    if (m2<=m1) and (m2<=m3) and (m2<=m4) and (m2<=m5) and (m2<=m6) and (m2<=m7) and (m2<=m8) and (m2<=m9) then
      label35.Visible:=true;
    if (m3<=m1) and (m3<=m2) and (m3<=m4) and (m3<=m5) and (m3<=m6) and (m3<=m7) and (m3<=m8) and (m3<=m9) then
      label36.Visible:=true;
    if (m4<=m1) and (m4<=m2) and (m4<=m3) and (m4<=m5) and (m4<=m6) and (m4<=m7) and (m4<=m8) and (m4<=m9) then
      label37.Visible:=true;
    if (m5<=m1) and (m5<=m5) and (m5<=m3) and (m5<=m4) and (m5<=m6) and (m5<=m7) and (m5<=m8) and (m5<=m9) then
      label38.Visible:=true;
    if (m6<=m1) and (m6<=m2) and (m6<=m3) and (m6<=m4) and (m6<=m5) and (m6<=m7) and (m6<=m8) and (m6<=m9) then
      label39.Visible:=true;
    if (m7<=m1) and (m7<=m2) and (m7<=m3) and (m7<=m4) and (m7<=m5) and (m7<=m6) and (m7<=m8) and (m7<=m9) then
      label40.Visible:=true;
    if (m8<=m1) and (m8<=m2) and (m8<=m3) and (m8<=m4) and (m8<=m5) and (m8<=m6) and (m8<=m7) and (m8<=m9) then
      label41.Visible:=true;
    if (m9<=m1) and (m9<=m2) and (m9<=m3) and (m9<=m4) and (m9<=m5) and (m9<=m6) and (m9<=m7) and (m9<=m8) then
      label42.Visible:=true;
  end;
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -