Delphi Developers Guide...
Posted: Fri Dec 20, 2002 2:15 pm
A Delphi Developers guide brought to you by relix... :D
Matrix Orbital home of Serial RS232, USB, I2C, TTL, RS422, HDMI, EVE, SPI, QSPI, LCD, VFD, TFT, OLED, HMI and Touchscreen displays
https://www.lcdforums.com/forums/
Code: Select all
procedure TForm1.HelloWorld;
begin
//Initialize settings
ComPort1.Port := 'COM1';
ComPort1.BaudRate := br19200;
//Open the comport
try
ComPort1.Open;
except
//If there was an error while opening the comport, inform the user
//and exit
ShowMessage('Com-port 1 could not be opened.');
exit;
end;
//Send the string
ComPort1.WriteStr('Hello World!');
//Close the comport again
ComPort1.Close;
end;
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
begin
//This function will clear the screen by sending 'X'
//to the display after a command-byte (255)
//Initialize settings
ComPort1.Port := 'COM1';
ComPort1.BaudRate := br19200;
//Open the comport
try
ComPort1.Open;
except
//If there was an error while opening the comport, inform the user and exit
ShowMessage('Com-port 1 could not be opened.');
exit;
end;
//Send the command (commands sent to the display are always preceeded
//by byte 255, the command-byte):
ComPort1.WriteStr(#255'X');
//Close the port
ComPort1.Close;
end;
Code: Select all
procedure TForm1.Button2Click(Sender: TObject);
begin
//This function lights the backlight
//Initialize settings
ComPort1.Port := 'COM1';
ComPort1.BaudRate := br19200;
//Open the comport
try
ComPort1.Open;
except
//If there was an error while opening the comport, inform the user
//and exit
ShowMessage('Com-port 1 could not be opened.');
exit;
end;
//Send the command ('B' for backlight on), followed by 0 (zero) for infinite on
ComPort1.WriteStr(#255'B'#0);
//To set the backlight off, send 'F' instead of 'B', like this:
//ComPort1.WriteStr(#255'F');
//Close the port
ComPort1.Close;
end;
Code: Select all
...
//Open the comport
ComPort.Open;
//If opening the comport didn't work, exit
if not ComPort.Connected then
begin
ShowMessage('Unable to connect to comport ' + ComPort.Port + '.');
Close;
end;
//Now go through all the settings
if CB_BacklightOff.Checked then
ComPort.WriteStr(#255'F');
if CB_ClearScreen.Checked then
ComPort.WriteStr(#255'X');
if CB_WriteText.Checked then
ComPort.WriteStr(Edit_Text.Text);
//Now close the port again
ComPort.Close;
...