You are on page 1of 10

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,


Dialogs, StdCtrls, CPort;

type

Tformpctopc = class(TForm)

comserial: TComPort;

memokirim_: TMemo;

Label1: TLabel;

Label2: TLabel;

send: TButton;

setup: TButton;

exit: TButton;

writedata: TEdit;

memoascii_krim: TMemo;

mebiner_krim: TMemo;

mehexa_krim: TMemo;

measciitrima: TMemo;

mebinertrima: TMemo;

mehexatrima: TMemo;

Label3: TLabel;

Label4: TLabel;

Label5: TLabel;

Label6: TLabel;

Label7: TLabel;

Label8: TLabel;

Label9: TLabel;
Label10: TLabel;

Label11: TLabel;

Button1: TButton;

memoterima: TMemo;

procedure comseialRxChar(Sender: TObject; Count: Integer);

procedure FormCreate(Sender: TObject);

procedure sendClick(Sender: TObject);

procedure setupClick(Sender: TObject);

procedure exitClick(Sender: TObject);

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

formpctopc: Tformpctopc;

implementation

{$R *.dfm}

procedure hexakebiner(kode_hexa: string);

var

b:integer;
data,kode_biner,kode : string;

begin

kode_biner:=' ';

for b:=1 to length(kode_hexa) do

begin

kode:=kode_hexa[b];

if kode = '0' then data := '0000';

if kode = '1' then data := '0001';

if kode = '2' then data := '0010';

if kode = '3' then data := '0011';

if kode = '4' then data := '0100';

if kode = '5' then data := '0101';

if kode = '6' then data := '0110';

if kode = '7' then data := '0111';

if kode = '8' then data := '1000';

if kode = '9' then data := '1001';

if kode = 'a' then data := '1010';

if kode = 'b' then data := '1011';

if kode = 'c' then data := '1100';

if kode = 'd' then data := '1101';

if kode = 'e' then data := '1110';

if kode = 'f' then data := '1111';

kode_biner := kode_biner + ' ' + data ;

end;

end;
procedure Tformpctopc.comseialRxChar(Sender: TObject; Count: Integer);

var

b,a:integer;

str,kode_hexa,kode_ascii,kode,data,kode_biner:string;

begin

comserial.ReadStr(str,Count);

memoterima.Text:=memoterima.Text + str;

for a:=1 to length(str) do

begin

kode_ascii:=inttostr(ord(str[a]));

measciitrima.lines.Add(str[a]+'>'+kode_ascii);

kode_hexa:=inttohex(ord(str[a]),1);

mehexatrima.lines.add(str[a]+' > '+kode_hexa);

kode_biner:='';

for b:=1 to 2 do

begin

kode:=kode_hexa[b];

if kode = '0' then data := '0000';

if kode = '1' then data := '0001';

if kode = '2' then data := '0010';

if kode = '3' then data := '0011';

if kode = '4' then data := '0100';


if kode = '5' then data := '0101';

if kode = '6' then data := '0110';

if kode = '7' then data := '0111';

if kode = '8' then data := '1000';

if kode = '9' then data := '1001';

if kode = 'a' then data := '1010';

if kode = 'b' then data := '1011';

if kode = 'c' then data := '1100';

if kode = 'd' then data := '1101';

if kode = 'e' then data := '1110';

if kode = 'f' then data := '1111';

kode_biner := kode_biner + ' ' + data ;

end;

mebinertrima.lines.add(str[a]+' >=> '+ kode_biner);

end;

end;

procedure Tformpctopc.FormCreate(Sender: TObject);

begin

comserial.Open;
end;

procedure Tformpctopc.sendClick(Sender: TObject);

var

b,a:integer;

str,kode_hexa,kode_ascii,kode,data,kode_biner:string;

begin

str:=writedata.text;

comserial.writestr(str);

memokirim_.Lines.Add('Pengirim :' + writedata.Text);

for a:=1 to length(str) do

begin

kode_ascii:=inttostr(ord(str[a]));

memoascii_krim.lines.Add(str[a]+'>'+kode_ascii);

kode_hexa:=inttohex(ord(str[a]),1);

mehexa_krim.lines.add(str[a]+' > '+kode_hexa);

kode_biner:='';

for b:=1 to 2 do

begin

kode:=kode_hexa[b];

if kode = '0' then data := '0000';

if kode = '1' then data := '0001';

if kode = '2' then data := '0010';


if kode = '3' then data := '0011';

if kode = '4' then data := '0100';

if kode = '5' then data := '0101';

if kode = '6' then data := '0110';

if kode = '7' then data := '0111';

if kode = '8' then data := '1000';

if kode = '9' then data := '1001';

if kode = 'a' then data := '1010';

if kode = 'b' then data := '1011';

if kode = 'c' then data := '1100';

if kode = 'd' then data := '1101';

if kode = 'e' then data := '1110';

if kode = 'f' then data := '1111';

kode_biner := kode_biner + ' ' + data ;

end;

mebiner_krim.lines.add(str[a]+' >=> '+ kode_biner);

end;

end;

procedure Tformpctopc.setupClick(Sender: TObject);

begin

comserial.ShowSetupDialog;
end;

procedure Tformpctopc.exitClick(Sender: TObject);

begin

comserial.Close;

Application.Terminate;

end;

procedure Tformpctopc.Button1Click(Sender: TObject);

begin

memokirim_.Clear;

memoterima.Clear;

memoascii_krim.Clear;

mebiner_krim.Clear;

mehexa_krim.Clear;

measciitrima.Clear;

mebinertrima.Clear;

mehexatrima.Clear;

writedata.Clear;

end;

end.

You might also like