Ver Mensaje Individual
  #1  
Antiguo 05-02-2010
rad01 rad01 is offline
Registrado
 
Registrado: feb 2010
Posts: 6
Reputación: 0
rad01 Va por buen camino
Tengo algo de código y necesito un programa

hola amigos del foro mi problema es que no se programar en delphi soy tecnico electronico y quisiera si alguien me pudiese compilar este programa que en realidad hay 2 versiones si pudiesen las 2 seria muy bueno para ver cual se ad`pta mejor a mis necesidades, porque es mas o menos lo que busco un programa que controle un periferico por puerto serie por tiempo. abajo les dejo un link hacia las fuentes del programa. desde ya muchisimas gracias y deisculpen las molestias

Código Delphi [-]
function Activar_RTS(Puerto: String; Espera:  Cardinal): String;
var hPort: THandle; 
DCB:  TDCB;
begin 
 Result:= ''; 
 Puerto:= Uppercase(Puerto); // Cambiar esto si es necesario un puerto diferente  
 if (Puerto<>'COM1') and (Puerto<>'COM2') then exit; 
 hPort:= CreateFile(PChar('\\.\'+Puerto), GENERIC_READ or  GENERIC_WRITE,0,  nil, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); 
 if hPort<>INVALID_HANDLE_VALUE then begin  
  DCB.DCBlength:= sizeof(DCB); 
  if GetCommState(hPort,DCB) then begin 
   with  DCB do begin  
     BaudRate :=  CBR_9600; 
     ByteSize := 8; 
     Parity := NOPARITY; 
     StopBits :=  ONESTOPBIT; 
     Flags := $01; 
    end; 
    if  SetCommState(hPort,  DCB) then  begin 
     EscapeCommFunction(hPort,SETRTS); 
     Sleep(Espera); 
     EscapeCommFunction(hPort,CLRRTS); 
    end; 
   end; 
   CloseHandle(hPort); 
  end;
 end;

y este es otro
Código Delphi [-]
var hPort: Thandle; 
procedure AbrirPuerto(Puerto: String);
var DCB: TDCB;
begin 
 Puerto:= Uppercase(Puerto); // Cambiar esto si es necesario un puerto diferente 
 if  (Puerto<>'COM1') and (Puerto<>'COM2') then exit; 
 hPort:= CreateFile(PChar('\\.\'+Puerto), GENERIC_READ or GENERIC_WRITE,0, nil, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); 
 if hPort<>INVALID_HANDLE_VALUE then begin  
  DCB.DCBlength:= sizeof(DCB); 
  if GetCommState(hPort,DCB) then begin 
   with  DCB do begin  
    BaudRate :=  CBR_9600; 
    ByteSize := 8; 
    Parity := NOPARITY; 
    StopBits :=  ONESTOPBIT; 
    Flags := $01; 
   end; 
   if  SetCommState(hPort,  DCB) then  Exit; 
  end; 
  CloseHandle(hPort); 
  hPort:= INVALID_HANDLE_VALUE; 
 end;
end; 

procedure  CerrarPuerto;
begin 
 if hPort <> INVALID_HANDLE_VALUE then begin  
  CloseHandle(hPort); 
  hPort:= INVALID_HANDLE_VALUE; 
 end;
end; 

procedure  ActivarRTS;
begin 
 if hPort <> INVALID_HANDLE_VALUE then EscapeCommFunction(hPort,SETRTS);
end; 

procedure DesactivarRTS;
begin 
 if  hPort <> INVALID_HANDLE_VALUE then  EscapeCommFunction(hPort,CLRRTS);
end;

http://delphi.jmrds.com/?q=node/8

Última edición por ContraVeneno fecha: 05-02-2010 a las 23:15:55. Razón: no salio bien - agregar tags
Responder Con Cita