Who is a great god can put this code into a c # code or c + + code, code or VB.net,
The unit Unit_LhmTest;
Interface
USES the
Winapi. Windows, Winapi Messages, System. SysUtils, System. Variants, System. Classes, Vcl. Graphics,
The Vcl. Controls, Vcl. Forms, Vcl. Dialogs, Vcl. StdCtrls, Vcl. Buttons, Unit_LonHandMiniLib,
The Vcl. Mask, Vcl.Com Ctrls IdGlobal, Vcl. ExtCtrls;
Type
TForm1=class (TForm)
Grp_udp: TGroupBox;
Btn3: TBitBtn;
Lv_dev: TListView;
Grp_log: TGroupBox;
Redt1: TRichEdit;
Btn7: TBitBtn;
Grp_tcp: TGroupBox;
Btn6: TBitBtn;
Btn4: TBitBtn;
Grp_connect: TGroupBox;
Btn5: TBitBtn;
Lbledt_mac: TLabeledEdit;
Lbledt_ip: TLabeledEdit;
Lbledt_port: TLabeledEdit;
Lbledt_psd: TLabeledEdit;
Lbledt_mac_connected: TLabeledEdit;
Lbledt_Data: TLabeledEdit;
Procedure btn3Click (Sender: TObject);
Procedure btn4Click (Sender: TObject);
Procedure btn5Click (Sender: TObject);
Procedure btn6Click (Sender: TObject);
Procedure redt1Change (Sender: TObject);
Procedure btn7Click (Sender: TObject);
Procedure FormCreate (Sender: TObject);
Procedure lv_devClick (Sender: TObject);
Private
LHM: ILhm;
Procedure FRcvSearchResult (aData: TIdBytes);
Procedure FRcvDevData (aData: TIdBytes; AMac: PChar);
{Private declarations}
Public
{Public declarations}
end;
Var
Form1: TForm1;
Implementation
{$R *. DFM}
Procedure TForm1. FormCreate (Sender: TObject);
The begin
LHM:=LhmCreate;
LHM. SetRcvSearchResultProc (FRcvSearchResult);
LHM. SetRcvDevDataProc (FRcvDevData);
end;
Procedure Log (aStr: string);
The begin
Form1. Redt1. Lines. The Add (aStr);
end;
{* TBUF4 to IP *}
The function Buf42IP (ABuf: PBUF4) : string;
Var
I: Integer;
The begin
Result:=';
For I:=0 to SizeOf (TBUF4) - 1 do
Then if I=SizeOf (TBUF4) - 1
Result: the Result=+ IntToStr (ABuf [I])
The else
Result: the Result=+ IntToStr (ABuf [I]) + '. '.
end;
The function Buf62Mac (Value: TBUF6) : string;
Var
I: Integer;
The begin
Result:=';
For I:=0 to Length (Value) - 1 do
Result: the Result=+ IntToHex (Value [I], 2)
end;
The function Buf2HexStr (aBuf: TIdBytes) : string;
Var
I: Integer;
The begin
Result:=';
For I:=0 to Length (aBuf) - 1 do
Result: the Result=+ IntToHex (aBuf [I], 2) + ";
end;
The function HexStr2Buf (aStr: string) : TIdBytes;
Var
I: Integer;
Len: Integer;
The begin
Result:=nil;
AStr:=StringReplace (aStr, ' ', ' ', [rfReplaceAll]);
AStr:=StringReplace (aStr, x '0', ' ', [rfReplaceAll]);
AStr:=StringReplace (aStr, '$',' ', [rfReplaceAll]);
Len:=Length (aStr);
SetLength (Result, len div 2);
For I:=0 to do len - 1
If Odd (I) then
Result: [I div 2]=StrToIntDef (' $' + aStr aStr [I] + [I + 1], 1);
end;
Procedure HexStrToBuf (var aBuf: TIdBytes; SourStr: string; Start to Count: Integer);
Var
X: Integer;
The begin
SourStr:=StringReplace (SourStr, ' ', ' ', [rfReplaceAll]);
For: x=0 to 5 do
ABuf [Start + x] :=word (SourStr [x + 1]).
end;
Procedure TForm1. Btn3Click (Sender: TObject);
The begin
Lv_dev. The Clear;
LHM. SearchDev;
end;
{* remove dev *}
Procedure TForm1. Btn4Click (Sender: TObject);
Var
MAC: PChar;
The begin
MAC:=PChar (lbledt_mac. Text);
If the MAC="' then
Exit;
LHM. RemoveDev (MAC);
end;
{* connect dev *}
Procedure TForm1. Btn5Click (Sender: TObject);
Var
MAC, IP, port, PSD: PChar;
The begin
MAC:=PChar (lbledt_mac. Text);
IP:=PChar (lbledt_ip. Text);
Port:=PChar (lbledt_port. Text);
PSD:=PChar (lbledt_psd. Text);
If (MAC=' ') or (IP=' ') or (port=' ') or (PSD=' ') then
Exit;
LHM. ConnectDev (MAC, IP, port, PSD)
end;
{* send the data to the device by MAC *}
Procedure TForm1. Btn6Click (Sender: TObject);
Var
DataBuf: TIdBytes;
MacStr: PChar;
The begin
If (lbledt_Data. Text=' ') or (lbledt_mac_connected. Text=' ') then
Exit;
DataBuf:=HexStr2Buf (lbledt_Data. Text);
MacStr:=PChar (lbledt_mac_connected. Text);
LHM. SendDataByMac (DataBuf macStr);
end;
Procedure TForm1. Btn7Click (Sender: TObject);
The begin
Redt1. The Clear;
end;
Procedure TForm1. FRcvSearchResult (aData: TIdBytes);
Var
RxRcd: TUDPRcvRcd;
The begin
The Log (' RcvSearchResult: + Buf2HexStr (aData));
BytesToRaw (AData, RxRcd, 36);
With lv_dev. Items. The Add do
The begin
Caption:=Buf62Mac (RxRcd. DevMAC);
SubItems. Add (Buf42IP (@ RxRcd DevIP));
end;
end;
Procedure TForm1. Lv_devClick (Sender: TObject);
The begin
If lv_dev. ItemIndex=1 then
Exit;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull