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

📄 com_send.pas

📁 串口数据传输,用Tcomm或MSComm控件
💻 PAS
📖 第 1 页 / 共 5 页
字号:
   count : integer;
   hei : string;
   low : string;

   get_flag : boolean;
   SCommandInfo,SErrorInfo : string;
begin
  allfalse;
  for i:=1 to 8 do
  begin
    if check_channel[i].Checked  then p[i] := 1
    else p[i] := 0;
  end;
  get_flag := ZjCommFun.setsingle_board_open_close_user(cocomm.Text, strtoint(edhouse.Text),
                                             strtoint(edadress.Text), p,
                                             SCommandInfo,SErrorInfo);

   if get_flag = true then memo2.Lines.Add('OK')
   else  memo2.Lines.Add(SErrorInfo);
   alltrue;
{
  clear;
  try          // by hs
  if comm1.PortOpen = true then
    comm1.PortOpen := false;

  if coComm.text='com1' then
  begin
    comm1.CommPort:=pnCOM1;
  end;

  if coComm.text='com2' then
  begin
    comm1.CommPort:=pnCOM2;
  end;

  if coComm.text='com3' then
  begin
    comm1.CommPort:=pnCOM3;
  end;

  if coComm.text='com4' then
  begin
    comm1.CommPort:=pnCOM4;
  end;

  if coComm.text='com5' then
  begin
    comm1.CommPort:=pnCOM5;
  end;

 ComStr:=cocomm.Text;
 hNewCommFile := CreateFile( PChar(ComStr),
                             GENERIC_READ or GENERIC_WRITE,
                             0, {not shared}
                        //     nil, {no security ??}
                        //     OPEN_EXISTING,
                        //     0,{No Overlapped}
                        //     0 {template} );
 {
 if hNewCommFile = INVALID_HANDLE_VALUE then
 begin
   showmessage( '此端口不存在或正在为其他程序占用!' ) ;
   exit;
 end
 else
 begin
    PurgeComm( hNewCommFile, PURGE_TXABORT or PURGE_RXABORT or  PURGE_TXCLEAR or PURGE_RXCLEAR ) ;    //  by hs
    CloseHandle( hNewCommFile );
    hNewCommFile := 0 ;
//    comm1.portopen:=false;
 end;
    for i:=1 to 8 do
    begin
      if check_channel[i].Checked  then p[i] := 1
      else p[i] := 0;

    end;

    sendbuf[0] := strtoint(edhouse.Text);
    sendbuf[1] := strtoint(edadress.Text);
    sendbuf[2] := $29;
    sendbuf[3] := $00;
    sendbuf[4] := $00;
    sendbuf[5] := p[8]*128 + p[7]*64 + p[6]*32 + p[5]*16 + p[4]*8 + p[3]*4 + p[2]*2 + p[1];
    checksum;
    if comm1.PortOpen=false then
    comm1.PortOpen:=true;

    outputdata;
    info_type :=$29;

 except               // by hs
  ;
 end;
 }
end;

procedure TForm1.Button9Click(Sender: TObject);
var
   i:integer;
   ComStr:String;
   hNewCommFile:   THandle;
   j : integer;
   k : integer;
   count_s : string;
   count : integer;
   hei : string;
   low : string;

   get_flag : boolean;
   SCommandInfo,SErrorInfo : string;
begin
   allfalse;
   get_flag := ZjCommFun.setbuilding_open_close_time(cocomm.Text, strtoint(edhouse.Text), start_time.Time,
                                                     end_time.Time, SCommandInfo,SErrorInfo);


   if get_flag = true then memo2.Lines.Add('OK')
   else  memo2.Lines.Add(SErrorInfo);
   alltrue;
{
  clear;
  try          // by hs
  if comm1.PortOpen = true then
    comm1.PortOpen := false;

  if coComm.text='com1' then
  begin
    comm1.CommPort:=pnCOM1;
  end;

  if coComm.text='com2' then
  begin
    comm1.CommPort:=pnCOM2;
  end;

  if coComm.text='com3' then
  begin
    comm1.CommPort:=pnCOM3;
  end;

  if coComm.text='com4' then
  begin
    comm1.CommPort:=pnCOM4;
  end;

  if coComm.text='com5' then
  begin
    comm1.CommPort:=pnCOM5;
  end;

 ComStr:=cocomm.Text;
 hNewCommFile := CreateFile( PChar(ComStr),
                             GENERIC_READ or GENERIC_WRITE,
                             0, {not shared}
                   //          nil, {no security ??}
                  //           OPEN_EXISTING,
                  //           0,{No Overlapped}
                 //            0 {template} );
  {
 if hNewCommFile = INVALID_HANDLE_VALUE then
 begin
   showmessage( '此端口不存在或正在为其他程序占用!' ) ;
   exit;
 end
 else
 begin
    PurgeComm( hNewCommFile, PURGE_TXABORT or PURGE_RXABORT or  PURGE_TXCLEAR or PURGE_RXCLEAR ) ;    //  by hs
    CloseHandle( hNewCommFile );
    hNewCommFile := 0 ;
//    comm1.portopen:=false;
 end;

    sendbuf[0] := strtoint(edhouse.Text);
    sendbuf[1] := strtoint(edstart_1.Text);
    sendbuf[2] := $2A;
    sendbuf[3] := strtoint(edstart_2.Text);
    sendbuf[4] := strtoint(edclose_1.Text);
    sendbuf[5] := strtoint(edclose_2.Text);
    checksum;
    if comm1.PortOpen=false then
    comm1.PortOpen:=true;

    outputdata;
    info_type :=$2A;

 except               // by hs
  ;
 end;
 }
end;

procedure TForm1.Button10Click(Sender: TObject);
var
   i:integer;
   ComStr:String;
   hNewCommFile:   THandle;
   j : integer;
   k : integer;
   count_s : string;
   count : integer;
   hei : string;
   low : string;

   get_flag : boolean;
   SCommandInfo,SErrorInfo : string;
begin
   allfalse;
   if trim(edstrict.Text) = '' then
   begin
     showmessage('请输入功限!!');
     edstrict.SetFocus;
     alltrue;
     exit;
   end;

   if trim(edangle.Text) = '' then
   begin
     showmessage('请输入角度!!');
     edangle.SetFocus;
     alltrue;
     exit;
   end;
   get_flag := ZjCommFun.setsingle_board_power_angle(cocomm.Text, strtoint(edhouse.Text), strtofloat(edstrict.Text),
                                     strtoint(edadress.Text), strtoint(edangle.Text),
                                     SCommandInfo,SErrorInfo) ;

   if get_flag = true then memo2.Lines.Add('OK')
   else  memo2.Lines.Add(SErrorInfo);
   alltrue;
{
  clear;
  try          // by hs
  if comm1.PortOpen = true then
    comm1.PortOpen := false;

  if coComm.text='com1' then
  begin
    comm1.CommPort:=pnCOM1;
  end;

  if coComm.text='com2' then
  begin
    comm1.CommPort:=pnCOM2;
  end;

  if coComm.text='com3' then
  begin
    comm1.CommPort:=pnCOM3;
  end;

  if coComm.text='com4' then
  begin
    comm1.CommPort:=pnCOM4;
  end;

  if coComm.text='com5' then
  begin
    comm1.CommPort:=pnCOM5;
  end;

 ComStr:=cocomm.Text;
 hNewCommFile := CreateFile( PChar(ComStr),
                             GENERIC_READ or GENERIC_WRITE,
                             0, {not shared}
                       //      nil, {no security ??}
                       //      OPEN_EXISTING,
                       //      0,{No Overlapped}
                      //       0 {template} );
 {
 if hNewCommFile = INVALID_HANDLE_VALUE then
 begin
   showmessage( '此端口不存在或正在为其他程序占用!' ) ;
   exit;
 end
 else
 begin
    PurgeComm( hNewCommFile, PURGE_TXABORT or PURGE_RXABORT or  PURGE_TXCLEAR or PURGE_RXCLEAR ) ;    //  by hs
    CloseHandle( hNewCommFile );
    hNewCommFile := 0 ;
//    comm1.portopen:=false;
 end;

    sendbuf[0] := strtoint(edhouse.Text);
    sendbuf[1] := strtoint(edadress.Text);
    sendbuf[2] := $2B;
    sendbuf[3] := $00;
    sendbuf[4] := strtoint(edstrict.Text);
    sendbuf[5] := strtoint(edangle.Text);
    checksum;
    if comm1.PortOpen=false then
    comm1.PortOpen:=true;

    outputdata;
    info_type :=$2B;

 except               // by hs
  ;
 end;
 }
end;

procedure TForm1.Button11Click(Sender: TObject);
var
   i:integer;
   ComStr:String;
   hNewCommFile:   THandle;
   j : integer;
   k : integer;
   count_s : string;
   count : integer;
   hei : string;
   low : string;

   get_flag : boolean;
   SCommandInfo,SErrorInfo : string;
begin
    allfalse;
    if trim(edchannel_6.Text) = '' then
    begin
      showmessage('请输入设定值');
      edchannel_6.SetFocus;
      alltrue;
      exit;
    end;

   get_flag := ZjCommFun.return_room(cocomm.Text, strtoint(edhouse.Text), strtoint(edadress.Text),
                              strtoint(edchannel_6.Text),
                              SCommandInfo,SErrorInfo );

   if get_flag = true then memo2.Lines.Add('OK')
   else  memo2.Lines.Add(SErrorInfo);
   alltrue;
{
  clear;
  try          // by hs
  if comm1.PortOpen = true then
    comm1.PortOpen := false;

  if coComm.text='com1' then
  begin
    comm1.CommPort:=pnCOM1;
  end;

  if coComm.text='com2' then
  begin
    comm1.CommPort:=pnCOM2;
  end;

  if coComm.text='com3' then
  begin
    comm1.CommPort:=pnCOM3;
  end;

  if coComm.text='com4' then
  begin
    comm1.CommPort:=pnCOM4;
  end;

  if coComm.text='com5' then
  begin
    comm1.CommPort:=pnCOM5;
  end;

 ComStr:=cocomm.Text;
 hNewCommFile := CreateFile( PChar(ComStr),
                             GENERIC_READ or GENERIC_WRITE,
                             0, {not shared}
                         //    nil, {no security ??}
                         //    OPEN_EXISTING,
                         //    0,{No Overlapped}
                         //    0 {template} );
 {
 if hNewCommFile = INVALID_HANDLE_VALUE then
 begin
   showmessage( '此端口不存在或正在为其他程序占用!' ) ;
   exit;
 end
 else
 begin
    PurgeComm( hNewCommFile, PURGE_TXABORT or PURGE_RXABORT or  PURGE_TXCLEAR or PURGE_RXCLEAR ) ;    //  by hs
    CloseHandle( hNewCommFile );
    hNewCommFile := 0 ;
//    comm1.portopen:=false;
 end;

    sendbuf[0] := strtoint(edhouse.Text);
    sendbuf[1] := strtoint(edadress.Text);
    sendbuf[2] := $2C;
    sendbuf[3] := strtoint(edchannel_6.Text);
    sendbuf[4] := $00;
    sendbuf[5] := $00;
    checksum;
    if comm1.PortOpen=false then
    comm1.PortOpen:=true;

    outputdata;
    info_type :=$2C;


 except               // by hs
  ;
 end;
 }
end;



procedure TForm1.Button12Click(Sender: TObject);
var
   i:integer;
   ComStr:String;
   hNewCommFile:   THandle;
   j : integer;
   k : integer;
   count_s : string;
   count : integer;
   hei : string;
   low : string;

   get_flag : boolean;
   SCommandInfo,SErrorInfo : string;
begin
    allfalse;
    if trim(edroom.Text) = '-' then
    begin
      showmessage('请输入房号!!');
      edroom.SetFocus;
      alltrue;
      exit;
    end;

    get_flag := ZjCommFun.setroom_0(cocomm.Text, strtoint(edhouse.Text), strtoint(edadress.Text),
                       strtoint(edstyle.Text), strtoint(edchannel_7.Text), edroom.Text,
                        SCommandInfo,SErrorInfo) ;

    if get_flag = true then memo2.Lines.Add('OK')
    else  memo2.Lines.Add(SErrorInfo);
    alltrue;
{
  clear;
  try          // by hs
  if comm1.PortOpen = true then
    comm1.PortOpen := false;

  if coComm.text='com1' then
  begin
    comm1.CommPort:=pnCOM1;
  end;

  if coComm.text='com2' then
  begin
    comm1.CommPort:=pnCOM2;
  end;

  if coComm.text='com3' then
  begin
    comm

⌨️ 快捷键说明

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