Ver Mensaje Individual
  #2  
Antiguo 25-08-2005
Avatar de Jobev Lee
Jobev Lee Jobev Lee is offline
Registrado
 
Registrado: jul 2005
Posts: 8
Reputación: 0
Jobev Lee Va por buen camino
Colaboremonos entonces...

Bueno, te cuento una buena.. tengo alguito de experiencia haciendo software para basculas, me facilitaria de harto saber si te estas comunicando directamente con la bascula o estas usando un indicador como intermediario...

Yo he hecho la mayoria de estos software en Delphicito y el Java, pero para serte sincero, nunca use ese componente que mencionas...(commport) ... Mejor te sale hacer una cosa, create tu propia libreria de captura de datos por el puerto Serial usando las instrucciones del Window (SDK)... a continuacion te mando el codigo de la unidad que podrias usar...
Código:
unit URS232;
interface
uses
	Windows, SysUtils;
type

	TRS232=class
	private
	   hCommFile : THandle;
	   sPuerto : String;
	public
	   constructor Create(lsPuerto: String; liBanda:Cardinal;
						  liByteSize, liParidad, liBitParada:Byte);
	   function LeerBuffer: string;
	   procedure EscribirBuffer(lsMensaje:string);
	end;
implementation
{ TRS232 }
constructor TRS232.Create(lsPuerto: String; liBanda:Cardinal;
						  liByteSize, liParidad, liBitParada:Byte);
var CommTimeouts : TCommTimeouts;
	CommConfig: TCommConfig;
	sizeConfig :  Cardinal;
begin
  sPuerto := lsPuerto;
hCommFile := CreateFile(PChar(sPuerto),
						  GENERIC_READ or GENERIC_WRITE,
						  0,
						  nil,
						  OPEN_EXISTING,
						  FILE_ATTRIBUTE_NORMAL,
						  0);
with CommTimeouts do
begin
  ReadIntervalTimeout := 0;
  ReadTotalTimeoutMultiplier := 0;
  ReadTotalTimeoutConstant := 300;
  WriteTotalTimeoutMultiplier := 0;
  WriteTotalTimeoutConstant := 200;
end;
if not SetCommTimeouts(hCommFile, CommTimeouts) then
	raise Exception.Create(Problemas estableciendo CommTimeouts);

	GetCommConfig(hCommFile, CommConfig, sizeConfig);
	with CommConfig do
	begin
		dcb.BaudRate := liBanda;//9600;//38400;//<-- Se comunica a esa velocidad ????
		dcb.ByteSize := liByteSize; //8;
		dcb.Parity := liParidad;//NOPARITY; //EVENPARITY;
		dcb.StopBits := liBitParada;;
	end;
	if not SetCommConfig(hCommFile, CommConfig, sizeConfig) then
	   raise Exception.Create(Problemas al querer establecer la configuracion);
end;

procedure TRS232.EscribirBuffer(lsMensaje: string);
var NumberWritten:dword;
begin
if hCommFile = INVALID_HANDLE_VALUE then
		raise Exception.Create('No se puede enviar los datos');
		WriteFile(hCommFile,
			PChar(lsMensaje)^,
			Length(lsMensaje),
			NumberWritten,
			nil);
end;

function TRS232.LeerBuffer: string;
var sTmp:string;
	c1:integer;
	chBuffer:array[0..255] of char;
	NumberOfBytesRead : dword;
begin
if hCommFile=INVALID_HANDLE_VALUE then exit;
if not ReadFile (hCommFile, chBuffer, sizeof(chBuffer),
			  NumberOfBytesRead, Nil) then
	raise Exception.Create('Imposible leer datos desde el puerto');
for c1:= 0 to NumberOfBytesRead - 1 do
	  sTmp:= sTmp+chBuffer[c1];
result:=sTmp;
end;
end.
...ahora, para mejor uso, te aconsejo que lo metas en un Hilo (que seria lo correcto) o en un timer (salida rapida) en donde tendrias que estar consultando si hay datos o no... eso lo consigues guardando el valor de la funcion en una variable local, y luego preguntas por el valor de la cadena, si es vacia.. no hay nada,,, si no... pues ya tu beras como se maneja...

Espero te sirva de ayuda cumpa, ami me funca... claro si es que estas trabajando en delphicito... ... cualquier cosa mantengamonos en contacto...

Atte..

Jobev Lee
Responder Con Cita