找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

帖子
查看: 1883|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

萬能遙控解碼器Delphi 源代碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:1038393 發(fā)表于 2022-7-5 11:43 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式

指令集為:
實習(xí)期附件不能傳大,主要代碼
unit Unit1;

interface

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


  const
    sStatyArry :array [0..3] of string=('01 06 00 00 00 01 48 0A',
    '01 06 00 00 00 02 08 0B',
    '01 06 00 00 00 03 C9 CB',
    '01 06 00 00 00 04 88 09') ;

    sButtonArry :array [0..3] of string=('01 06 00 01 00 01 19 CA',
    '01 06 00 01 00 02 59 CB',
    '01 06 00 01 00 03 98 0B',
    '01 06 00 01 00 04 D9 C9') ;
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
  BufferLength: Word);
var
  iTmp, I, StrLenght : Integer;
  ViewString,ViewChar, sTmp, sTmp1 : string;
  rbuf : array[1..1000] of byte;
  rbufChar : array[1..1000] of Char;
  MS : TMemoryStream;
begin
// BufferLength := Sizeof(rbuf);
  ViewString := '';
  Move(Buffer^, PChar(@rbuf)^, BufferLength);
  for I := 1 to BufferLength do begin
    ViewString := ViewString + IntToHex(rbuf[I-1],2)+'';
  end;
  ViewString:=Trim(ViewString);
  if ViewString ='000101' then
  begin
     Memo1.Lines.Add('connect sucuss');
  end
  else
  begin
      Memo1.Lines.Add('receive data:'+#13#10+'----------------------'+#13#10+ViewString+#13#10+'----------------------'+#13#10+FormatDateTime('YYYY-MM-DD hh:mm:ss',Now));
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  SendHex(sStatyArry[0]);
end;

procedure TForm1.SendHex(S: String);
var
  s2:string;
  buf1:array[0..50000] of char;
  i:integer;
begin
  if not bOpen then
  begin
    Memo1.Lines.Add('send data failed!,pls connect;');
    Exit;
  end;
  s2:='';
  for i:=1 to  length(s) do
  begin
    if ((copy(s,i,1)>='0') and (copy(s,i,1)<='9'))or((copy(s,i,1)>='a') and (copy(s,i,1)<='f'))
        or((copy(s,i,1)>='A') and (copy(s,i,1)<='F')) then
    begin
        s2:=s2+copy(s,i,1);
    end;
  end;
  for i:=0 to (length(s2) div 2-1) do
    buf1[ i]:=char(strtoint('$'+copy(s2,i*2+1,2)));
  Comm1.WriteCommData(buf1,(length(s2) div 2));
  Memo1.Lines.Add('send data:'+#13#10+'----------------------'+#13#10+s+#13#10+'----------------------'+#13#10+FormatDateTime('YYYY-MM-DD hh:mm:ss',Now));
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Comm1.StopComm;
  Button1.Enabled:=True;
  Button3.Enabled:=False;
  bOpen:=False;
end;

評分

參與人數(shù) 1黑幣 +10 收起 理由
admin + 10 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

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

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表