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

📄 hardwareinterfacesrc.~pas

📁 报警地图电子显示源代码
💻 ~PAS
字号:
unit HardwareInterfaceSrc;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, SPComm, MPlayer, DB, ADODB;

const len = 16;    //增加报警点需修改

type
  TFormHardwareInterface = class(TForm)
    ComboBoxCOM: TComboBox;
    Button1: TButton;
    Button2: TButton;
    ListenComm: TComm;
    MediaPlayer1: TMediaPlayer;
    EditLevel1: TEdit;
    EditLevel2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    CbBaudRate: TComboBox;
    Button3: TButton;
    Label3: TLabel;
    DataSource1: TDataSource;
    ADOConnection1: TADOConnection;
    ADOQuery1: TADOQuery;
    ADOQuery2: TADOQuery;
    DataSource2: TDataSource;
    procedure ButtonOKClick(Sender: TObject);
    procedure ButtonCancelClick(Sender: TObject);
    procedure OnReceiveData(Sender: TObject; Buffer: Pointer;
      BufferLength: Word);
    procedure Button3Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    SPath:string;
    function  IsCommSetUp:boolean;
  public
    endposition:Integer;
    biaozhi : Integer;
  end;

var
  FormHardwareInterface: TFormHardwareInterface;
  rBuf:array[1..len] of byte;
  RrBuf : array of byte;
  IsRight:boolean;
  Alert:array[1..len] of byte;
implementation

{$R *.dfm}
uses
   BJDataSrc, BJInfoSrc, MainSrc,ModifyBJDataSrc,JieDianWeiHuScr;

procedure TFormHardwareInterface.ButtonOKClick(Sender: TObject);
begin
       //先停止串口
       ListenComm.StopComm;
       //修改串口
       ListenComm.CommName := ComboBoxCOM.Text;
       ListenComm.BaudRate := strtoint(CbBaudRate.text);
       //再开启串口
       ListenComm.StartComm;
       Close;
end;

procedure TFormHardwareInterface.ButtonCancelClick(Sender: TObject);
begin
        ListenComm.StopComm;
        Close;
end;

procedure TFormHardwareInterface.OnReceiveData(Sender: TObject;
  Buffer: Pointer; BufferLength: Word);
//////////////////////////
var i,ii:integer;
    strDate,strTime:string;
    strSQL,str,str1:string;
    ARec: PNoteList;
