I'm a Delphi 5 user. I'm trying to write a program to open a cash drawer.
I need to send a sequence of special characters directly to COM1 Port
I wrote the following code:
procedure TForm1.Button1Click(Sender: TObject);
var
hwndfile : HWND;
Written : DWORD;
ToWrite : String;
PToWrite,PWritten : Pointer;
begin
hwndfile:=CreateFile('COM1',GENERIC_WRITE,0,nil,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL);
PToWrite:=@ToWrite; {Pointer to the sequence of characters}
PWritten:=@Written;
ToWrite:=CHR(27)+CHR(112)+CHR(0)+CHR(100)+CHR(250); {sequence of characters}
WriteFile(hwndfile,PToWrite,5,PWritten,nil);
CloseHandle(hwndfile);
end;
The problem is that when I compile it, an error occurs in the "WriteFile" line:
[Error] main.pas(41): Types of actual and formal var parameters must be identical
(the error occurs in the PWritten parameter)
and I don't know how correct it. Any help?
I need to send a sequence of special characters directly to COM1 Port
I wrote the following code:
procedure TForm1.Button1Click(Sender: TObject);
var
hwndfile : HWND;
Written : DWORD;
ToWrite : String;
PToWrite,PWritten : Pointer;
begin
hwndfile:=CreateFile('COM1',GENERIC_WRITE,0,nil,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL);
PToWrite:=@ToWrite; {Pointer to the sequence of characters}
PWritten:=@Written;
ToWrite:=CHR(27)+CHR(112)+CHR(0)+CHR(100)+CHR(250); {sequence of characters}
WriteFile(hwndfile,PToWrite,5,PWritten,nil);
CloseHandle(hwndfile);
end;
The problem is that when I compile it, an error occurs in the "WriteFile" line:
[Error] main.pas(41): Types of actual and formal var parameters must be identical
(the error occurs in the PWritten parameter)
and I don't know how correct it. Any help?