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

📄 unit1.pas

📁 在Delphi 環境下編寫的串口調試程序 ,能與下位機(MSP430F147)實現串口485通訊.完成對下位機狀態的檢測.校準. 對於使用Delphi的串口編程有一定的作用.
💻 PAS
📖 第 1 页 / 共 3 页
字号:
               end;
        6   :  begin
                    TxstrP150:='EB 04 07 01 01 0E 00 EE 0A 00 00 13 01 90 ';
                    TxstrN150:='EB 04 07 01 01 0E 00 EE 0B 00 00 14 01 90';
                strP150:='发送:EB 04 07 01 01 0E 00 EE 0A 00 00 13 01 90  ';
                strN150:='发送:EB 04 07 01 01 0E 00 EE 0B 00 00 14 01 90 ';
               end;
        7   :  begin
                    TxstrP150:='EB 04 08 01 01 0E 00 EE 0A 00 00 14 01 90 ';
                    TxstrN150:='EB 04 08 01 01 0E 00 EE 0B 00 00 15 01 90';
                strP150:='发送:EB 04 08 01 01 0E 00 EE 0A 00 00 14 01 90  ';
                strN150:='发送:EB 04 08 01 01 0E 00 EE 0B 00 00 15 01 90 ';
               end;
        8   :   begin
                    TxstrP150:='EB 04 09 01 01 0E 00 EE 0A 00 00 15 01 90 ';
                    TxstrN150:='EB 04 09 01 01 0E 00 EE 0B 00 00 16 01 90';
                strP150:='发送:EB 04 09 01 01 0E 00 EE 0A 00 00 15 01 90  ';
                strN150:='发送:EB 04 09 01 01 0E 00 EE 0B 00 00 16 01 90 ';
               end;
        9   :   begin
                    TxstrP150:='EB 04 0A 01 01 0E 00 EE 0A 00 00 16 01 90 ';
                    TxstrN150:='EB 04 0A 01 01 0E 00 EE 0B 00 00 17 01 90';
                strP150:='发送:EB 04 0A 01 01 0E 00 EE 0A 00 00 16 01 90  ';
                strN150:='发送:EB 04 0A 01 01 0E 00 EE 0B 00 00 17 01 90 ';
               end;
        10  :   begin
                    TxstrP150:='EB 04 0B 01 01 0E 00 EE 0A 00 00 17 01 90 ';
                    TxstrN150:='EB 04 0B 01 01 0E 00 EE 0B 00 00 18 01 90';
                strP150:='发送:EB 04 0B 01 01 0E 00 EE 0A 00 00 17 01 90  ';
                strN150:='发送:EB 04 0B 01 01 0E 00 EE 0B 00 00 18 01 90 ';
               end;
        else   begin
                    TxstrP150:='EB 04 01 01 01 0E 00 EE 0A 00 00 0D 01 90 ';
                    TxstrN150:='EB 04 01 01 01 0E 00 EE 0B 00 00 0E 01 90';
                strP150:='发送:EB 04 01 01 01 0E 00 EE 0A 00 00 0D 01 90  ';
                strN150:='发送:EB 04 01 01 01 0E 00 EE 0B 00 00 0E 01 90 ';
               end; ;
      End;
