unit uFrameAutoYLBland; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, uFrameBase, System.ImageList, FMX.ImgList, FMX.ListBox, uksoap, FMX.Controls.Presentation, FMX.Edit, FMX.Objects,uListConent,uShowInfo,uPLCDevice, uTcpDevice; type TFrameAutoYLBland = class(TFrameBase) Rectangle88: TRectangle; Option1: TRectangle; Glyph9: TGlyph; OptionLabel1: TText; Text19: TText; Edit_KuangJi: TEdit; Option2: TRectangle; Glyph2: TGlyph; OptionLabel3: TText; Text6: TText; Edit_ChengShi: TEdit; TxtError: TText; ImageList1: TImageList; Rectangle1: TRectangle; Glyph1: TGlyph; Text1: TText; Text2: TText; Edit1: TEdit; Rectangle2: TRectangle; Glyph3: TGlyph; Text3: TText; Text4: TText; Edit2: TEdit; Rectangle3: TRectangle; Glyph4: TGlyph; Text5: TText; Text7: TText; Edit3: TEdit; PlcDeviceShowState: TLabel; private function DoPlc(): Boolean;override; procedure FPlcMelsecDeviceWork(Sender: TObject; sValue: string); procedure FPlcOmronDeviceWork(Sender: TObject; sValue: string); procedure FPlcDeviceShowState(Sender: TObject; Avalue: string); procedure FPlcDeviceOpen(Sender: TObject; sValue:string); { Private declarations } public FPlcMelsecDevice:array[0..9] of TMelsec; FPlcOmronDevice:array[0..9] of TOmron; procedure FillDefaultValue(sPartnumValue,sDefaultTxt:string);override; //填写默认值 function DoExec():boolean;override; //判断输入是否有效,执行插入主表,或打开窗体 function CheckValid(var sTxt:string):boolean;override; // function GetFixture_Code():string;override; //返回治具ID end; //var // Frame_Plasma: TFrame_Plasma; implementation {$R *.fmx} uses uDM, uBlandPrintConent, uPucFun, uSafeLog; { 285090 D3007585AG } function TFrameAutoYLBland.CheckValid(var sTxt:string):boolean; //返回面次数据 begin Result:= False; if Trim(Edit_KuangJi.Text)='' then begin TxtShowErrorInfo(TxtError,'板厚不能為空'); Exit; end; if Trim(Edit3.Text)='' then begin TxtShowErrorInfo(TxtError,'熱熔溫度不能為空'); Exit; end; if Trim(Edit1.Text)='' then begin TxtShowErrorInfo(TxtError,'熱熔時間不能為空'); Exit; end; if Trim(Edit2.Text)='' then begin TxtShowErrorInfo(TxtError,'冷却時間不能為空'); Exit; end; if Trim(Edit_ChengShi.Text)='' then begin TxtShowErrorInfo(TxtError,'叠片數不能為空'); Exit; end; Result:= True; end; procedure TFrameAutoYLBland.FillDefaultValue(sPartnumValue,sDefaultTxt:string); begin WorkLog.MessageInfo('生产参数sPartnumValue:'+sPartnumValue+',sDefaultTxt:'+sDefaultTxt); with TStringList.Create do try // a:= TStringList.Create; Delimiter:= ','; DelimitedText:= sDefaultTxt; if Count>15 then Edit_KuangJi.Text:=Strings[15]; // 板厚(mm) if Count>20 then Edit3.Text:=Strings[20]; // 熱熔溫度(℃) if Count>22 then Edit1.Text:=Strings[22]; // 熱熔時間(S) if Count>23 then Edit2.Text:=Strings[23]; // 冷却時間(S) if Count>21 then Edit_ChengShi.Text:=Strings[21]; // 叠片數 // if Count>=1 then Edit6.Text:=Strings[0]; // if Count>=2 then Edit5.Text:=Strings[1]; // if Count>=3 then Edit4.Text:=Strings[2]; // if Count>=4 then Edit2.Text:=Strings[3]; // if Count>=5 then Edit9.Text:=Strings[4]; // if Count>=6 then Edit1.Text:=Strings[5]; // if Count>=7 then Edit3.Text:=Strings[6]; // if Count>=8 then Edit_KuangJi.Text:=Strings[7]; // if Count>=9 then Edit_ChengShi.Text:=Strings[8]; // if Count>=10 then Edit7.Text:=Strings[9]; finally Free; end; end; procedure TFrameAutoYLBland.FPlcDeviceShowState(Sender: TObject; Avalue: string); //显示读头状态 begin PlcDeviceShowState.Text:= (Avalue); end; function TFrameAutoYLBland.DoPlc():Boolean; var i: integer; tmpValue:string; sDevName,sIp,sPort:string; begin Result:= True; PlcDeviceShowState.Text:= '1'; //根据配置加载设备 for i := 1 to 3 do begin tmpValue:=dm.MemTableReadKeyValue('plc设备','DevStyle_plc'+i.ToString); if tmpValue<>'' then begin if CheckParameter(tmpValue,sDevName,sIp,sPort) then begin PlcDeviceShowState.Text:= '2'; if sameText(sDevName.ToLower,'melsec') then //三棱plc begin PlcDeviceShowState.Text:= '3'; FPlcMelsecDevice[i]:=TMelsec.Create(sIp,sPort.ToInteger); FPlcMelsecDevice[i].Num:=i; FPlcMelsecDevice[i].OnWork:=FPlcMelsecDeviceWork; FPlcMelsecDevice[i].OnShowState:=FPlcDeviceShowState; FPlcMelsecDevice[i].Connect; FPlcMelsecDevice[i].OnOpen:= FPlcDeviceOpen; // TThread.CreateThreadX( // procedure (Avalue:Integer) // begin // Sleep(1000); // TThread.Synchronize( nil, // procedure // begin // FPlcDevice[Avalue].Open:= FPlcDeviceOpen; // end // ); // end,i // ).Start; end; //D300039100 純膠預粘 if sameText(sDevName.ToLower,'omron') then //欧姆龙plc begin PlcDeviceShowState.Text:= '4'; FPlcOmronDevice[i]:=TOmron.Create(sIp,sPort.ToInteger); FPlcOmronDevice[i].Num:=i; FPlcOmronDevice[i].OnWork:=FPlcOmronDeviceWork; FPlcOmronDevice[i].OnShowState:=FPlcDeviceShowState; FPlcOmronDevice[i].Connect; // FPlcOmronDevice[i].OnOpen:= FPlcDeviceOpen; TThread.CreateThreadX( procedure (Avalue:Integer) begin Sleep(1000); TThread.Synchronize( nil, procedure begin FPlcOmronDevice[Avalue].Open; end ); end,i ).Start; end; end; end; end; end; procedure TFrameAutoYLBland.FPlcDeviceOpen(Sender: TObject; sValue:string); //4C4F4E0d VAR bBtye:array[0..4] of byte; begin // if Sender<>nil then TMelsec(Sender).Open(Sender,sValue); end; procedure TFrameAutoYLBland.FPlcMelsecDeviceWork(Sender:TObject;sValue: string); //读取条码 procedure ReOpen2D(); begin TThread.CreateAnonymousThread( procedure begin Sleep(3000); TThread.Synchronize( nil, procedure begin if Sender<>nil then TMelsec(Sender).Open(Sender,sValue); // TxtBarCodePrompt.Text:='读码中...'; end ); end ).Start; end; begin if sValue='ERROR' then BEGIN // AddLog('plc读取出错'+sValue); WorkLog.MessageInfo('plc读取出错'+sValue); ReOpen2D(); Exit; END; end; procedure TFrameAutoYLBland.FPlcOmronDeviceWork(Sender:TObject;sValue: string); //读取条码 procedure ReOpen2D(); begin TThread.CreateAnonymousThread( procedure begin Sleep(3000); TThread.Synchronize( nil, procedure begin if Sender<>nil then TMelsec(Sender).Open(Sender,sValue); // TxtBarCodePrompt.Text:='读码中...'; end ); end ).Start; end; begin if sValue='ERROR' then BEGIN // AddLog('plc读取出错'+sValue); WorkLog.MessageInfo('plc读取出错'+sValue); ReOpen2D(); Exit; END; end; function TFrameAutoYLBland.DoExec():boolean; var LotNoRecord:TLotNoRecord; vId:Integer; sTxt:string; sError:string; vP_ID:Double; i_SLAB_THICKNESS,i_COM_TEMPERATURE,i_PREHEATING_SEC, i_COMPRESS_SEC, i_PRODUCT_PRESSURE: Double; begin Result:=False; if CheckValid(sTxt) then //上传数据 begin LotNoRecord:=TLotNoRecord.Create('-1'); //初始化记录 LotNoRecord.P_LOT:=ksoap.P_Lot; LotNoRecord.P_Enable:='Y'; LotNoRecord.P_ID:=0; LotNoRecord.P_ORG_CODE:=ksoap.P_ORG_CODE; //廠區 LotNoRecord.P_NUM:=ksoap.P_WORK_NUM; //工號 LotNoRecord.P_PC:=ksoap.P_PC; //製程 LotNoRecord.P_LINE:=ksoap.P_LINE; //線別 LotNoRecord.P_LINE_NUM:=ksoap.P_LINE_NUM; //線別編號 try i_SLAB_THICKNESS:=StrToFloat(Trim(Edit_KuangJi.Text)); //板厚(mm) 31 i_COM_TEMPERATURE:=StrToFloat(Trim(Edit3.Text)); //熱熔溫度(℃) 13 i_PREHEATING_SEC:=StrToFloat(Trim(Edit1.Text)); //熱熔時間(S) 15 i_COMPRESS_SEC:=StrToFloat(Trim(Edit2.Text)); //冷却時間(S) 16 i_PRODUCT_PRESSURE:=StrToFloat(Trim(Edit_ChengShi.Text)); //叠片數 14 except end; LotNoRecord.P_SLAB_THICKNESS:= i_SLAB_THICKNESS; //板厚(mm) 31 LotNoRecord.P_COM_TEMPERATURE:= i_COM_TEMPERATURE; //熱熔溫度(℃) 13 LotNoRecord.P_PREHEATING_SEC:= i_PREHEATING_SEC; //熱熔時間(S) 15 LotNoRecord.P_COMPRESS_SEC:= i_COMPRESS_SEC; //冷却時間(S) 16 LotNoRecord.P_PRODUCT_PRESSURE:= i_PRODUCT_PRESSURE; //叠片數 14 LotNoRecord.P_CREATION_DATE:=FormatDateTime('yyyymmdd hh:mm:ss',Now); sError:=''; vP_ID:=Ksoap.Thread_cf_traceability_seq_f(ksoap.P_ORG_CODE,sError); LotNoRecord.P_ID:=vP_ID; if vP_ID=0 then BEGIN dm.InsertMain(vId,LotNoRecord,false); Result:=true; END ELSE BEGIN //直接调用API,出错再保存本地 if not Ksoap.Thread_Insert_CM_WIP_PROCESS_LINE_HISTORY_NEW(LotNoRecord,sError) then //提交主表不成功 begin if sError='連接數據庫服務器失败' then begin dm.InsertMain(vId,LotNoRecord,false); Result:=true; end else ShowError(sError); end else begin dm.InsertMain(vId,LotNoRecord,false); dm.UpdateMainId(vId,vP_ID.ToString,True); Result:=true; end; END; end; //打开窗体 if Result then begin // WorkLog.MessageInfo('frmBlandPrinterConent'); frmBlandPrinterConent:=TfrmBlandPrinterConent.Create(nil); try frmBlandPrinterConent.LotNoRecord:=LotNoRecord; //记录 frmBlandPrinterConent.vP_ID:=LotNoRecord.P_ID; //ID號,需與主檔的ID號相同 frmBlandPrinterConent.vId:=vId; //本地表记录ID // frmListConent.Text6.Text:='更改烤架編號'; frmBlandPrinterConent.ShowModal; finally frmBlandPrinterConent.Free; end; end; end; end.