unit1.pas 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  6. Buttons, StdCtrls, SdpoSerial;
  7. type
  8. { TForm1 }
  9. TForm1 = class(TForm)
  10. BitBtn_close: TBitBtn;
  11. Button_connect: TButton;
  12. Button_disconnect: TButton;
  13. Button_send: TButton;
  14. ComboBox_flowcontrol: TComboBox;
  15. ComboBox_databits: TComboBox;
  16. ComboBox_stopbits: TComboBox;
  17. ComboBox_parite: TComboBox;
  18. ComboBox_port: TComboBox;
  19. ComboBox_baudrate: TComboBox;
  20. Edit1: TEdit;
  21. Label1: TLabel;
  22. Label2: TLabel;
  23. Label3: TLabel;
  24. Label4: TLabel;
  25. Label5: TLabel;
  26. Label6: TLabel;
  27. Memo_terminal: TMemo;
  28. SdpoSerial1: TSdpoSerial;
  29. procedure Button_connectClick(Sender: TObject);
  30. procedure Button_disconnectClick(Sender: TObject);
  31. procedure Button_sendClick(Sender: TObject);
  32. procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  33. procedure FormCreate(Sender: TObject);
  34. procedure SdpoSerial1RxData(Sender: TObject);
  35. private
  36. { private declarations }
  37. public
  38. { public declarations }
  39. end;
  40. var
  41. Form1: TForm1;
  42. implementation
  43. { TForm1 }
  44. procedure TForm1.FormCreate(Sender: TObject);
  45. begin
  46. SdpoSerial1.Active:=False;
  47. end;
  48. procedure TForm1.SdpoSerial1RxData(Sender: TObject);
  49. var rec:string;
  50. begin
  51. rec:=SdpoSerial1.ReadData;
  52. Memo_terminal.Append(rec);
  53. end;
  54. procedure TForm1.Button_connectClick(Sender: TObject);
  55. begin
  56. Memo_terminal.Clear;
  57. SdpoSerial1.Device:=ComboBox_port.text;
  58. SdpoSerial1.BaudRate:=TBaudrate(ComboBox_baudrate.ItemIndex);
  59. SdpoSerial1.DataBits:=TDataBits(ComboBox_databits.ItemIndex);
  60. SdpoSerial1.FlowControl:=TFlowControl(ComboBox_flowcontrol.ItemIndex);
  61. SdpoSerial1.Parity:=TParity(ComboBox_parite.ItemIndex);
  62. SdpoSerial1.StopBits:=TStopBits(ComboBox_stopbits.ItemIndex);
  63. SdpoSerial1.Active:=True;
  64. end;
  65. procedure TForm1.Button_disconnectClick(Sender: TObject);
  66. begin
  67. SdpoSerial1.Active:=false;
  68. end;
  69. procedure TForm1.Button_sendClick(Sender: TObject);
  70. begin
  71. SdpoSerial1.WriteData(Edit1.text);
  72. end;
  73. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  74. begin
  75. SdpoSerial1.Active:=false;
  76. end;
  77. initialization
  78. {$I unit1.lrs}
  79. end.