1428 lines
39 KiB
ObjectPascal
1428 lines
39 KiB
ObjectPascal
unit LsPlcMain;
|
||
|
||
interface
|
||
|
||
uses
|
||
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
||
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Vcl.ExtCtrls,
|
||
System.Win.ScktComp, System.StrUtils, Vcl.Grids, Vcl.ComCtrls, Vcl.Menus,
|
||
FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf,
|
||
FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async,
|
||
FireDAC.Phys, FireDAC.VCLUI.Wait, FireDAC.Stan.Param, FireDAC.DatS,
|
||
FireDAC.DApt.Intf, FireDAC.DApt, FireDAC.Phys.MySQLDef, FireDAC.Phys.MySQL,
|
||
Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client, IniFiles, plc_addr_info, plc_tmp_data,
|
||
System.TypInfo, Math;
|
||
|
||
type
|
||
TfrmLsPlcMain = class(TForm)
|
||
ClientSocket1: TClientSocket;
|
||
Timer1: TTimer;
|
||
GroupBox1: TGroupBox;
|
||
GroupBox2: TGroupBox;
|
||
GroupBox3: TGroupBox;
|
||
Edit2: TEdit;
|
||
GroupBox4: TGroupBox;
|
||
Edit3: TEdit;
|
||
Edit4: TEdit;
|
||
Label1: TLabel;
|
||
GroupBox5: TGroupBox;
|
||
Edit5: TEdit;
|
||
PageControl1: TPageControl;
|
||
TabSheet1: TTabSheet;
|
||
Panel5: TPanel;
|
||
Splitter1: TSplitter;
|
||
Memo1: TMemo;
|
||
Memo2: TMemo;
|
||
Splitter2: TSplitter;
|
||
Panel6: TPanel;
|
||
Memo3: TMemo;
|
||
TabSheet2: TTabSheet;
|
||
ComboBox1: TComboBox;
|
||
SpeedButton1: TSpeedButton;
|
||
SpeedButton2: TSpeedButton;
|
||
PopupMenu1: TPopupMenu;
|
||
Splitter3: TSplitter;
|
||
N1: TMenuItem;
|
||
PopupMenu2: TPopupMenu;
|
||
Address1: TMenuItem;
|
||
N2: TMenuItem;
|
||
Address2: TMenuItem;
|
||
Timer2: TTimer;
|
||
TabSheet3: TTabSheet;
|
||
StringGrid3: TStringGrid;
|
||
Memo4: TMemo;
|
||
Splitter4: TSplitter;
|
||
GroupBox6: TGroupBox;
|
||
BitBtn4: TBitBtn;
|
||
GroupBox8: TGroupBox;
|
||
StringGrid2: TStringGrid;
|
||
GroupBox9: TGroupBox;
|
||
StringGrid1: TStringGrid;
|
||
FDConnection1: TFDConnection;
|
||
FDQuery1: TFDQuery;
|
||
FDPhysMySQLDriverLink1: TFDPhysMySQLDriverLink;
|
||
BitBtn5: TBitBtn;
|
||
BitBtn6: TBitBtn;
|
||
GroupBox10: TGroupBox;
|
||
Label4: TLabel;
|
||
ComboBox2: TComboBox;
|
||
LabeledEdit4: TLabeledEdit;
|
||
LabeledEdit1: TLabeledEdit;
|
||
LabeledEdit2: TLabeledEdit;
|
||
BitBtn1: TBitBtn;
|
||
BitBtn3: TBitBtn;
|
||
Panel4: TPanel;
|
||
BitBtn2: TBitBtn;
|
||
Panel1: TPanel;
|
||
LabeledEdit6: TLabeledEdit;
|
||
LabeledEdit7: TLabeledEdit;
|
||
LabeledEdit8: TLabeledEdit;
|
||
LabeledEdit9: TLabeledEdit;
|
||
LabeledEdit10: TLabeledEdit;
|
||
GroupBox7: TGroupBox;
|
||
BitBtn10: TBitBtn;
|
||
BitBtn9: TBitBtn;
|
||
GroupBox11: TGroupBox;
|
||
BitBtn7: TBitBtn;
|
||
BitBtn8: TBitBtn;
|
||
LabeledEdit3: TLabeledEdit;
|
||
GroupBox12: TGroupBox;
|
||
Edit1: TEdit;
|
||
CheckBox1: TCheckBox;
|
||
procedure BitBtn1Click(Sender: TObject);
|
||
procedure FormCreate(Sender: TObject);
|
||
procedure BitBtn3Click(Sender: TObject);
|
||
procedure BitBtn2Click(Sender: TObject);
|
||
procedure FormDestroy(Sender: TObject);
|
||
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
|
||
procedure BitBtn4Click(Sender: TObject);
|
||
procedure Timer1Timer(Sender: TObject);
|
||
procedure BitBtn5Click(Sender: TObject);
|
||
procedure BitBtn6Click(Sender: TObject);
|
||
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||
procedure FormShow(Sender: TObject);
|
||
procedure ComboBox1Change(Sender: TObject);
|
||
procedure SpeedButton1Click(Sender: TObject);
|
||
procedure SpeedButton2Click(Sender: TObject);
|
||
procedure N1Click(Sender: TObject);
|
||
procedure Address1Click(Sender: TObject);
|
||
procedure Address2Click(Sender: TObject);
|
||
procedure BitBtn7Click(Sender: TObject);
|
||
procedure BitBtn9Click(Sender: TObject);
|
||
procedure BitBtn10Click(Sender: TObject);
|
||
procedure BitBtn8Click(Sender: TObject);
|
||
procedure ClientSocket1Connecting(Sender: TObject;
|
||
Socket: TCustomWinSocket);
|
||
procedure ClientSocket1Disconnect(Sender: TObject;
|
||
Socket: TCustomWinSocket);
|
||
procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
|
||
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
|
||
procedure ComboBox2Change(Sender: TObject);
|
||
procedure ComboBox2CloseUp(Sender: TObject);
|
||
procedure LabeledEdit3KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
procedure LabeledEdit4KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
procedure LabeledEdit1KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
procedure LabeledEdit2KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
procedure ComboBox1CloseUp(Sender: TObject);
|
||
procedure Edit2KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||
procedure Edit5KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||
procedure Edit3KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||
procedure Edit4KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||
procedure LabeledEdit6KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
procedure LabeledEdit7KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
procedure LabeledEdit8KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
procedure LabeledEdit9KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
procedure LabeledEdit10KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
procedure StringGrid1Click(Sender: TObject);
|
||
procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||
procedure Timer2Timer(Sender: TObject);
|
||
private
|
||
{ Private declarations }
|
||
AddrList: TStringList;
|
||
AddrIndex: Integer;
|
||
FqryList: TList;
|
||
FtmpList: TList;
|
||
|
||
procedure ParseAndDisplayData(const Raw: TBytes; const Addr: string);
|
||
procedure BuildReadPacket1;
|
||
procedure BuildReadPacket2(const Addr: string);
|
||
function ByteToBinStr(B: Byte): string;
|
||
|
||
procedure xSetGridColumns;
|
||
procedure xSetGridInit(grid: TStringGrid);
|
||
procedure xSetDatabase;
|
||
procedure xSetPlcInfoSetting(nameStr: string);
|
||
procedure xSetPlcSections;
|
||
procedure xUpdtePlcConfig;
|
||
|
||
function xWriteInsertSql(curPlc: Tplc_addr_info): string;
|
||
function xWriteUpdateSql(tmpPlc: Tplc_addr_info): string;
|
||
function xGetAllAttrNames(out valStrs: TStrings; newObj: TObject): TStrings;
|
||
function xAddSqlMark(velStr: string): string;
|
||
function xDatabaseExecSQL(sqlStr: string): Boolean;
|
||
|
||
procedure xPlcAddrInfoView;
|
||
procedure xFreeAll(tmpList: TList);
|
||
procedure xFreeAllFtmpList;
|
||
function xGetObjPlcAddrInfo: TList;
|
||
procedure xShowPlcAddrInfo(FqryList: TList);
|
||
procedure xAutoResizeStringGridColumns(Grid: TStringGrid; Canvas: TCanvas);
|
||
procedure xStringGridInit(grid: TStringGrid);
|
||
function xSavePlcTmpData(tmpPlc: Tplc_addr_info): Tplc_tmp_data;
|
||
function xWriteInsertSqlToTmpData(tmpData: Tplc_tmp_data): string;
|
||
procedure xShowPlcTmpData;
|
||
public
|
||
{ Public declarations }
|
||
end;
|
||
|
||
var
|
||
frmLsPlcMain: TfrmLsPlcMain;
|
||
|
||
implementation
|
||
|
||
uses
|
||
PlcAddressEdit;
|
||
|
||
var
|
||
TxBuf: array[0..1023] of Byte;
|
||
RxBuf: array[0..1023] of Byte;
|
||
plcIdx: Integer;
|
||
runLog: Boolean;
|
||
rowIdx: Integer;
|
||
|
||
{$R *.dfm}
|
||
|
||
procedure TfrmLsPlcMain.Address1Click(Sender: TObject);
|
||
var
|
||
cidx, ridx: Integer;
|
||
upOk: Boolean;
|
||
sqlStr: string;
|
||
tmpPlc: Tplc_addr_info;
|
||
tmpForm: TfrmPlcAddressEdit;
|
||
begin
|
||
if not FDConnection1.Connected then begin
|
||
showMessage('<27>켱 "DB <20><><EFBFBD><EFBFBD>" <20><>ư<EFBFBD><C6B0> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA>̽<EFBFBD><CCBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ּ<EFBFBD><D6BC><EFBFBD>!!');
|
||
Exit;
|
||
end;
|
||
if StringGrid2.Objects[StringGrid2.Col,StringGrid2.Row] = nil then Exit;
|
||
cidx := StringGrid2.Rows[0].IndexOf('<27><>Ī');
|
||
ridx := StringGrid2.Row;
|
||
tmpPlc := Tplc_addr_info(StringGrid2.Objects[cidx,ridx]);
|
||
|
||
tmpForm := TfrmPlcAddressEdit.Create(Self);
|
||
tmpForm.Tag := 1;
|
||
tmpForm.objPlc := tmpPlc;
|
||
if tmpForm.ShowModal = mrOk then begin
|
||
//Tplc_addr_info db <20><><EFBFBD><EFBFBD>..
|
||
tmpPlc := TmpForm.objPlc;
|
||
//get update sql str..
|
||
sqlStr := xWriteUpdateSql(tmpPlc);
|
||
//sql <20><><EFBFBD><EFBFBD>..
|
||
upOk := xDatabaseExecSQL(sqlStr);
|
||
end;
|
||
tmpForm.Free;
|
||
if upOk then begin
|
||
//StringGrid2 <20><><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>..
|
||
StringGrid2.Objects[cidx,ridx] := tmpPlc;
|
||
StringGrid2.Cells[cidx,ridx] := tmpPlc.Name;
|
||
cidx := StringGrid2.Rows[0].IndexOf('Address');
|
||
StringGrid2.Cells[cidx,ridx] := tmpPlc.Address;
|
||
cidx := StringGrid2.Rows[0].IndexOf('<27><><EFBFBD><EFBFBD>');
|
||
StringGrid2.Cells[cidx,ridx] := tmpPlc.Descriptions;
|
||
//Cells ĭ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>..
|
||
//xAutoResizeStringGridColumns(StringGrid2, Canvas);
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.Address2Click(Sender: TObject);
|
||
var
|
||
cidx, ridx: Integer;
|
||
upOk: Boolean;
|
||
sqlStr: string;
|
||
tmpPlc: Tplc_addr_info;
|
||
begin
|
||
if not FDConnection1.Connected then begin
|
||
showMessage('<27>켱 "DB <20><><EFBFBD><EFBFBD>" <20><>ư<EFBFBD><C6B0> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA>̽<EFBFBD><CCBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ּ<EFBFBD><D6BC><EFBFBD>!!');
|
||
Exit;
|
||
end;
|
||
if StringGrid2.Objects[StringGrid2.Col,StringGrid2.Row] = nil then Exit;
|
||
cidx := StringGrid2.Rows[0].IndexOf('<27><>Ī');
|
||
ridx := StringGrid2.Row;
|
||
tmpPlc := Tplc_addr_info(StringGrid2.Objects[cidx,ridx]);
|
||
tmpPlc.IsValid := '0';
|
||
//get update sql str..
|
||
sqlStr := xWriteUpdateSql(tmpPlc);
|
||
//sql <20><><EFBFBD><EFBFBD>..
|
||
upOk := xDatabaseExecSQL(sqlStr);
|
||
if upOk then xPlcAddrInfoView;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.BitBtn10Click(Sender: TObject);
|
||
begin
|
||
if FDConnection1.Connected then begin
|
||
FDConnection1.Connected := False;
|
||
if not FDConnection1.Connected then begin
|
||
Memo4.Lines.Add(LabeledEdit6.Text + ' <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.');
|
||
end else begin
|
||
Memo4.Lines.Add(LabeledEdit6.Text + ' <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>!!');
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.BitBtn1Click(Sender: TObject);
|
||
begin
|
||
xUpdtePlcConfig;
|
||
|
||
try
|
||
if not ClientSocket1.Active then begin
|
||
ClientSocket1.Host := Trim(LabeledEdit1.Text);
|
||
ClientSocket1.Port := StrToIntDef(LabeledEdit2.Text, 2004);
|
||
ClientSocket1.Open;
|
||
end;
|
||
except
|
||
on E: Exception do begin
|
||
Memo1.Lines.Add('<27><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>: ' + E.Message);
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.BitBtn2Click(Sender: TObject);
|
||
begin
|
||
if ClientSocket1.Active then begin
|
||
ClientSocket1.Close;
|
||
end;
|
||
if FDConnection1.Connected then begin
|
||
FDConnection1.Connected := False;
|
||
end;
|
||
Application.Terminate;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.BitBtn3Click(Sender: TObject);
|
||
begin
|
||
if ClientSocket1.Active then begin
|
||
ClientSocket1.Close;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.BitBtn4Click(Sender: TObject);
|
||
var
|
||
Sent, Recv: Integer;
|
||
begin
|
||
if not ClientSocket1.Active then Exit;
|
||
|
||
BuildReadPacket1;
|
||
|
||
Sent := ClientSocket1.Socket.SendBuf(TxBuf, 36);
|
||
if Sent <> 36 then begin
|
||
Memo1.Lines.Add('<27><>Ŷ <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>');
|
||
Exit;
|
||
end;
|
||
|
||
Recv := ClientSocket1.Socket.ReceiveBuf(RxBuf, 34);
|
||
if Recv < 34 then begin
|
||
Memo1.Lines.Add('<27><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>');
|
||
Exit;
|
||
end;
|
||
|
||
// 1. Memo1: <20><><EFBFBD><EFBFBD> HEX
|
||
var hexStr := '';
|
||
for var i := 0 to Recv - 1 do hexStr := hexStr + IntToHex(RxBuf[i], 2) + ' ';
|
||
Memo1.Lines.Add(hexStr);
|
||
|
||
// 2. Memo2: <20>ؼ<EFBFBD><D8BC><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
var value := RxBuf[32] + (RxBuf[33] shl 8);
|
||
Memo2.Lines.Add('DEC: ' + IntToStr(value));
|
||
StringGrid1.Cells[1,1] := Trim(Edit2.Text) + '=' + IntToStr(value);
|
||
Memo2.Lines.Add('HEX: ' + IntToHex(value, 4));
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.BitBtn5Click(Sender: TObject);
|
||
begin
|
||
if not ClientSocket1.Active then Exit;
|
||
|
||
if AddrIndex = 0 then begin
|
||
xSetGridInit(StringGrid1);
|
||
xSetGridColumns;
|
||
end;
|
||
// Timer1.Interval := 500;
|
||
Timer1.Interval := StrToIntDef(Trim(Edit5.Text),1000);
|
||
Timer1.Enabled := True;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.BitBtn6Click(Sender: TObject);
|
||
begin
|
||
if not ClientSocket1.Active then Exit;
|
||
|
||
Timer1.Enabled := False;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.BitBtn7Click(Sender: TObject);
|
||
begin
|
||
if not FDConnection1.Connected then begin
|
||
showMessage('<27>켱 "DB <20><><EFBFBD><EFBFBD>" <20><>ư<EFBFBD><C6B0> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA>̽<EFBFBD><CCBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ּ<EFBFBD><D6BC><EFBFBD>!!');
|
||
Exit;
|
||
end;
|
||
//Timer2.Interval := 250;
|
||
Timer2.Interval := StrToIntDef(Trim(Edit1.Text),1000);
|
||
Timer2.Enabled := True;
|
||
runLog := True;
|
||
PageControl1.ActivePageIndex := 2;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.BitBtn8Click(Sender: TObject);
|
||
begin
|
||
if not FDConnection1.Connected then begin
|
||
showMessage('<27>켱 "DB <20><><EFBFBD><EFBFBD>" <20><>ư<EFBFBD><C6B0> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA>̽<EFBFBD><CCBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ּ<EFBFBD><D6BC><EFBFBD>!!');
|
||
Exit;
|
||
end;
|
||
runLog := False;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.BitBtn9Click(Sender: TObject);
|
||
var
|
||
Ini: TIniFile;
|
||
IniPath: string;
|
||
begin
|
||
// ini <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> (<28><>: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϰ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>)
|
||
IniPath := ExtractFilePath(ParamStr(0)) + 'db_config.ini';
|
||
// <20><><EFBFBD>ΰ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ڵ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
//ForceDirectories(ExtractFilePath(IniPath));
|
||
|
||
// ini <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>..
|
||
Ini := TIniFile.Create(IniPath);
|
||
try
|
||
Ini.WriteString('Database', 'DBName', LabeledEdit6.Text);
|
||
Ini.WriteString('Database', 'User', LabeledEdit7.Text);
|
||
Ini.WriteString('Database', 'Password', LabeledEdit8.Text);
|
||
Ini.WriteString('Database', 'Server', LabeledEdit9.Text);
|
||
Ini.WriteString('Database', 'Port', LabeledEdit10.Text);
|
||
finally
|
||
Ini.Free;
|
||
end;
|
||
|
||
// <20><><EFBFBD><EFBFBD> FireDAC <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20>߰<EFBFBD>
|
||
FDConnection1.Params.Clear;
|
||
FDConnection1.Params.DriverID := 'MySQL'; // <20>Ǵ<EFBFBD> PostgreSQL
|
||
FDConnection1.Params.Database := LabeledEdit6.Text;
|
||
FDConnection1.Params.UserName := LabeledEdit7.Text;
|
||
FDConnection1.Params.Password := LabeledEdit8.Text;
|
||
FDConnection1.Params.Add('Server=' + LabeledEdit9.Text);
|
||
FDConnection1.Params.Add('Port=' + LabeledEdit10.Text);
|
||
FDConnection1.Params.Add('CharacterSet=utf8mb4');
|
||
FDConnection1.Connected := True;
|
||
if FDConnection1.Connected then begin
|
||
PageControl1.ActivePageIndex := 2;
|
||
Memo4.Lines.Add(LabeledEdit6.Text + ' <20><><EFBFBD><EFBFBD> <20>Ǿ<EFBFBD><C7BE><EFBFBD><EFBFBD>ϴ<EFBFBD>.');
|
||
xPlcAddrInfoView;
|
||
end else begin
|
||
Memo4.Lines.Add(LabeledEdit6.Text + ' <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>!!');
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.BuildReadPacket1;
|
||
var
|
||
i, varcnt, sum: Integer;
|
||
addrStr: string;
|
||
begin
|
||
FillChar(TxBuf, SizeOf(TxBuf), 0);
|
||
|
||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
Move('LSIS-XGT', TxBuf[0], 8);
|
||
TxBuf[8] := $00; TxBuf[9] := $00;
|
||
TxBuf[10] := $00; TxBuf[11] := $00;
|
||
TxBuf[12] := $A0; // XGK
|
||
TxBuf[13] := $33;
|
||
TxBuf[14] := $00; TxBuf[15] := $00;
|
||
TxBuf[16] := 16; // Length (<28><><EFBFBD>ɿ<EFBFBD><C9BF><EFBFBD> 16<31><36><EFBFBD><EFBFBD>Ʈ)
|
||
TxBuf[17] := $00;
|
||
TxBuf[18] := $00;
|
||
|
||
// CheckSum <20><><EFBFBD><EFBFBD>
|
||
sum := 0;
|
||
for i := 0 to 18 do begin
|
||
sum := sum + TxBuf[i];
|
||
if sum > 255 then sum := sum - 256;
|
||
end;
|
||
TxBuf[19] := sum;
|
||
|
||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
TxBuf[20] := $54; // READ
|
||
TxBuf[21] := 0; // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>Ǵ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
TxBuf[22] := $02; // DataType = WORD
|
||
TxBuf[23] := 0; // $30; DataType (<28>̾<EFBFBD><CCBE><EFBFBD>)
|
||
TxBuf[24] := 0; // $30; LinkID (2)
|
||
TxBuf[25] := 0; // $30; (<28>̾<EFBFBD><CCBE><EFBFBD>)
|
||
TxBuf[26] := $01; // Variable count
|
||
TxBuf[27] := 0; // $30; (<28>̾<EFBFBD><CCBE><EFBFBD>)
|
||
{
|
||
TxBuf[28] := $06; // Variable length
|
||
TxBuf[29] := 0; // $30; (<28>̾<EFBFBD><CCBE><EFBFBD>)
|
||
TxBuf[30] := $25; // '%'
|
||
TxBuf[31] := Ord('K'); // <20><><EFBFBD><EFBFBD><EFBFBD>̽<EFBFBD><CCBD>ڵ<EFBFBD> 'K'
|
||
TxBuf[32] := Ord('W'); // <20><><EFBFBD><EFBFBD>
|
||
TxBuf[33] := Ord('3'); // <20>ּ<EFBFBD> 301
|
||
TxBuf[34] := Ord('0');
|
||
TxBuf[35] := Ord('1');
|
||
}
|
||
//%MW556 <20><><EFBFBD><EFBFBD> <20>µ<EFBFBD>..
|
||
addrStr := Trim(ComboBox1.Text) + Trim(Edit2.Text);
|
||
varcnt := Length(addrStr);
|
||
TxBuf[28] := varcnt;
|
||
TxBuf[29] := 0;
|
||
for i := 1 to varcnt do TxBuf[29 + i] := Ord(addrStr[i]);
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.BuildReadPacket2(const Addr: string);
|
||
var
|
||
i, varcnt: Integer;
|
||
begin
|
||
FillChar(TxBuf, SizeOf(TxBuf), 0);
|
||
Move('LSIS-XGT', TxBuf[0], 8);
|
||
TxBuf[12] := $A0; // XGK
|
||
TxBuf[13] := $33;
|
||
TxBuf[14] := 0;
|
||
TxBuf[15] := 0;
|
||
TxBuf[16] := 16; // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
TxBuf[17] := 0;
|
||
TxBuf[18] := 0;
|
||
|
||
// Checksum <20><><EFBFBD><EFBFBD>
|
||
var sum := 0;
|
||
for i := 0 to 18 do begin
|
||
sum := sum + TxBuf[i];
|
||
if sum > 255 then sum := sum - 256;
|
||
end;
|
||
TxBuf[19] := sum;
|
||
|
||
// <20><><EFBFBD>ɺ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
TxBuf[20] := $54; // READ
|
||
TxBuf[21] := 0;
|
||
TxBuf[22] := 2; // WORD
|
||
TxBuf[23] := 0;
|
||
TxBuf[24] := 0;
|
||
TxBuf[25] := 0;
|
||
TxBuf[26] := 1;
|
||
TxBuf[27] := 0;
|
||
|
||
varcnt := Length(Addr); // <20><>: %MW121 <20><> 6
|
||
TxBuf[28] := varcnt;
|
||
TxBuf[29] := 0;
|
||
|
||
// <20>ּ<EFBFBD> <20><><EFBFBD><EFBFBD> (ASCII)
|
||
for i := 1 to varcnt do TxBuf[29 + i] := Ord(Addr[i]);
|
||
|
||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
var s := 'TxBuf (HEX): ';
|
||
for i := 20 to 29 + varcnt do
|
||
s := s + IntToHex(TxBuf[i], 2) + ' ';
|
||
Memo1.Lines.Add(s);
|
||
end;
|
||
|
||
function TfrmLsPlcMain.ByteToBinStr(B: Byte): string;
|
||
var
|
||
i: Integer;
|
||
begin
|
||
Result := '';
|
||
for i := 7 downto 0 do begin
|
||
if (B and (1 shl i)) <> 0 then Result := Result + '1'
|
||
else Result := Result + '0';
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.ClientSocket1Connecting(Sender: TObject;
|
||
Socket: TCustomWinSocket);
|
||
begin
|
||
Memo1.Lines.Add('<27><><EFBFBD><EFBFBD> <20>õ<EFBFBD>..');
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.ClientSocket1Disconnect(Sender: TObject;
|
||
Socket: TCustomWinSocket);
|
||
begin
|
||
Memo1.Lines.Add('<27><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!');
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.ClientSocket1Error(Sender: TObject;
|
||
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer);
|
||
begin
|
||
Memo1.Lines.Add('<27><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>..');
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.ClientSocket1Read(Sender: TObject;
|
||
Socket: TCustomWinSocket);
|
||
var
|
||
Buf: array[0..1023] of Byte;
|
||
i, Len: Integer;
|
||
RawData: TBytes;
|
||
BufCopy: TBytes;
|
||
S: string;
|
||
Recv: Integer;
|
||
begin
|
||
Len := Socket.ReceiveBuf(Buf, SizeOf(Buf));
|
||
if Len > 0 then begin
|
||
SetLength(RawData, Len);
|
||
Move(Buf, RawData[0], Len);
|
||
|
||
// 1. Memo1<6F><31> <20><><EFBFBD><EFBFBD> ǥ<><C7A5>
|
||
S := '';
|
||
for i := 0 to Len - 1 do S := S + IntToHex(RawData[i], 2) + ' ';
|
||
|
||
Memo1.Lines.Add('>> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> (HEX)');
|
||
Memo1.Lines.Add(S);
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.ComboBox1Change(Sender: TObject);
|
||
begin
|
||
xSetGridInit(StringGrid1);
|
||
xSetGridColumns;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.ComboBox1CloseUp(Sender: TObject);
|
||
begin
|
||
Edit2.SetFocus;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.ComboBox2Change(Sender: TObject);
|
||
begin
|
||
xSetPlcInfoSetting(ComboBox2.Text);
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.ComboBox2CloseUp(Sender: TObject);
|
||
begin
|
||
LabeledEdit3.SetFocus;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.Edit1KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
begin
|
||
if Key = VK_RETURN then BitBtn7.SetFocus;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.Edit2KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
begin
|
||
if Key = VK_RETURN then BitBtn4.SetFocus;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.Edit3KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
begin
|
||
if Key = VK_RETURN then Edit4.SetFocus;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.Edit4KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
begin
|
||
if Key = VK_RETURN then BitBtn5.SetFocus;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.Edit5KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
begin
|
||
if Key = VK_RETURN then BitBtn5.SetFocus;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.FormCreate(Sender: TObject);
|
||
var
|
||
i, stInt, enInt: Integer;
|
||
hStr: string;
|
||
begin
|
||
FqryList := nil;
|
||
FtmpList := TList.Create;
|
||
|
||
AddrList := TStringList.Create;
|
||
//556 <20><><EFBFBD><EFBFBD> <20>µ<EFBFBD>.. 124 <20><><EFBFBD><EFBFBD> <20>µ<EFBFBD>..
|
||
//AddrList.Add('%MW556');
|
||
//AddrList.Add('%MW124');
|
||
|
||
//for i := 100 to 150 do AddrList.Add('%MW' + IntToStr(i));
|
||
hStr := Trim(ComboBox1.Text);
|
||
stInt := StrToIntDef(Trim(Edit3.Text),0);
|
||
enInt := StrToIntDef(Trim(Edit4.Text),100);
|
||
for i := stInt to enInt do AddrList.Add(hStr + IntToStr(i));
|
||
|
||
AddrIndex := 0;
|
||
plcIdx := 0;
|
||
runLog := False;
|
||
rowIdx := 0;
|
||
|
||
ClientSocket1.ClientType := ctBlocking;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.FormDestroy(Sender: TObject);
|
||
begin
|
||
if FqryList <> nil then xFreeAll(FqryList);
|
||
if FtmpList <> nil then xFreeAllFtmpList;
|
||
|
||
ClientSocket1.Close;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.FormKeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
begin
|
||
if Key = VK_Escape then begin
|
||
if not Timer1.Enabled then begin
|
||
if not ClientSocket1.Active then ClientSocket1.Close;
|
||
BitBtn2.OnClick(Sender);
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.FormShow(Sender: TObject);
|
||
begin
|
||
PageControl1.ActivePageIndex := 0;
|
||
xSetGridInit(StringGrid1);
|
||
xSetGridColumns;
|
||
Memo1.Lines.Clear;
|
||
Memo2.Lines.Clear;
|
||
Memo3.Lines.Clear;
|
||
Memo4.Lines.Clear;
|
||
xSetDatabase;
|
||
xSetPlcSections;
|
||
xSetPlcInfoSetting(ComboBox2.Text);
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.LabeledEdit10KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
begin
|
||
if Key = VK_RETURN then BitBtn9.SetFocus;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.LabeledEdit1KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
begin
|
||
if Key = VK_RETURN then LabeledEdit2.SetFocus;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.LabeledEdit2KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
begin
|
||
if Key = VK_RETURN then BitBtn1.SetFocus;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.LabeledEdit3KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
begin
|
||
if Key = VK_RETURN then LabeledEdit4.SetFocus;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.LabeledEdit4KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
begin
|
||
if Key = VK_RETURN then LabeledEdit1.SetFocus;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.LabeledEdit6KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
begin
|
||
if Key = VK_RETURN then LabeledEdit7.SetFocus;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.LabeledEdit7KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
begin
|
||
if Key = VK_RETURN then LabeledEdit8.SetFocus;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.LabeledEdit8KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
begin
|
||
if Key = VK_RETURN then LabeledEdit9.SetFocus;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.LabeledEdit9KeyDown(Sender: TObject; var Key: Word;
|
||
Shift: TShiftState);
|
||
begin
|
||
if Key = VK_RETURN then LabeledEdit10.SetFocus;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.N1Click(Sender: TObject);
|
||
var
|
||
insertOk: Boolean;
|
||
plcAddr, sqlStr: string;
|
||
curPlc: Tplc_addr_info;
|
||
tmpData: Tplc_tmp_data;
|
||
tmpForm: TfrmPlcAddressEdit;
|
||
begin
|
||
if not FDConnection1.Connected then begin
|
||
showMessage('<27>켱 "DB <20><><EFBFBD><EFBFBD>" <20><>ư<EFBFBD><C6B0> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA>̽<EFBFBD><CCBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ּ<EFBFBD><D6BC><EFBFBD>!!');
|
||
Exit;
|
||
end;
|
||
if Length(Trim(StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row])) = 0 then Exit;
|
||
plcAddr := StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row];
|
||
curPlc := nil;
|
||
|
||
tmpForm := TfrmPlcAddressEdit.Create(Self);
|
||
tmpForm.Tag := 0;
|
||
tmpForm.PlcAddr := plcAddr;
|
||
if tmpForm.ShowModal = mrOk then begin
|
||
curPlc := TmpForm.objPlc;
|
||
//get insert sql str..
|
||
sqlStr := xWriteInsertSql(curPlc);
|
||
//sql <20><><EFBFBD><EFBFBD>..
|
||
insertOk := xDatabaseExecSQL(sqlStr);
|
||
end;
|
||
//plc_addr_info <20>˻<EFBFBD><CBBB>ؼ<EFBFBD> TabSheet2.StringGrid2 <20><> ǥ<><C7A5>..
|
||
if insertOk then xPlcAddrInfoView;
|
||
|
||
// xwins <20><EFBFBD>Ʈ<EFBFBD><C6AE>..
|
||
// curPlc.PreValue := IntToStr(Random(1000));
|
||
// tmpData := xSavePlcTmpData(curPlc);
|
||
// if tmpData <> nil then begin
|
||
// if CheckBox1.Checked then begin
|
||
// FtmpList.Add(tmpData);
|
||
// xShowPlcTmpData;
|
||
// end;
|
||
// end;
|
||
if curPlc <> nil then curPlc.Free;
|
||
tmpForm.Free;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.ParseAndDisplayData(const Raw: TBytes;
|
||
const Addr: string);
|
||
var
|
||
i, col, row, cidx: Integer;
|
||
value: Word;
|
||
binStr, hexStr: string;
|
||
tmpPlc: Tplc_addr_info;
|
||
tmpData: Tplc_tmp_data;
|
||
begin
|
||
value := Raw[32] + (Raw[33] shl 8);
|
||
hexStr := IntToHex(value, 4);
|
||
binStr := '';
|
||
//for i := 15 downto 0 do binStr := binStr + IfThen((value and (1 shl i)) <> 0, '1', '0');
|
||
for i := 0 to 15 do binStr := binStr + IfThen((value and (1 shl i)) <> 0, '1', '0');
|
||
|
||
// Memo1: HEX
|
||
Memo1.Lines.Add(Addr + ' = ' + hexStr);
|
||
|
||
// Memo2: Binary
|
||
//Memo2.Lines.Add(Addr + ' = ' + binStr);
|
||
Memo2.Lines.Add(Addr + ' = ' + binStr + ' / ' + IntToStr(value) + ' / ' + hexStr);
|
||
|
||
col := AddrIndex div 20;
|
||
row := AddrIndex mod 20;
|
||
StringGrid1.Cells[col+1,row+1] := Addr + '=' + IntToStr(value);
|
||
|
||
// Memo3: Bit <20><><EFBFBD><EFBFBD>
|
||
Memo3.Lines.Add(Addr + ' <20><>Ʈ <20><><EFBFBD><EFBFBD>:');
|
||
for i := 15 downto 0 do Memo3.Lines.Add(' [' + IntToStr(15 - i) + '] = ' + IfThen((value and (1 shl i)) <> 0, 'ON', 'OFF'));
|
||
|
||
if Memo1.Lines.Count > 10000 then Memo1.Lines.Clear;
|
||
if Memo2.Lines.Count > 10000 then Memo2.Lines.Clear;
|
||
if Memo3.Lines.Count > 10000 then Memo3.Lines.Clear;
|
||
if runLog then begin
|
||
//<2F><>ü <20>Ҵ<EFBFBD>..
|
||
for i := 0 to FqryList.Count-1 do begin
|
||
tmpPlc := Tplc_addr_info(FqryList.Items[i]);
|
||
if SameText(Addr,tmpPlc.Address) then begin
|
||
if Length(Trim(tmpPlc.PreValue)) = 0 then begin
|
||
tmpPlc.PreValue := IntToStr(value);
|
||
end else begin
|
||
if not SameText(tmpPlc.PreValue, IntToStr(value)) then begin
|
||
tmpPlc.PreValue := IntToStr(value);
|
||
//DB <20><><EFBFBD><EFBFBD>..
|
||
tmpData := xSavePlcTmpData(tmpPlc);
|
||
if tmpData <> nil then begin
|
||
if CheckBox1.Checked then begin
|
||
FtmpList.Add(tmpData);
|
||
xShowPlcTmpData;
|
||
end;
|
||
end;
|
||
Break;
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
//ȭ<><C8AD> view..
|
||
Memo4.Lines.Add(Addr + '=' + IntToStr(value));
|
||
if Memo4.Lines.Count > 10000 then Memo4.Lines.Clear;
|
||
if CheckBox1.Checked then begin
|
||
Inc(rowIdx);
|
||
cidx := StringGrid3.Rows[0].IndexOf('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
|
||
StringGrid3.Cells[cidx,rowIdx] := FormatDateTime('yyyy-MM-dd',Now);
|
||
cidx := StringGrid3.Rows[0].IndexOf('<27><><EFBFBD><EFBFBD><EFBFBD>ð<EFBFBD>');
|
||
StringGrid3.Cells[cidx,rowIdx] := FormatDateTime('HH:nn:ss',Now);
|
||
cidx := StringGrid3.Rows[0].IndexOf('<27>ּ<EFBFBD>');
|
||
StringGrid3.Cells[cidx,rowIdx] := Addr;
|
||
cidx := StringGrid3.Rows[0].IndexOf('<27><>');
|
||
StringGrid3.Cells[cidx,rowIdx] := IntToStr(value);
|
||
if StringGrid3.RowCount > 1000 then begin
|
||
xSetGridInit(StringGrid3);
|
||
StringGrid3.RowCount := 2;
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.SpeedButton1Click(Sender: TObject);
|
||
var
|
||
stInt, enInt, refInt: Integer;
|
||
begin
|
||
refInt := 64;
|
||
stInt := StrToIntDef(Edit3.Text,100);
|
||
stInt := stInt - refInt;
|
||
enInt := stInt + refInt;
|
||
Edit3.Text := IntToStr(stInt);
|
||
Edit4.Text := IntToStr(enInt);
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.SpeedButton2Click(Sender: TObject);
|
||
var
|
||
stInt, enInt, refInt: Integer;
|
||
begin
|
||
refInt := 64;
|
||
stInt := StrToIntDef(Edit3.Text,100);
|
||
stInt := stInt + refInt;
|
||
enInt := stInt + refInt;
|
||
Edit3.Text := IntToStr(stInt);
|
||
Edit4.Text := IntToStr(enInt);
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.StringGrid1Click(Sender: TObject);
|
||
var
|
||
ran: Integer;
|
||
ranStr: string;
|
||
begin
|
||
// xwins <20><EFBFBD>Ʈ<EFBFBD><C6AE>..
|
||
// ran := Random(999);
|
||
// ranStr := '%MW' + IntToStr(ran);
|
||
// StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row] := ranStr;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.Timer1Timer(Sender: TObject);
|
||
var
|
||
Addr: string;
|
||
Sent, Recv: Integer;
|
||
BufCopy: TBytes; // <-- <20>߿<EFBFBD>: <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ <20>迭 <20><><EFBFBD><EFBFBD>
|
||
begin
|
||
Timer1.Enabled := False;
|
||
if not ClientSocket1.Active then Exit;
|
||
|
||
Addr := AddrList[AddrIndex];
|
||
BuildReadPacket2(Addr);
|
||
|
||
Sent := ClientSocket1.Socket.SendBuf(TxBuf, 36);
|
||
if Sent <> 36 then Exit;
|
||
|
||
Recv := ClientSocket1.Socket.ReceiveBuf(RxBuf, 34);
|
||
// if Recv < 34 then Exit;
|
||
if Recv < 34 then begin
|
||
Memo1.Lines.Add(Addr + ' <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>');
|
||
Exit;
|
||
end;
|
||
|
||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>κ<EFBFBD>: Copy <20><><EFBFBD><EFBFBD> Move <20><><EFBFBD><EFBFBD>
|
||
SetLength(BufCopy, Recv);
|
||
Move(RxBuf[0], BufCopy[0], Recv);
|
||
|
||
// Parse <20>Լ<EFBFBD> ȣ<><C8A3>
|
||
ParseAndDisplayData(BufCopy, Addr);
|
||
|
||
Inc(AddrIndex);
|
||
//if AddrIndex >= AddrList.Count then AddrIndex := 0;
|
||
if AddrIndex >= AddrList.Count then begin
|
||
AddrIndex := 0;
|
||
Memo2.Lines.Add('--END--');
|
||
Exit;
|
||
end;
|
||
Timer1.Enabled := True;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.Timer2Timer(Sender: TObject);
|
||
var
|
||
Addr: string;
|
||
Sent, Recv: Integer;
|
||
BufCopy: TBytes; // <-- <20>߿<EFBFBD>: <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ <20>迭 <20><><EFBFBD><EFBFBD>
|
||
tmpPlc: Tplc_addr_info;
|
||
begin
|
||
//FqryList
|
||
Timer2.Enabled := False;
|
||
if not ClientSocket1.Active then Exit;
|
||
|
||
if plcIdx > FqryList.Count-1 then plcIdx := 0;
|
||
tmpPlc := Tplc_addr_info(FqryList.Items[plcIdx]);
|
||
|
||
Addr := tmpPlc.Address;
|
||
BuildReadPacket2(Addr);
|
||
|
||
Sent := ClientSocket1.Socket.SendBuf(TxBuf, 36);
|
||
if Sent <> 36 then Exit;
|
||
|
||
Recv := ClientSocket1.Socket.ReceiveBuf(RxBuf, 34);
|
||
// if Recv < 34 then Exit;
|
||
if Recv < 34 then begin
|
||
Memo1.Lines.Add(Addr + ' <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>');
|
||
Exit;
|
||
end;
|
||
|
||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>κ<EFBFBD>: Copy <20><><EFBFBD><EFBFBD> Move <20><><EFBFBD><EFBFBD>
|
||
SetLength(BufCopy, Recv);
|
||
Move(RxBuf[0], BufCopy[0], Recv);
|
||
|
||
// Parse <20>Լ<EFBFBD> ȣ<><C8A3>..<2E>м<EFBFBD> <20><> <20><><EFBFBD><EFBFBD>..
|
||
ParseAndDisplayData(BufCopy, Addr);
|
||
|
||
if runLog then begin
|
||
Inc(plcIdx);
|
||
Timer2.Enabled := True;
|
||
end;
|
||
end;
|
||
|
||
function TfrmLsPlcMain.xAddSqlMark(velStr: String): string;
|
||
begin
|
||
Result := '';
|
||
Result := '''' + velStr + '''';
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.xAutoResizeStringGridColumns(Grid: TStringGrid;
|
||
Canvas: TCanvas);
|
||
var
|
||
Col, Row: Integer;
|
||
MaxWidth: Integer;
|
||
CellText: string;
|
||
begin
|
||
for Col := 0 to Grid.ColCount - 1 do begin
|
||
MaxWidth := 0;
|
||
for Row := 0 to Grid.RowCount - 1 do begin
|
||
CellText := Grid.Cells[Col, Row];
|
||
MaxWidth := Max(MaxWidth, Canvas.TextWidth(CellText));
|
||
end;
|
||
Grid.ColWidths[Col] := MaxWidth + 10;
|
||
end;
|
||
end;
|
||
|
||
function TfrmLsPlcMain.xDatabaseExecSQL(sqlStr: string): Boolean;
|
||
var
|
||
errStr: string;
|
||
begin
|
||
Result := False;
|
||
if not FDConnection1.Connected then begin
|
||
showMessage('Not Connect!! Insert');
|
||
Exit;
|
||
end;
|
||
try
|
||
FDQuery1.SQL.Text := sqlStr;
|
||
if Pos('UPDATE',sqlStr) > 0 then errStr := 'Update Error'
|
||
else if Pos('INSERT',sqlStr) > 0 then errStr := 'Insert Into Error'
|
||
else errStr := 'ExecSQL Error';
|
||
|
||
FDQuery1.ExecSQL;
|
||
Result := True;
|
||
except
|
||
on E: Exception do begin
|
||
showMessage(errStr);
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.xFreeAll(tmpList: TList);
|
||
var
|
||
i: Integer;
|
||
tmpPlc: Tplc_addr_info;
|
||
begin
|
||
i := 0;
|
||
while i < tmpList.Count do begin
|
||
tmpPlc := Tplc_addr_info(tmpList.Items[0]);
|
||
tmpPlc.Free;
|
||
tmpList.Delete(0);
|
||
end;
|
||
tmpList.Free; tmpList:=nil;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.xFreeAllFtmpList;
|
||
var
|
||
i: Integer;
|
||
tmpData: Tplc_tmp_data;
|
||
begin
|
||
i := 0;
|
||
while i < FtmpList.Count do begin
|
||
tmpData := Tplc_tmp_data(FtmpList.Items[0]);
|
||
tmpData.Free;
|
||
FtmpList.Delete(0);
|
||
end;
|
||
FtmpList.Free; FtmpList:=nil;
|
||
end;
|
||
|
||
function TfrmLsPlcMain.xGetAllAttrNames(out valStrs: TStrings;
|
||
newObj: TObject): TStrings;
|
||
var
|
||
i, Count, cnt : integer;
|
||
sStr: string;
|
||
PropList: PPropList;
|
||
PropInfo: PPropInfo;
|
||
begin
|
||
Result := TStringList.Create;
|
||
valStrs := TStringList.Create;
|
||
//Ŭ<><C5AC><EFBFBD><EFBFBD> <20>Ӽ<EFBFBD><D3BC><EFBFBD> <20><><EFBFBD><EFBFBD> <20>и<EFBFBD><D0B8><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD>..
|
||
cnt := GetPropList(newObj,PropList);
|
||
for i := 0 to cnt-1 do begin
|
||
//Idx <20>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>..
|
||
if SameText(PropList[i].Name, 'Idx') then Continue;
|
||
//<2F>Ӽ<EFBFBD>..
|
||
Result.Add(PropList[i].Name);
|
||
//<2F><>..
|
||
valStrs.Add(GetPropValue(newObj,PropList[i].Name,True));
|
||
end;
|
||
FreeMem(PropList);
|
||
end;
|
||
|
||
function TfrmLsPlcMain.xGetObjPlcAddrInfo: TList;
|
||
var
|
||
curPlc: Tplc_addr_info;
|
||
begin
|
||
Result := TList.Create;
|
||
while not FDQuery1.Eof do begin
|
||
curPlc := Tplc_addr_info.Create;
|
||
curPlc.MachNum := FDQuery1.FieldByName('MachNum').AsString;
|
||
curPlc.MachName := FDQuery1.FieldByName('MachName').AsString;
|
||
curPlc.Kind := FDQuery1.FieldByName('Kind').AsString;
|
||
curPlc.Name := FDQuery1.FieldByName('Name').AsString;
|
||
curPlc.Address := FDQuery1.FieldByName('Address').AsString;
|
||
curPlc.Descriptions := FDQuery1.FieldByName('Descriptions').AsString;
|
||
curPlc.Idx := IntToStr(FDQuery1.FieldByName('Idx').AsInteger);
|
||
curPlc.IsValid := FDQuery1.FieldByName('IsValid').AsString;
|
||
|
||
Result.Add(curPlc);
|
||
|
||
FDQuery1.Next;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.xPlcAddrInfoView;
|
||
var
|
||
sql: string;
|
||
begin
|
||
sql := 'SELECT * FROM plc_addr_info'
|
||
+ ' WHERE Kind=' + xAddSqlMark(ComboBox2.Text)
|
||
+ ' AND IsValid=' + xAddSqlMark('1')
|
||
+ ';';
|
||
try
|
||
FDQuery1.Close;
|
||
FDQuery1.SQL.Text := sql;
|
||
FDQuery1.Open;
|
||
except
|
||
on E: Exception do ShowMessage('<27><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>: ' + E.Message);
|
||
end;
|
||
if FqryList <> nil then xFreeAll(FqryList);
|
||
//plc <20><>ü <20><><EFBFBD>ƿ<EFBFBD><C6BF><EFBFBD>..
|
||
FqryList := xGetObjPlcAddrInfo;
|
||
//StringGrid <20>ʱ<EFBFBD>ȭ..
|
||
xStringGridInit(StringGrid2);
|
||
//StringGrid2 <20><><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>..
|
||
xShowPlcAddrInfo(FqryList);
|
||
//Cells ĭ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>..
|
||
//xAutoResizeStringGridColumns(StringGrid2, Canvas);
|
||
end;
|
||
|
||
function TfrmLsPlcMain.xSavePlcTmpData(tmpPlc: Tplc_addr_info): Tplc_tmp_data;
|
||
var
|
||
sqlStr: string;
|
||
begin
|
||
Result := Tplc_tmp_data.Create;
|
||
Result.Kind := tmpPlc.Kind;
|
||
Result.CreateDate := FormatDateTime('yyyy-MM-dd',Now);
|
||
Result.CreateTime := FormatDateTime('HH:nn:ss',Now);
|
||
Result.TM := tmpPlc.PreValue;
|
||
Result.Address := tmpPlc.Address;
|
||
//get insert sql str..
|
||
sqlStr := xWriteInsertSqlToTmpData(Result);
|
||
//sql <20><><EFBFBD><EFBFBD>..
|
||
xDatabaseExecSQL(sqlStr);
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.xSetDatabase;
|
||
var
|
||
Ini: TIniFile;
|
||
IniPath: string;
|
||
begin
|
||
// ini <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> (<28><>: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϰ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>)
|
||
IniPath := ExtractFilePath(ParamStr(0)) + 'db_config.ini';
|
||
|
||
// ini <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ٸ<EFBFBD> <20>⺻<EFBFBD><E2BABB>..
|
||
if not FileExists(IniPath) then begin
|
||
LabeledEdit6.Text := 'neol_db';
|
||
LabeledEdit7.Text := 'qsentech';
|
||
LabeledEdit8.Text := 'qsentech!1233';
|
||
LabeledEdit9.Text := 'qst-s.iptime.org';
|
||
LabeledEdit10.Text := '33063';
|
||
end else begin
|
||
Ini := TIniFile.Create(IniPath);
|
||
try
|
||
LabeledEdit6.Text := Ini.ReadString('Database', 'DBName', '');
|
||
LabeledEdit7.Text := Ini.ReadString('Database', 'User', '');
|
||
LabeledEdit8.Text := Ini.ReadString('Database', 'Password', '');
|
||
LabeledEdit9.Text := Ini.ReadString('Database', 'Server', '');
|
||
LabeledEdit10.Text := Ini.ReadString('Database', 'Port', '');
|
||
finally
|
||
Ini.Free;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.xSetGridColumns;
|
||
var
|
||
i: Integer;
|
||
colStrs: TStrings;
|
||
begin
|
||
colStrs := TStringList.Create;
|
||
colStrs.Add('###');
|
||
colStrs.Add('#1'); colStrs.Add('#2'); colStrs.Add('#3');
|
||
colStrs.Add('#4'); colStrs.Add('#5'); colStrs.Add('#6');
|
||
colStrs.Add('#7'); colStrs.Add('#8'); colStrs.Add('#9'); colStrs.Add('#10');
|
||
for i := 0 to StringGrid1.ColCount-1 do StringGrid1.Cells[i,0] := colStrs.Strings[i];
|
||
for i := StringGrid1.FixedRows to StringGrid1.RowCount-1 do StringGrid1.Cells[0,i] := ComboBox1.Text;
|
||
colStrs.Clear;
|
||
|
||
colStrs.Add('<27><>Ī'); colStrs.Add('Address'); colStrs.Add('<27><><EFBFBD><EFBFBD>');
|
||
StringGrid2.Rows[0].AddStrings(colStrs);
|
||
colStrs.Clear;
|
||
|
||
colStrs.Add('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'); colStrs.Add('<27><><EFBFBD><EFBFBD><EFBFBD>ð<EFBFBD>'); colStrs.Add('<27>ּ<EFBFBD>'); colStrs.Add('<27><>');
|
||
StringGrid3.Rows[0].AddStrings(colStrs);
|
||
|
||
colStrs.Free;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.xSetGridInit(grid: TStringGrid);
|
||
var
|
||
i, j: Integer;
|
||
begin
|
||
for i := 0 to grid.RowCount-1 do begin
|
||
for j := 0 to grid.ColCount-1 do begin
|
||
grid.Objects[j,i] := nil;
|
||
grid.Cells[j,i] := '';
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.xSetPlcSections;
|
||
var
|
||
i: Integer;
|
||
IniPath: string;
|
||
Sections: TStringList;
|
||
Ini: TIniFile;
|
||
begin
|
||
IniPath := ExtractFilePath(ParamStr(0)) + 'plc_config.ini';
|
||
if FileExists(IniPath) then begin
|
||
ComboBox2.Items.Clear;
|
||
|
||
Sections := TStringList.Create;
|
||
Ini := TIniFile.Create(IniPath);
|
||
try
|
||
Ini.ReadSections(Sections);
|
||
for i := 0 to Sections.Count - 1 do begin
|
||
if ComboBox2.Items.IndexOf(Sections[i]) = -1 then begin
|
||
ComboBox2.Items.Add(Sections[i]);
|
||
end;
|
||
end;
|
||
finally
|
||
Ini.Free;
|
||
Sections.Free;
|
||
end;
|
||
if ComboBox2.Items.Count > 0 then ComboBox2.ItemIndex := 0;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.xShowPlcAddrInfo(FqryList: TList);
|
||
var
|
||
i, cidx, ridx: Integer;
|
||
tmpPlc: Tplc_addr_info;
|
||
begin
|
||
ridx := 0;
|
||
StringGrid2.RowCount := FqryList.Count+1;
|
||
for i := 0 to FqryList.Count-1 do begin
|
||
tmpPlc := Tplc_addr_info(FqryList.Items[i]);
|
||
Inc(ridx);
|
||
cidx := StringGrid2.Rows[0].IndexOf('<27><>Ī');
|
||
StringGrid2.Objects[cidx,ridx] := tmpPlc;
|
||
StringGrid2.Cells[cidx,ridx] := tmpPlc.Name;
|
||
cidx := StringGrid2.Rows[0].IndexOf('Address');
|
||
StringGrid2.Cells[cidx,ridx] := tmpPlc.Address;
|
||
cidx := StringGrid2.Rows[0].IndexOf('<27><><EFBFBD><EFBFBD>');
|
||
StringGrid2.Cells[cidx,ridx] := tmpPlc.Descriptions;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.xShowPlcTmpData;
|
||
var
|
||
i, cidx, ridx: Integer;
|
||
tmpData: Tplc_tmp_data;
|
||
begin
|
||
StringGrid3.RowCount := FtmpList.Count+1;
|
||
tmpData := Tplc_tmp_data(FtmpList.Items[FtmpList.Count-1]);
|
||
ridx := StringGrid3.RowCount-1;
|
||
cidx := StringGrid3.Rows[0].IndexOf('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
|
||
StringGrid3.Cells[cidx,ridx] := tmpData.CreateDate;
|
||
cidx := StringGrid3.Rows[0].IndexOf('<27><><EFBFBD><EFBFBD><EFBFBD>ð<EFBFBD>');
|
||
StringGrid3.Cells[cidx,ridx] := tmpData.CreateTime;
|
||
cidx := StringGrid3.Rows[0].IndexOf('<27>ּ<EFBFBD>');
|
||
StringGrid3.Cells[cidx,ridx] := tmpData.Address;
|
||
cidx := StringGrid3.Rows[0].IndexOf('<27><>');
|
||
StringGrid3.Cells[cidx,ridx] := tmpData.TM;
|
||
StringGrid3.Row := ridx;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.xStringGridInit(grid: TStringGrid);
|
||
var
|
||
i, j: Integer;
|
||
begin
|
||
for i := grid.FixedRows to grid.RowCount-1 do begin
|
||
for j := 0 to grid.ColCount-1 do begin
|
||
grid.Objects[j,i] := nil;
|
||
grid.Cells[j,i] := '';
|
||
end;
|
||
end;
|
||
grid.RowCount := 2;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.xUpdtePlcConfig;
|
||
var
|
||
Ini: TIniFile;
|
||
IniPath, sectionName: string;
|
||
begin
|
||
IniPath := ExtractFilePath(ParamStr(0)) + 'plc_config.ini';
|
||
sectionName := ComboBox2.Text;
|
||
|
||
Ini := TIniFile.Create(IniPath);
|
||
try
|
||
Ini.WriteString(sectionName, 'MachName', LabeledEdit3.Text);
|
||
Ini.WriteString(sectionName, 'MachNum', LabeledEdit4.Text);
|
||
Ini.WriteString(sectionName, 'IP', LabeledEdit1.Text);
|
||
Ini.WriteString(sectionName, 'Port', LabeledEdit2.Text);
|
||
finally
|
||
Ini.Free;
|
||
end;
|
||
end;
|
||
|
||
function TfrmLsPlcMain.xWriteInsertSql(curPlc: Tplc_addr_info): string;
|
||
var
|
||
i: Integer;
|
||
sqlStr, attrStr, valStr, clsName: string;
|
||
attrStrs, valStrs: TStrings;
|
||
begin
|
||
Result := '';
|
||
sqlStr := '';
|
||
sqlStr := 'INSERT INTO plc_addr_info ';
|
||
//Ŭ<><C5AC><EFBFBD><EFBFBD> <20>Ӽ<EFBFBD><D3BC><EFBFBD> <20><><EFBFBD><EFBFBD> <20>и<EFBFBD><D0B8><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD>..
|
||
attrStrs := xGetAllAttrNames(valStrs, curPlc);
|
||
attrStr := '';
|
||
for i := 0 to attrStrs.Count-1 do begin
|
||
if i = 0 then attrStr := ' (' + attrStrs.Strings[i]
|
||
else attrStr := attrStr + ', ' + attrStrs.Strings[i];
|
||
end;
|
||
attrStr := attrStr + ') ';
|
||
sqlStr := sqlStr + attrStr;
|
||
valStr := '';
|
||
for i := 0 to valStrs.Count-1 do begin
|
||
//<2F><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ǥ <20><><EFBFBD>̱<EFBFBD>..
|
||
if i = 0 then valStr := 'VALUES (' + xAddSqlMark(valStrs.Strings[i])
|
||
else valStr := valStr + ', ' + xAddSqlMark(valStrs.Strings[i]);
|
||
end;
|
||
sqlStr := sqlStr + valStr;
|
||
sqlStr := sqlStr + ')';
|
||
sqlStr := sqlStr + ';';
|
||
Result := sqlStr;
|
||
attrStrs.Free;
|
||
valStrs.Free;
|
||
end;
|
||
|
||
function TfrmLsPlcMain.xWriteInsertSqlToTmpData(tmpData: Tplc_tmp_data): string;
|
||
var
|
||
i: Integer;
|
||
sqlStr, attrStr, valStr, clsName: string;
|
||
attrStrs, valStrs: TStrings;
|
||
begin
|
||
Result := '';
|
||
sqlStr := '';
|
||
sqlStr := 'INSERT INTO plc_tmp_data ';
|
||
//Ŭ<><C5AC><EFBFBD><EFBFBD> <20>Ӽ<EFBFBD><D3BC><EFBFBD> <20><><EFBFBD><EFBFBD> <20>и<EFBFBD><D0B8><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD>..
|
||
attrStrs := xGetAllAttrNames(valStrs, tmpData);
|
||
attrStr := '';
|
||
for i := 0 to attrStrs.Count-1 do begin
|
||
if i = 0 then attrStr := ' (' + attrStrs.Strings[i]
|
||
else attrStr := attrStr + ', ' + attrStrs.Strings[i];
|
||
end;
|
||
attrStr := attrStr + ') ';
|
||
sqlStr := sqlStr + attrStr;
|
||
valStr := '';
|
||
for i := 0 to valStrs.Count-1 do begin
|
||
//<2F><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ǥ <20><><EFBFBD>̱<EFBFBD>..
|
||
if i = 0 then valStr := 'VALUES (' + xAddSqlMark(valStrs.Strings[i])
|
||
else valStr := valStr + ', ' + xAddSqlMark(valStrs.Strings[i]);
|
||
end;
|
||
sqlStr := sqlStr + valStr;
|
||
sqlStr := sqlStr + ')';
|
||
sqlStr := sqlStr + ';';
|
||
Result := sqlStr;
|
||
attrStrs.Free;
|
||
valStrs.Free;
|
||
end;
|
||
|
||
function TfrmLsPlcMain.xWriteUpdateSql(tmpPlc: Tplc_addr_info): string;
|
||
var
|
||
i: Integer;
|
||
sqlStr, setStr, clsName: string;
|
||
attrStrs, valStrs: TStrings;
|
||
begin
|
||
Result := '';
|
||
sqlStr := 'UPDATE plc_addr_info SET ';
|
||
attrStrs := TStringList.Create;
|
||
valStrs := TStringList.Create;
|
||
|
||
// Ŭ<><C5AC><EFBFBD><EFBFBD> <20>Ӽ<EFBFBD><D3BC><EFBFBD> <20><><EFBFBD><EFBFBD> <20>и<EFBFBD><D0B8>ؼ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD>.
|
||
attrStrs := xGetAllAttrNames(valStrs, tmpPlc);
|
||
|
||
setStr := '';
|
||
for i := 0 to attrStrs.Count - 1 do begin
|
||
// 'Idx' <20>ʵ<EFBFBD><CAB5><EFBFBD> <20><><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD> <20><><EFBFBD>ǿ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ǹǷ<C7B9>)
|
||
if attrStrs[i] = 'Idx' then Continue;
|
||
|
||
if setStr <> '' then setStr := setStr + ', ';
|
||
setStr := setStr + attrStrs[i] + ' = ' + xAddSqlMark(valStrs[i]);
|
||
end;
|
||
|
||
sqlStr := sqlStr + setStr;
|
||
|
||
// WHERE <20><><EFBFBD><EFBFBD>: Idx<64><78> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
sqlStr := sqlStr + ' WHERE Idx = ' + xAddSqlMark(tmpPlc.Idx);
|
||
|
||
Result := sqlStr;
|
||
|
||
attrStrs.Free;
|
||
valStrs.Free;
|
||
end;
|
||
|
||
procedure TfrmLsPlcMain.xSetPlcInfoSetting(nameStr: string);
|
||
var
|
||
Ini: TIniFile;
|
||
IniPath: string;
|
||
begin
|
||
if Length(Trim(nameStr)) = 0 then Exit;
|
||
IniPath := ExtractFilePath(ParamStr(0)) + 'plc_config.ini';
|
||
|
||
if FileExists(IniPath) then begin
|
||
Ini := TIniFile.Create(IniPath);
|
||
try
|
||
LabeledEdit3.Text := Ini.ReadString(nameStr, 'MachName', '');
|
||
LabeledEdit4.Text := Ini.ReadString(nameStr, 'MachNum', '');
|
||
LabeledEdit1.Text := Ini.ReadString(nameStr, 'IP', '');
|
||
LabeledEdit2.Text := Ini.ReadString(nameStr, 'Port', '');
|
||
finally
|
||
Ini.Free;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
end.
|