//TxstrP150:='EB 04 01 01 01 0E 00 EE 0A 00 00 0D 01 90 ';
//TxstrN150:='EB 04 01 01 01 0E 00 EE 0B 00 00 0E 01 90';
//strP150:='发送:EB 04 01 01 01 0E 00 EE 0A 00 00 0D 01 90  ';
//strN150:='发送:EB 04 01 01 01 0E 00 EE 0B 00 00 0E 01 90 ';
    if  ComHaveSet<>55 then
           begin
           Application.MessageBox('老大'+#13+
                             ' 麻烦你设置一下串口好不好?','警告',MB_ICONWARNING or MB_OK);
            //  ComboBox2.SetFocus;
           Form2.showmodal;
           end
    else
           begin
           if RadioButton5.Checked then
               begin
               liaoxu:=  HexStrToStr(TxstrP150);
               //   Form2.Comm1.WriteCommData(Pchar(HexStrToStr(TxstrP25)),Length(TxstrP25));
               Form2.Comm1.WriteCommData(Pchar(liaoxu),Length(liaoxu));
               Button3.Caption:='+15V';
               Memo1.Text := Memo1.Text + StrP150;
               Memo1.SelStart := Length(Memo1.Text);
               Memo1.SelLength:= 0;
               Memo1.Perform(EM_SCROLLCARET,0,0);
              //\r\njlklkkjkjl
               memo1.Lines.Append('');
               memo1.Lines.Append('');
             //if Comm1.WriteCommData(Pchar(str),Length(str)) then
               //begin
             //   FTXNum:=FTXNum+Length(str);
             //   ShowTX;
              // end;

               end;
           if RadioButton6.Checked then
               begin
               Button3.Caption:='-15V';
               liaoxu:=  HexStrToStr(TxstrN150);
               Form2.Comm1.WriteCommData(Pchar(liaoxu),Length(liaoxu));
               Memo1.Text := Memo1.Text + StrN150;
               Memo1.SelStart := Length(Memo1.Text);
               Memo1.SelLength:= 0;
               Memo1.Perform(EM_SCROLLCARET,0,0);
               //\r\njlklkkjkjl
               memo1.Lines.Append('');
               memo1.Lines.Append('');
              end;
            end;
end;

procedure TForm1.Button4Click(Sender: TObject);
var strT05 :string;
var strT10 :string;
var TxstrT05:  string;
var TxstrT10:  string;
//var liao: string;
var liaoxu: string;
//var liaoxuming :string;
begin
//var BaudRate :integer;
//liao:='EB 04 01 01 01 0B 00 EC FE 00 90';


