|
Ideas -
Delphi
|
procedure TForm1.Button1Click(Sender: TObject);
var
CommPort : string;
hCommFile : THandle;
Buffer : PCommConfig;
size : DWORD;
begin
CommPort := 'COM1';
{Abir el puerto}
hCommFile := CreateFile(PChar(CommPort),
GENERIC_WRITE,
0,
nil,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if hCommFile=INVALID_HANDLE_VALUE then
begin
ShowMessage('Imposible abrir '+ CommPort);
exit;
end;
{Reservar espacio para el buffer temporal}
GetMem(Buffer, sizeof(TCommConfig));
{Obtener el tamaño de la estrucutra CommConfig}
size := 0;
GetCommConfig(hCommFile, Buffer^, size);
{Liberar el buffer temporal}
FreeMem(Buffer, sizeof(TCommConfig));
{Reservar espacion para la estructura CommConfig}
GetMem(Buffer, size);
GetCommConfig(hCommFile, Buffer^, size);
{Modificar la velocidad del puerto en baudios}
Buffer^.dcb.BaudRate := 1200;
{Establecer la nueva configuración del puerto}
SetCommConfig(hCommFile, Buffer^, size);
{Liberar el buffer}
FreeMem(Buffer, size);
{Cerrar el puerto}
CloseHandle(hCommFile);
end;
|