Ver Mensaje Individual
  #5  
Antiguo 23-09-2014
nuxbaster nuxbaster is offline
Miembro
NULL
 
Registrado: dic 2010
Posts: 13
Reputación: 0
nuxbaster Va por buen camino
Agradezco a todos su apoyo y comentarios, como les comente no soy programador avanzado, solo entiendo un poco de lógica e investigo pero este detalle ha sido un quebradero de cabeza les dejo las lineas que he colocado, estoy utilizando el Comport y el simulador de balanzas y Delphi XE3
Código Delphi [-]
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, CPort, Vcl.StdCtrls,StrUtils, Vcl.Grids,
  Vcl.ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ComPort1: TComPort;
    Button2: TButton;
    ListBox1: TListBox;
    Edit1: TEdit;
    Label1: TLabel;
    Button3: TButton;
    CheckBox1: TCheckBox;
    Label2: TLabel;
    Button4: TButton;
    ListView1: TListView;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure ComPort1RxChar(Sender: TObject; Count: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation


{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
comport1.ShowSetupDialog
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if ComPort1.Connected then
    ComPort1.Close
  else
    ComPort1.Open;
    Application.MessageBox('El puerto ha sido abierto de forma satisfactoria.','Abierto',0);
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  Str: String;
begin
  Str := Edit1.Text;
  if CheckBox1.Checked then
    Str := Str + #13#10;
    ComPort1.WriteStr(Str);
end;

procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);
var
  Str: String;
  begin

  ComPort1.ReadStr(Str, Count);
  while (length(Str)>1) and (Copy(Str,1,1)='0') do
    delete(Str,1,1);
    if Copy(Str,1,1)='.' then
    Str:= '0' + Str;

    ListBox1.Items.Add(Str);

end;
end.

Última edición por Casimiro Notevi fecha: 24-09-2014 a las 00:20:42.
Responder Con Cita