1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140:
| unit main_unit;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, StdCtrls, CPort, ComCtrls, ExtCtrls, StrUtils;
type TStringDynArray = Array of String; TFrm_Main = class(TForm) MainMenu1: TMainMenu; Datei1: TMenuItem; Open1: TMenuItem; Close1: TMenuItem; Settings1: TMenuItem; Datei2: TMenuItem; Close2: TMenuItem; ComPort1: TComPort; ools1: TMenuItem; Terminal1: TMenuItem; Panel1: TPanel; GroupBox1: TGroupBox; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; Label9: TLabel; Label10: TLabel;
procedure Close2Click(Sender: TObject); procedure Open1Click(Sender: TObject); procedure Close1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Settings1Click(Sender: TObject); procedure Terminal1Click(Sender: TObject); procedure FormResize(Sender: TObject); procedure ComPort1RxChar(Sender: TObject; Count: Integer); procedure FormClose(Sender: TObject; var Action: TCloseAction); function Explode(const Separator, S: string; Limit: Integer = 0): TStringDynArray; private public end;
var Frm_Main: TFrm_Main; Serial_in: String;
implementation
uses terminal_unit;
{$R *.dfm}
procedure TFrm_Main.ComPort1RxChar(Sender: TObject; Count: Integer); var Str: String; position: integer; type_of_input: String; exparr: TStringDynArray; const strUmbruch = #13 + #10; begin
ComPort1.ReadStr(Str, Count); Serial_in := Serial_in + Str;
position := pos(strUmbruch, Serial_in);
if position <> 0 then begin Delete(Serial_in, length(Serial_in)-1, length(serial_in));
type_of_input := LeftStr(Serial_in, 3);
if type_of_input = 'Pos' then begin exparr := explode(':', Serial_in); end;
Serial_in := ''; end; end;
function Explode(const Separator, S: string; Limit: Integer = 0): TStringDynArray; var SepLen: Integer; F, P: PChar; ALen, Index: Integer; begin SetLength(Result, 0); if (S = '') or (Limit < 0) then Exit; if Separator = '' then begin SetLength(Result, 1); Result[0] := S; Exit; end; SepLen := Length(Separator); ALen := Limit; SetLength(Result, ALen);
Index := 0; P := PChar(S); while P^ <> #0 do begin F := P; P := StrPos(P, PChar(Separator)); if (P = nil) or ((Limit > 0) and (Index = Limit - 1)) then P := StrEnd(F); if Index >= ALen then begin Inc(ALen, 5); SetLength(Result, ALen); end; SetString(Result[Index], F, P - F); Inc(Index); if P^ <> #0 then Inc(P, SepLen); end; if Index < ALen then SetLength(Result, Index); end;
end. |