|
Ideas -
Delphi
|
implementation
{$R *.DFM}
var
hCommFile : THandle;
// Botón para establecer la comunicación
procedure TForm1.Button1Click(Sender: TObject);
var
NumeroTfno: string;
PuertoCom: string;
numero: cardinal;
begin
NumeroTfno := 'ATDT 901120120' + #13 + #10;
PuertoCom := 'COM3'; // Puerto del modem
{ Utiliza el COM como si de un fichero más se tratase. Por ello la funcion CreateFile}
hCommFile := CreateFile(PChar(PuertoCom),
GENERIC_WRITE,
0,
nil,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if hCommFile=INVALID_HANDLE_VALUE then
begin
ShowMessage('No puedo abrir el puerto ' + PuertoCom);
exit;
end;
// Escribe en el fichero, es decir, efectúa el marcaje
numero := 0;
if WriteFile(hCommFile,
PChar(numerotfno)^,
Length(numerotfno),
numero,
nil) = false then
begin
ShowMessage('No puedo comunicar con el ' + PuertoCom);
end;
end;
// Botón para cerrar la comunicación
procedure TForm1.Button2Click(Sender: TObject);
begin
CloseHandle(hCommFile);
end;
|