begin
   setLength(RrBuf, BufferLength);
   move(Buffer^, pchar(@RrBuf[1])^, BufferLength);
   if RrBuf[1] = 250 then   //若是0xFA的握手信号, 则确认该信号
   begin
      IsRight:=true;
      if not ListenComm.writecommdata(@RrBuf[1], 1) then
      begin
        MessageBox(Application.Handle, '发送握手确认信号错误', '错误', MB_OK);
      end;
   end
   //如果不是0XFA,则说明开始发送数据部分
   else
   begin
      if IsRight=true then
      begin
        IsRight:=false;
       //获取日期和时间
       strDate:=DateToStr(date);
       strTime:=TimeToStr(Time);
       //组装数据。。。
       i:= RrBuf[1];
       strSQL:='select * from bjqwhb where 对应硬件节点='''+inttostr(i)+'''';
       ADOQuery2.Close;
       ADOQuery2.SQL.Clear;
       ADOQuery2.SQL.Text := strSQL;
       ADOQuery2.ExecSQL;
       ADOQuery2.open;
       if ADOQuery2.RecordCount>0 then
       begin
         //下面写入报警记录表
         str := adoquery2.FieldByName('所在地址').AsString;
         str1 := adoquery2.FieldByName('报警器编号').AsString;
        ii := adoquery2.FieldByName('对应硬件节点').AsInteger;

         strSQL := 'Insert into BJJLB(报警器编号, 报警器日期, 报警器时间, 所在地址, 对应硬件节点) values (';
         strSQL:=strSQL+str1+',''' + strDate + ''',''' + strTime + ''',''' + str + ''','''+IntToStr(ii)+''')';
         //??????
         FormBJInfo.ADOQuery1.Close;
         FormBJInfo.ADOQuery1.SQL.Clear;
         FormBJInfo.ADOQuery1.SQL.Text := strSQL;
         FormBJInfo.ADOQuery1.ExecSQL;
         //更新显示
         strSQL := 'select * from BJJLB';
         FormBJInfo.ADOQuery1.SQL.Text := strSQL;
         FormBJInfo.ADOQuery1.Open;

         //下面使能信号灯控制时钟
         for i:=0 to MyList.Count-1 do
         begin
          ARec := MyList.Items[i];
          if ii=strtoint(ARec^.dyyjjd) then
          begin
            ARec^.State:=1;
            break;
          end;
         end;

         //下面是报警音乐
         FormMain.Timer3.Enabled:=false;
         biaozhi:=0;
         MediaPlayer1.Close;
         MediaPlayer1.FileName := SPath+'\picture\music.mp3';
         MediaPlayer1.Open();
         MediaPlayer1.Next;
         endposition:=MediaPlayer1.Position;
         MediaPlayer1.Rewind;
         MediaPlayer1.Play;
         biaozhi:=1;
         FormMain.Timer3.Enabled:=true;
       end;
      end;
      
   end;
end;

procedure TFormHardwareInterface.Button3Click(Sender: TObject);
var strtemp:string;
begin
  if IsCommSetUp then
  begin
      adoquery1.Close;
      adoquery1.SQL.Clear;
      strtemp:='update TbCommParam set Commpos='''+inttostr(ComboBoxCOM.ItemIndex)+''',Baudpos='''+inttostr(CbBaudRate.ItemIndex)+'''';
      adoquery1.SQL.Add(strtemp);
      adoquery1.ExecSQL;
  end
  else
  begin
      adoquery1.Close;
      adoquery1.SQL.Clear;
      strtemp:= 'insert into TbCommParam (Commpos,Baudpos) values(';
      strtemp:=strtemp +inttostr(ComboBoxCOM.ItemIndex)+','+inttostr(CbBaudRate.ItemIndex)+')';
      adoquery1.SQL.Add(strtemp);
      adoquery1.ExecSQL;
  end;
  ShowMessage('已修改默认值')
end;

function TFormHardwareInterface.IsCommSetUp:boolean;
var strtemp:string;
begin
    ADOQuery1.Close;
    ADOQuery1.SQL.Clear;
    strtemp:='select * from TbCommParam';
    ADOQuery1.SQL.Add(strtemp);
    ADOQuery1.Open;
    if ADOQuery1.RecordCount>0 then
      Result:=true
    else
      Result:=false;
end;

procedure TFormHardwareInterface.FormActivate(Sender: TObject);
var strtemp:string;
begin
  adoquery1.Close;
  adoquery1.SQL.Clear;
  strtemp:= 'select * FROM TbCommParam';
  adoquery1.SQL.Add(strtemp);
  adoquery1.ExecSQL;
  ADOQuery1.open;
  while not adoquery1.Eof do
  begin
    ComboBoxCOM.ItemIndex := adoquery1.FieldByName('Commpos').AsInteger;
    CbBaudRate.ItemIndex:= adoquery1.FieldByName('Baudpos').AsInteger;
    ADOQuery1.Next;
  end;
  adoquery1.Close;
end;

procedure TFormHardwareInterface.FormCreate(Sender: TObject);
var i:Integer;
    strtemp:string;
begin
  IsRight:=false;

  adoquery1.Close;
  adoquery1.SQL.Clear;
  strtemp:= 'select * FROM TbCommParam';
  adoquery1.SQL.Add(strtemp);
  adoquery1.ExecSQL;
  ADOQuery1.open;
  while not adoquery1.Eof do
  begin
    ComboBoxCOM.ItemIndex := adoquery1.FieldByName('Commpos').AsInteger;
    CbBaudRate.ItemIndex:= adoquery1.FieldByName('Baudpos').AsInteger;
    ADOQuery1.Next;
  end;
  adoquery1.Close;
  ListenComm.CommName := ComboBoxCOM.Text;
  ListenComm.BaudRate := strtoint(CbBaudRate.text);
  ListenComm.StartComm;
  for i:=1 to len do Alert[i]:=0;
  biaozhi:=0;
  SPath:=extractFilePath(ParamStr(0));
end;

end.

⌨️ 快捷键说明

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