Case   ComboBox1.ItemIndex   Of
        0   :  begin
                 TxstrT05:='EB 04 01 01 01 0E 00 EE 0C 00 00 0F 01 90';
                 TxstrT10:='EB 04 01 01 01 0E 00 EE 0D 00 00 10 01 90';
             strT05:='发送:EB 04 01 01 01 0E 00 EE 0C 00 00 0F 01 90 ';
             strT10:='发送:EB 04 01 01 01 0E 00 EE 0D 00 00 10 01 90 ';
               end;
        1   :  begin
                 TxstrT05:='EB 04 02 01 01 0E 00 EE 0C 00 00 10 01 90';
                 TxstrT10:='EB 04 02 01 01 0E 00 EE 0D 00 00 11 01 90';
             strT05:='发送:EB 04 02 01 01 0E 00 EE 0C 00 00 10 01 90 ';
             strT10:='发送:EB 04 02 01 01 0E 00 EE 0D 00 00 11 01 90 ';
               end;
        2   :  begin
                 TxstrT05:='EB 04 03 01 01 0E 00 EE 0C 00 00 11 01 90';
                 TxstrT10:='EB 04 03 01 01 0E 00 EE 0D 00 00 12 01 90';
             strT05:='发送:EB 04 03 01 01 0E 00 EE 0C 00 00 11 01 90 ';
             strT10:='发送:EB 04 03 01 01 0E 00 EE 0D 00 00 12 01 90 ';
               end;
        3   :  begin
                 TxstrT05:='EB 04 04 01 01 0E 00 EE 0C 00 00 12 01 90';
                 TxstrT10:='EB 04 04 01 01 0E 00 EE 0D 00 00 13 01 90';
             strT05:='发送:EB 04 04 01 01 0E 00 EE 0C 00 00 12 01 90 ';
             strT10:='发送:EB 04 04 01 01 0E 00 EE 0D 00 00 13 01 90 ';
               end;
        4   :  begin
                 TxstrT05:='EB 04 05 01 01 0E 00 EE 0C 00 00 13 01 90';
                 TxstrT10:='EB 04 05 01 01 0E 00 EE 0D 00 00 14 01 90';
             strT05:='发送:EB 04 05 01 01 0E 00 EE 0C 00 00 13 01 90 ';
             strT10:='发送:EB 04 05 01 01 0E 00 EE 0D 00 00 14 01 90 ';
               end;
        5   :  begin
                 TxstrT05:='EB 04 06 01 01 0E 00 EE 0C 00 00 14 01 90';
                 TxstrT10:='EB 04 06 01 01 0E 00 EE 0D 00 00 15 01 90';
             strT05:='发送:EB 04 06 01 01 0E 00 EE 0C 00 00 14 01 90 ';
             strT10:='发送:EB 04 06 01 01 0E 00 EE 0D 00 00 15 01 90 ';
               end;
        6   :  begin
                 TxstrT05:='EB 04 07 01 01 0E 00 EE 0C 00 00 15 01 90';
                 TxstrT10:='EB 04 07 01 01 0E 00 EE 0D 00 00 16 01 90';
             strT05:='发送:EB 04 07 01 01 0E 00 EE 0C 00 00 15 01 90 ';
             strT10:='发送:EB 04 07 01 01 0E 00 EE 0D 00 00 16 01 90 ';
               end;
        7   :  begin
                 TxstrT05:='EB 04 08 01 01 0E 00 EE 0C 00 00 16 01 90';
                 TxstrT10:='EB 04 08 01 01 0E 00 EE 0D 00 00 17 01 90';
             strT05:='发送:EB 04 08 01 01 0E 00 EE 0C 00 00 16 01 90 ';
             strT10:='发送:EB 04 08 01 01 0E 00 EE 0D 00 00 17 01 90 ';
               end;
        8   :  begin
                 TxstrT05:='EB 04 09 01 01 0E 00 EE 0C 00 00 17 01 90';
                 TxstrT10:='EB 04 09 01 01 0E 00 EE 0D 00 00 18 01 90';
             strT05:='发送:EB 04 09 01 01 0E 00 EE 0C 00 00 17 01 90 ';
             strT10:='发送:EB 04 09 01 01 0E 00 EE 0D 00 00 18 01 90 ';
               end;
        9   :  begin
                 TxstrT05:='EB 04 0A 01 01 0E 00 EE 0C 00 00 18 01 90';
                 TxstrT10:='EB 04 0A 01 01 0E 00 EE 0D 00 00 19 01 90';
             strT05:='发送:EB 04 0A 01 01 0E 00 EE 0C 00 00 18 01 90 ';
             strT10:='发送:EB 04 0A 01 01 0E 00 EE 0D 00 00 19 01 90 ';
               end;
        10  :  begin
                 TxstrT05:='EB 04 0B 01 01 0E 00 EE 0C 00 00 19 01 90';
                 TxstrT10:='EB 04 0B 01 01 0E 00 EE 0D 00 00 1A 01 90';
             strT05:='发送:EB 04 0B 01 01 0E 00 EE 0C 00 00 19 01 90 ';
             strT10:='发送:EB 04 0B 01 01 0E 00 EE 0D 00 00 1A 01 90 ';
               end;
        else   begin
                 TxstrT05:='EB 04 01 01 01 0E 00 EE 0C 00 00 0F 01 90';
                 TxstrT10:='EB 04 01 01 01 0E 00 EE 0D 00 00 10 01 90';
             strT05:='发送:EB 04 01 01 01 0E 00 EE 0C 00 00 0F 01 90 ';
             strT10:='发送:EB 04 01 01 01 0E 00 EE 0D 00 00 10 01 90 ';
               end; ;
      End;
