久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 6232|回復: 1
打印 上一主題 下一主題
收起左側

上位機與S7-200 cpu224自由口通訊之上位機源程序

[復制鏈接]
跳轉到指定樓層
樓主
ID:72519 發表于 2015-1-23 00:34 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式








{本程序為s7-200 cpu224自由口通訊實驗,由上位機發送,PLC返回查詢輸入輸出狀態
1.01 xx FF;若為$01開頭則視為只查詢輸入輸出狀態
2.02 xx FF;若為$02開頭則視為查詢輸入輸出狀態,同時寫QB0
3.03 xx FF;若為$03開頭則視為查詢輸入輸出狀態,同時寫QB1
   其中FF為自由口結束字符
   DATE:2013-11
   Auther:hcwp}
unit unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,SPComm, StdCtrls, JvExControls, JvLED, ExtCtrls, iComponent,
  iVCLComponent, iCustomComponent, iPositionComponent, iScaleComponent,
  iGaugeComponent, iLogGauge;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Comm1: TComm;
    JvLED1: TJvLED;
    JvLED2: TJvLED;
    JvLED3: TJvLED;
    JvLED4: TJvLED;
    JvLED5: TJvLED;
    JvLED6: TJvLED;
    JvLED7: TJvLED;
    JvLED8: TJvLED;
    JvLED9: TJvLED;
    JvLED10: TJvLED;
    JvLED11: TJvLED;
    JvLED12: TJvLED;
    JvLED13: TJvLED;
    JvLED14: TJvLED;
    Label1: TLabel;
    Label2: TLabel;
    Timer1: TTimer;
    JvLED0: TJvLED;
    JvLED15: TJvLED;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    CheckBox6: TCheckBox;
    CheckBox7: TCheckBox;
    CheckBox8: TCheckBox;
    CheckBox9: TCheckBox;
    CheckBox10: TCheckBox;
    CheckBox11: TCheckBox;
    CheckBox12: TCheckBox;
    CheckBox13: TCheckBox;
    CheckBox14: TCheckBox;
    CheckBox15: TCheckBox;
    CheckBox16: TCheckBox;
    Label3: TLabel;
    Label4: TLabel;
    JvLED16: TJvLED;
    JvLED17: TJvLED;
    JvLED18: TJvLED;
    JvLED19: TJvLED;
    JvLED20: TJvLED;
    JvLED21: TJvLED;
    JvLED22: TJvLED;
    JvLED23: TJvLED;
    Label5: TLabel;
    Label6: TLabel;
    JvLED24: TJvLED;
    JvLED25: TJvLED;
    JvLED26: TJvLED;
    JvLED27: TJvLED;
    JvLED28: TJvLED;
    JvLED29: TJvLED;
    JvLED30: TJvLED;
    JvLED31: TJvLED;
    Label7: TLabel;
    Label8: TLabel;
    Timer2: TTimer;
    Timer3: TTimer;
    Label9: TLabel;
    Label10: TLabel;


    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Comm1ReceiveData(Sender: TObject; Buffer: PAnsiChar;
     BufferLength: Word);
    procedure Button2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure Timer3Timer(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure CheckBox3Click(Sender: TObject);
    procedure CheckBox4Click(Sender: TObject);
    procedure CheckBox5Click(Sender: TObject);
    procedure CheckBox6Click(Sender: TObject);
    procedure CheckBox7Click(Sender: TObject);
    procedure CheckBox8Click(Sender: TObject);
    procedure CheckBox9Click(Sender: TObject);
    procedure CheckBox10Click(Sender: TObject);
    procedure CheckBox11Click(Sender: TObject);
    procedure CheckBox12Click(Sender: TObject);
    procedure CheckBox13Click(Sender: TObject);
    procedure CheckBox14Click(Sender: TObject);
    procedure CheckBox15Click(Sender: TObject);
    procedure CheckBox16Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  //Comm1:TComm;
  InputArray:array[0..3]of Byte;
  IB0,IB1,QB0,QB1:array[0..7]of Boolean;
implementation

{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
  with Comm1 do
  begin
    BaudRate:= 9600;//波特率9600bps
    Parity:=None;//奇偶交驗
    ByteSize:=_8;//數據位 8
    StopBits:=_1;//停止位1
    Comm1.CommPort:=3;
    InBufferSize:=5;
    InputLen:=5;
    ParityCheck:=False;
    StopBits:=_1;
    DtrControl:=dtrEnable;
  end;


end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   Comm1.StartComm;
   Timer3.Enabled:=True;
end;

procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: PAnsiChar;
  BufferLength: Word);
var
    aa: Integer;
    ss: Integer;
    dd:string;
begin
    //aa:=12;
    for  ss:=0 to 4 do
    begin
      aa:=Byte(Buffer[ss]);
      //sleep(100);
      dd:=IntToHex(aa,2);

     //ss:=IntToHex(aa,2);
     // ss:= chr(aa);
      //dd:= IntToHex(aa,2);
     Memo1.Lines.Add(dd);
     //Sleep(10);
     InputArray[ss]:= Byte(Buffer[ss]);
    end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Timer1.Enabled:=True;
  Timer2.Enabled:=True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
//const
  // j:array[0..2]of string=('jvled1','jvled2','jvled3');
var
  iFlag:Integer;
  k,I:Integer;
  j:array[0..15]of Boolean;

begin
{ for k := 1 to 14 do
  begin
    j[k]:='JvLED'+ IntToStr(k);
  end; }

  for iFlag:=7 downto 0 do
  begin
    if InputArray[0] and (1 shl iFlag)<>0 then
      IB0[iFlag]:=True
    else
      IB0[iFlag]:=False;
  end;
  for i := 0 to 7 do
  begin
    if IB0=True then
     j[I]:=True
    else j[I]:=False;
  end;
  for iFlag:=7 downto 0 do
  begin
    if InputArray[1] and (1 shl iFlag)<>0 then
      IB1[iFlag]:=True
    else
      IB1[iFlag]:=False;
  end;
  for i := 0 to 7 do
  begin
    if IB1=True then
     j[I+8]:=True
    else j[I+8]:=False;
  end;
  for k :=0  to 15 do
  begin
    case k of
      0: JvLED0.Status:=j[0] ;
      1: JvLED1.Status:=j[1] ;
      2: JvLED2.Status:=j[2] ;
      3: JvLED3.Status:=j[3] ;
      4: JvLED4.Status:=j[4] ;
      5: JvLED5.Status:=j[5] ;
      6: JvLED6.Status:=j[6] ;
      7: JvLED7.Status:=j[7] ;
      8: JvLED8.Status:=j[8] ;
      9: JvLED9.Status:=j[9] ;
      10: JvLED10.Status:=j[10] ;
      11: JvLED11.Status:=j[11] ;
      12: JvLED12.Status:=j[12] ;
      13: JvLED13.Status:=j[13] ;
      14: JvLED14.Status:=j[14] ;
      15: JvLED15.Status:=j[15] ;
    end;
  end;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
var
  iFlag:Integer;
  k,I:Integer;
  j:array[0..15]of Boolean;

begin
{ for k := 1 to 14 do
  begin
    j[k]:='JvLED'+ IntToStr(k);
  end; }

  for iFlag:=7 downto 0 do
  begin
    if InputArray[2] and (1 shl iFlag)<>0 then
      QB0[iFlag]:=True
    else
      QB0[iFlag]:=False;
  end;
  for i := 0 to 7 do
  begin
    if QB0=True then
     j[I]:=True
    else j[I]:=False;
  end;
  for iFlag:=7 downto 0 do
  begin
    if InputArray[3] and (1 shl iFlag)<>0 then
      QB1[iFlag]:=True
    else
      QB1[iFlag]:=False;
  end;
  for i := 0 to 7 do
  begin
    if QB1=True then
     j[I+8]:=True
    else j[I+8]:=False;
  end;
  for k :=0  to 15 do
  begin
    case k of
      0: JvLED16.Status:=j[0] ;
      1: JvLED17.Status:=j[1] ;
      2: JvLED18.Status:=j[2] ;
      3: JvLED19.Status:=j[3] ;
      4: JvLED20.Status:=j[4] ;
      5: JvLED21.Status:=j[5] ;
      6: JvLED22.Status:=j[6] ;
      7: JvLED23.Status:=j[7] ;
      8: JvLED24.Status:=j[8] ;
      9: JvLED25.Status:=j[9] ;
      10: JvLED26.Status:=j[10] ;
      11: JvLED27.Status:=j[11] ;
      12: JvLED28.Status:=j[12] ;
      13: JvLED29.Status:=j[13] ;
      14: JvLED30.Status:=j[14] ;
      15: JvLED31.Status:=j[15] ;
    end;
  end;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
var
  str:string;
  temp,temp1:Byte;
begin

  Timer3.Enabled:=False;
  temp:= InputArray[2] and ($01);
  case temp of
    {判斷分兩種情況原先為此位為1,后再分選中和非選中兩種狀態的處理}
    $01:    if CheckBox1.State= cbchecked then  //選中狀態
            begin

              str:=Char($02)+char( InputArray[2])+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin
              temp1:= InputArray[2] and ($fe);   //與1111 1110進行與運算 ,使此位為0
              str:=Char($02)+char(temp1)+ Char($ff);
              Comm1.Output:=str;
            end;
      {判斷分兩種情況原先為此位為0,后再分選中和非選中兩種狀態的處理}
    $00:    if CheckBox1.State= cbchecked then  //選中狀態
            begin
              temp1:= Inputarray[2] or ($01);
              str:=Char($02)+char( temp1)+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin

              str:=Char($02)+char( InputArray[2])+ Char($ff);
              Comm1.Output:=str;
            end;
  end;


  Timer3.Enabled:=True;
end;

procedure TForm1.Timer3Timer(Sender: TObject);
var
  str:string;
begin
  str:=char($01)+ Char($00)+Chr($ff);

    Comm1.Output:=str;

end;

procedure TForm1.CheckBox2Click(Sender: TObject);
var
  str:string;
  temp,temp1:Byte;
begin

  Timer3.Enabled:=False;
  temp:= InputArray[2] and ($02);
  case temp of
    {判斷分兩種情況原先為此位為1,后再分選中和非選中兩種狀態的處理}
    $02:    if CheckBox2.State= cbchecked then  //選中狀態
            begin

              str:=Char($02)+char( InputArray[2])+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin
              temp1:= InputArray[2] and ($fd);   //與1111 1110進行與運算 ,使此位為0
              str:=Char($02)+char(temp1)+ Char($ff);
              Comm1.Output:=str;
            end;
      {判斷分兩種情況原先為此位為0,后再分選中和非選中兩種狀態的處理}
    $00:    if CheckBox2.State= cbchecked then  //選中狀態
            begin
              temp1:= Inputarray[2] or ($02);
              str:=Char($02)+char( temp1)+ Char($ff);  //
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin

              str:=Char($02)+char( InputArray[2])+ Char($ff);
              Comm1.Output:=str;
            end;
  end;


  Timer3.Enabled:=True;
end;

procedure TForm1.CheckBox3Click(Sender: TObject);
var
  str:string;
  temp,temp1:Byte;
begin

  Timer3.Enabled:=False;
  temp:= InputArray[2] and ($04);
  case temp of
    {判斷分兩種情況原先為此位為1,后再分選中和非選中兩種狀態的處理}
    $04:    if CheckBox3.State= cbchecked then  //選中狀態
            begin

              str:=Char($02)+char( InputArray[2])+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin
              temp1:= InputArray[2] and ($fb);   //與1111 1110進行與運算 ,使此位為0
              str:=Char($02)+char(temp1)+ Char($ff);
              Comm1.Output:=str;
            end;
      {判斷分兩種情況原先為此位為0,后再分選中和非選中兩種狀態的處理}
    $00:    if CheckBox3.State= cbchecked then  //選中狀態
            begin
              temp1:= Inputarray[2] or ($04);
              str:=Char($02)+char( temp1)+ Char($ff);  //
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin

              str:=Char($02)+char( InputArray[2])+ Char($ff);
              Comm1.Output:=str;
            end;
  end;
  Timer3.Enabled:=True;
end;

procedure TForm1.CheckBox4Click(Sender: TObject);
var
  str:string;
  temp,temp1:Byte;
begin

  Timer3.Enabled:=False;
  temp:= InputArray[2] and ($08);
  case temp of
    {判斷分兩種情況原先為此位為1,后再分選中和非選中兩種狀態的處理}
    $08:    if CheckBox4.State= cbchecked then  //選中狀態
            begin

              str:=Char($02)+char( InputArray[2])+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin
              temp1:= InputArray[2] and ($f7);   //與1111 1110進行與運算 ,使此位為0
              str:=Char($02)+char(temp1)+ Char($ff);
              Comm1.Output:=str;
            end;
      {判斷分兩種情況原先為此位為0,后再分選中和非選中兩種狀態的處理}
    $00:    if CheckBox4.State= cbchecked then  //選中狀態
            begin
              temp1:= Inputarray[2] or ($08);
              str:=Char($02)+char( temp1)+ Char($ff);  //
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin

              str:=Char($02)+char( InputArray[2])+ Char($ff);
              Comm1.Output:=str;
            end;
  end;
  Timer3.Enabled:=True;
end;

procedure TForm1.CheckBox5Click(Sender: TObject);  //Q0.4
var
  str:string;
  temp,temp1:Byte;
begin

  Timer3.Enabled:=False;
  temp:= InputArray[2] and ($10);
  case temp of
    {判斷分兩種情況原先為此位為1,后再分選中和非選中兩種狀態的處理}
    $10:    if CheckBox5.State= cbchecked then  //選中狀態
            begin

              str:=Char($02)+char( InputArray[2])+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin
              temp1:= InputArray[2] and ($ef);   //與1111 1110進行與運算 ,使此位為0
              str:=Char($02)+char(temp1)+ Char($ff);
              Comm1.Output:=str;
            end;
      {判斷分兩種情況原先為此位為0,后再分選中和非選中兩種狀態的處理}
    $00:    if CheckBox5.State= cbchecked then  //選中狀態
            begin
              temp1:= Inputarray[2] or ($10);
              str:=Char($02)+char( temp1)+ Char($ff);  //
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin

              str:=Char($02)+char( InputArray[2])+ Char($ff);
              Comm1.Output:=str;
            end;
  end;
  Timer3.Enabled:=True;
end;

procedure TForm1.CheckBox6Click(Sender: TObject); //Q0.5
var
  str:string;
  temp,temp1:Byte;
begin

  Timer3.Enabled:=False;
  temp:= InputArray[2] and ($20);
  case temp of
    {判斷分兩種情況原先為此位為1,后再分選中和非選中兩種狀態的處理}
    $20:    if CheckBox6.State= cbchecked then  //選中狀態
            begin

              str:=Char($02)+char( InputArray[2])+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin
              temp1:= InputArray[2] and ($df);   //與1111 1110進行與運算 ,使此位為0
              str:=Char($02)+char(temp1)+ Char($ff);
              Comm1.Output:=str;
            end;
      {判斷分兩種情況原先為此位為0,后再分選中和非選中兩種狀態的處理}
    $00:    if CheckBox6.State= cbchecked then  //選中狀態
            begin
              temp1:= Inputarray[2] or ($20);
              str:=Char($02)+char( temp1)+ Char($ff);  //
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin

              str:=Char($02)+char( InputArray[2])+ Char($ff);
              Comm1.Output:=str;
            end;
  end;
  Timer3.Enabled:=True;
end;

procedure TForm1.CheckBox7Click(Sender: TObject);
var
  str:string;
  temp,temp1:Byte;
begin

  Timer3.Enabled:=False;
  temp:= InputArray[2] and ($40);
  case temp of
    {判斷分兩種情況原先為此位為1,后再分選中和非選中兩種狀態的處理}
    $40:    if CheckBox7.State= cbchecked then  //選中狀態
            begin

              str:=Char($02)+char( InputArray[2])+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin
              temp1:= InputArray[2] and ($bf);   //與1111 1110進行與運算 ,使此位為0
              str:=Char($02)+char(temp1)+ Char($ff);
              Comm1.Output:=str;
            end;
      {判斷分兩種情況原先為此位為0,后再分選中和非選中兩種狀態的處理}
    $00:    if CheckBox7.State= cbchecked then  //選中狀態
            begin
              temp1:= Inputarray[2] or ($40);
              str:=Char($02)+char( temp1)+ Char($ff);  //
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin

              str:=Char($02)+char( InputArray[2])+ Char($ff);
              Comm1.Output:=str;
            end;
  end;
  Timer3.Enabled:=True;
end;

procedure TForm1.CheckBox8Click(Sender: TObject);
var
  str:string;
  temp,temp1:Byte;
begin

  Timer3.Enabled:=False;
  temp:= InputArray[2] and ($80);
  case temp of
    {判斷分兩種情況原先為此位為1,后再分選中和非選中兩種狀態的處理}
    $80:    if CheckBox8.State= cbchecked then  //選中狀態
            begin

              str:=Char($02)+char( InputArray[2])+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin
              temp1:= InputArray[2] and ($7f);   //與1111 1110進行與運算 ,使此位為0
              str:=Char($02)+char(temp1)+ Char($ff);
              Comm1.Output:=str;
            end;
      {判斷分兩種情況原先為此位為0,后再分選中和非選中兩種狀態的處理}
    $00:    if CheckBox8.State= cbchecked then  //選中狀態
            begin
              temp1:= Inputarray[2] or ($80);
              str:=Char($02)+char( temp1)+ Char($ff);  //
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin

              str:=Char($02)+char( InputArray[2])+ Char($ff);
              Comm1.Output:=str;
            end;
  end;
  Timer3.Enabled:=True;
end;

procedure TForm1.CheckBox9Click(Sender: TObject);
var
  str:string;
  temp,temp1:Byte;
begin

  Timer3.Enabled:=False;
  temp:= InputArray[3] and ($01);
  case temp of
    {判斷分兩種情況原先為此位為1,后再分選中和非選中兩種狀態的處理}
    $01:    if CheckBox9.State= cbchecked then  //選中狀態
            begin

              str:=Char($03)+char( InputArray[3])+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin
              temp1:= InputArray[3] and ($fe);   //與1111 1110進行與運算 ,使此位為0
              str:=Char($03)+char(temp1)+ Char($ff);
              Comm1.Output:=str;
            end;
      {判斷分兩種情況原先為此位為0,后再分選中和非選中兩種狀態的處理}
    $00:    if CheckBox9.State= cbchecked then  //選中狀態
            begin
              temp1:= Inputarray[3] or ($01);
              str:=Char($03)+char( temp1)+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin

              str:=Char($03)+char( InputArray[3])+ Char($ff);
              Comm1.Output:=str;
            end;
  end;


  Timer3.Enabled:=True;
end;

procedure TForm1.CheckBox10Click(Sender: TObject);
var
  str:string;
  temp,temp1:Byte;
begin

  Timer3.Enabled:=False;
  temp:= InputArray[3] and ($02);
  case temp of
    {判斷分兩種情況原先為此位為1,后再分選中和非選中兩種狀態的處理}
    $02:    if CheckBox10.State= cbchecked then  //選中狀態
            begin

              str:=Char($03)+char( InputArray[3])+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin
              temp1:= InputArray[3] and ($fd);   //與1111 1110進行與運算 ,使此位為0
              str:=Char($03)+char(temp1)+ Char($ff);
              Comm1.Output:=str;
            end;
      {判斷分兩種情況原先為此位為0,后再分選中和非選中兩種狀態的處理}
    $00:    if CheckBox10.State= cbchecked then  //選中狀態
            begin
              temp1:= Inputarray[3] or ($02);
              str:=Char($03)+char( temp1)+ Char($ff);  //
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin

              str:=Char($03)+char( InputArray[3])+ Char($ff);
              Comm1.Output:=str;
            end;
  end;


  Timer3.Enabled:=True;
end;

procedure TForm1.CheckBox11Click(Sender: TObject);
var
  str:string;
  temp,temp1:Byte;
begin

  Timer3.Enabled:=False;
  temp:= InputArray[3] and ($04);
  case temp of
    {判斷分兩種情況原先為此位為1,后再分選中和非選中兩種狀態的處理}
    $04:    if CheckBox11.State= cbchecked then  //選中狀態
            begin

              str:=Char($03)+char( InputArray[3])+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin
              temp1:= InputArray[3] and ($fb);   //與1111 1110進行與運算 ,使此位為0
              str:=Char($03)+char(temp1)+ Char($ff);
              Comm1.Output:=str;
            end;
      {判斷分兩種情況原先為此位為0,后再分選中和非選中兩種狀態的處理}
    $00:    if CheckBox11.State= cbchecked then  //選中狀態
            begin
              temp1:= Inputarray[3] or ($04);
              str:=Char($03)+char( temp1)+ Char($ff);  //
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin

              str:=Char($03)+char( InputArray[3])+ Char($ff);
              Comm1.Output:=str;
            end;
  end;
  Timer3.Enabled:=True;
end;


procedure TForm1.CheckBox12Click(Sender: TObject);
var
  str:string;
  temp,temp1:Byte;
begin

  Timer3.Enabled:=False;
  temp:= InputArray[3] and ($08);
  case temp of
    {判斷分兩種情況原先為此位為1,后再分選中和非選中兩種狀態的處理}
    $08:    if CheckBox12.State= cbchecked then  //選中狀態
            begin

              str:=Char($03)+char( InputArray[3])+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin
              temp1:= InputArray[3] and ($f7);   //與1111 1110進行與運算 ,使此位為0
              str:=Char($03)+char(temp1)+ Char($ff);
              Comm1.Output:=str;
            end;
      {判斷分兩種情況原先為此位為0,后再分選中和非選中兩種狀態的處理}
    $00:    if CheckBox12.State= cbchecked then  //選中狀態
            begin
              temp1:= Inputarray[3] or ($08);
              str:=Char($03)+char( temp1)+ Char($ff);  //
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin

              str:=Char($03)+char( InputArray[3])+ Char($ff);
              Comm1.Output:=str;
            end;
  end;
  Timer3.Enabled:=True;
end;

procedure TForm1.CheckBox13Click(Sender: TObject);
var
  str:string;
  temp,temp1:Byte;
begin

  Timer3.Enabled:=False;
  temp:= InputArray[3] and ($10);
  case temp of
    {判斷分兩種情況原先為此位為1,后再分選中和非選中兩種狀態的處理}
    $10:    if CheckBox13.State= cbchecked then  //選中狀態
            begin

              str:=Char($03)+char( InputArray[3])+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin
              temp1:= InputArray[3] and ($ef);   //與1111 1110進行與運算 ,使此位為0
              str:=Char($03)+char(temp1)+ Char($ff);
              Comm1.Output:=str;
            end;
      {判斷分兩種情況原先為此位為0,后再分選中和非選中兩種狀態的處理}
    $00:    if CheckBox13.State= cbchecked then  //選中狀態
            begin
              temp1:= Inputarray[3] or ($10);
              str:=Char($03)+char( temp1)+ Char($ff);  //
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin

              str:=Char($03)+char( InputArray[3])+ Char($ff);
              Comm1.Output:=str;
            end;
  end;
  Timer3.Enabled:=True;
end;

procedure TForm1.CheckBox14Click(Sender: TObject);
var
  str:string;
  temp,temp1:Byte;
begin

  Timer3.Enabled:=False;
  temp:= InputArray[3] and ($20);
  case temp of
    {判斷分兩種情況原先為此位為1,后再分選中和非選中兩種狀態的處理}
    $20:    if CheckBox14.State= cbchecked then  //選中狀態
            begin

              str:=Char($03)+char( InputArray[3])+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin
              temp1:= InputArray[3] and ($df);   //與1111 1110進行與運算 ,使此位為0
              str:=Char($03)+char(temp1)+ Char($ff);
              Comm1.Output:=str;
            end;
      {判斷分兩種情況原先為此位為0,后再分選中和非選中兩種狀態的處理}
    $00:    if CheckBox14.State= cbchecked then  //選中狀態
            begin
              temp1:= Inputarray[3] or ($20);
              str:=Char($03)+char( temp1)+ Char($ff);  //
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin

              str:=Char($03)+char( InputArray[3])+ Char($ff);
              Comm1.Output:=str;
            end;
  end;
  Timer3.Enabled:=True;
end;

procedure TForm1.CheckBox15Click(Sender: TObject);
var
  str:string;
  temp,temp1:Byte;
begin

  Timer3.Enabled:=False;
  temp:= InputArray[3] and ($40);
  case temp of
    {判斷分兩種情況原先為此位為1,后再分選中和非選中兩種狀態的處理}
    $40:    if CheckBox15.State= cbchecked then  //選中狀態
            begin

              str:=Char($03)+char( InputArray[3])+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin
              temp1:= InputArray[3] and ($bf);   //與1111 1110進行與運算 ,使此位為0
              str:=Char($03)+char(temp1)+ Char($ff);
              Comm1.Output:=str;
            end;
      {判斷分兩種情況原先為此位為0,后再分選中和非選中兩種狀態的處理}
    $00:    if CheckBox15.State= cbchecked then  //選中狀態
            begin
              temp1:= Inputarray[3] or ($40);
              str:=Char($03)+char( temp1)+ Char($ff);  //
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin

              str:=Char($03)+char( InputArray[3])+ Char($ff);
              Comm1.Output:=str;
            end;
  end;
  Timer3.Enabled:=True;
end;



procedure TForm1.CheckBox16Click(Sender: TObject);
var
  str:string;
  temp,temp1:Byte;
begin

  Timer3.Enabled:=False;
  temp:= InputArray[3] and ($80);
  case temp of
    {判斷分兩種情況原先為此位為1,后再分選中和非選中兩種狀態的處理}
    $80:    if CheckBox16.State= cbchecked then  //選中狀態
            begin

              str:=Char($03)+char( InputArray[3])+ Char($ff);  //保持原狀態
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin
              temp1:= InputArray[3] and ($7f);   //與1111 1110進行與運算 ,使此位為0
              str:=Char($03)+char(temp1)+ Char($ff);
              Comm1.Output:=str;
            end;
      {判斷分兩種情況原先為此位為0,后再分選中和非選中兩種狀態的處理}
    $00:    if CheckBox16.State= cbchecked then  //選中狀態
            begin
              temp1:= Inputarray[3] or ($80);
              str:=Char($03)+char( temp1)+ Char($ff);  //
              Comm1.Output:=str;
            end
            else                      //未選中狀態
            begin

              str:=Char($03)+char( InputArray[3])+ Char($ff);
              Comm1.Output:=str;
            end;
  end;
  Timer3.Enabled:=True;
end;

end.
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:75077 發表于 2015-4-3 21:35 | 只看該作者
程序太長了吧。。。。以后編寫這么長程序前是不是先要寫清思路
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久人人网 | 亚洲高清成人在线 | 极品一区| 亚洲天堂网站 | www.久草.com| 精品中文字幕在线 | 国产一区二区精品在线 | 在线免费中文字幕 | 国产欧美精品区一区二区三区 | 亚洲久在线 | 91看国产| 久久狠狠 | 人人艹人人 | 日本三级日产三级国产三级 | 国产精品久久久久久久久久 | 成人免费视频观看视频 | 国产精品海角社区在线观看 | 男人的天堂久久 | 黄色大片免费网站 | 国产精品自拍啪啪 | 日韩视频一区在线观看 | 欧美中文一区 | 自拍偷拍亚洲一区 | 国产在线观看一区二区 | 91在线视频免费观看 | 国产亚洲网站 | 国产日韩久久 | 国产精品久久久久久久久久久久 | 国精产品一区二区三区 | 国产精品亚洲成在人线 | 久久这里有精品 | 波多野结衣一区二区三区在线观看 | 在线观看日本网站 | 午夜欧美 | 色婷婷av777 av免费网站在线 | 亚州成人 | 国产精品美女久久久久aⅴ国产馆 | 国产日韩欧美在线一区 | 国产高清久久 | 婷婷在线视频 | 国产成人jvid在线播放 |