找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1188|回复: 0
打印 上一主题 下一主题
收起左侧

万能遥控解码器Delphi 源代码

[复制链接]
跳转到指定楼层
楼主

指令集为:
实习期附件不能传大,主要代码
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;

评分

参与人数 1黑币 +10 收起 理由
admin + 10 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表