//TxstrT05:='EB 04 01 01 01 0E 00 EE 0C 00 00 0F 01 90';
//TxstrT10:='EB 04 01 01 01 0E 00 EE 0D 00 00 10 01 90';
//strT05:='发送:EB 04 01 01 01 0E 00 EE 0C 00 00 0F 01 90 ';
//strT10:='发送:EB 04 01 01 01 0E 00 EE 0D 00 00 10 01 90 ';
    if  ComHaveSet<>55 then
           begin
           Application.MessageBox('老大'+#13+
                             ' 麻烦你设置一下串口好不好?','警告',MB_ICONWARNING or MB_OK);
            //  ComboBox2.SetFocus;
           Form2.showmodal;
           end
    else
           begin
           if RadioButton7.Checked then
               begin
               liaoxu:=  HexStrToStr(TxstrT05);
               //   Form2.Comm1.WriteCommData(Pchar(HexStrToStr(TxstrP25)),Length(TxstrP25));
               Form2.Comm1.WriteCommData(Pchar(liaoxu),Length(liaoxu));
               Button4.Caption:='+7.5V';
               Memo1.Text := Memo1.Text + StrT05;
               Memo1.SelStart := Length(Memo1.Text);
               Memo1.SelLength:= 0;
               Memo1.Perform(EM_SCROLLCARET,0,0);
              //\r\njlklkkjkjl
               memo1.Lines.Append('');
               memo1.Lines.Append('');
             //if Comm1.WriteCommData(Pchar(str),Length(str)) then
               //begin
             //   FTXNum:=FTXNum+Length(str);
             //   ShowTX;
              // end;

               end;
           if RadioButton8.Checked then
               begin
               Button4.Caption:='-7.5V';
               liaoxu:=  HexStrToStr(TxstrT10);
               Form2.Comm1.WriteCommData(Pchar(liaoxu),Length(liaoxu));
               Memo1.Text := Memo1.Text + StrT10;
               Memo1.SelStart := Length(Memo1.Text);
               Memo1.SelLength:= 0;
               Memo1.Perform(EM_SCROLLCARET,0,0);
               //\r\njlklkkjkjl
               memo1.Lines.Append('');
               memo1.Lines.Append('');
              end;
            end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
ADate:TDateTime;
ss:string;
Days:array[1..7] of string;
begin
  days[1]:='星期日';
  days[2]:='星期一';
  days[3]:='星期二';
  days[4]:='星期三';
  days[5]:='星期四';
  days[6]:='星期五';
  days[7]:='星期六';
  ADate:=strtodate(FormatDateTime('yyyy-mm-dd',date));
 ss:=FormatDateTime('yyyy"年"m"月"d"日"hh:nn:ss',now);
 StatusBar1.Panels[2].Text:='当前时间:'+ss+#0+days[DayOfWeek(ADate)];
 StatusBar1.Panels[3].Text:=days[DayOfWeek(ADate)];
 StatusBar1.Panels[0].Text:='串口状态';
    if ComHaveSet<>55 then
      begin
          StatusBar1.Panels[1].Text:='==>>末打开';
      end
    else
      begin
          StatusBar1.Panels[1].Text:=Form2.ComboBox1.Text+'  '+Form2.ComboBox4.Text+'  '+Form2.ComboBox3.Text+'  '+'1'+'   '+Form2.ComboBox6.Text;
      end;



     // Comm1.CommName:=ComboBox1.Text;                    //1

     // ComboBox2.ItemIndex := 0;                          //2

      //Comm1.ByteSize :=  TByteSize(ComboBox3.ItemIndex); //3
     //
     // Comm1.BaudRate := StrToInt(ComboBox4.Text);        //4

     // Comm1.StopBits := TStopBits(ComboBox5.ItemIndex);  //5

     // ComboBox6.ItemIndex := 0;                          //6
     // Comm1.Parity := None;

    //  if TryStrToInt(ComboBox4.Text,BaudRate) then
     //      Comm1.BaudRate := BaudRate;
// StatusBar1.Panels[0].Text:=days[DayOfWeek(ADate)];


end;


procedure TForm1.N3Click(Sender: TObject);
begin
 Form5.showmodal;
end;

end.

⌨️ 快捷键说明

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