//----------------------系统初始化---------------------------
procedure system_init;
var
temp: string;
begin
with mainform do
begin
helpmemo.lines.loadfromfile('help.txt'); // 调入帮助文件
datainit; // 初始化变量
comm_status := false; // 通讯状态初始为停止
smindex := 0;
poll_count := 0;
read_index := 0;
sendflag1 := false;
econfile := Teconfile.init; // 构造ECONFILE对象
getdatafromfile(datamemo, getfilename, econfile);// 调入数据定义中的系统设置
// 根据数据定义文件初始化界面
if econfile.coilstatetotal>0 then displaycoilstate(econfile,coilstategrid);
coilstate.TabVisible := econfile.coilstatetotal>0;
if econfile.inputstatetotal>0 then displayinputstate(econfile,inputstategrid);
inputstate.TabVisible := econfile.inputstatetotal>0;
if econfile.holdregistertotal>0 then displayholdregister(econfile,holdregistergrid);
holdregister.TabVisible := econfile.holdregistertotal>0;
if econfile.inputregistertotal>0 then displayinputregister(econfile,inputregistergrid);
inputregister.TabVisible := econfile.inputregistertotal>0;
if econfile.setprotecttotal>0 then displayprotect(econfile,protectgrid);
protect.TabVisible := econfile.setprotecttotal>0;
if econfile.setpowertotal>0 then displaypower(econfile,powergrid);
power.TabVisible := econfile.setpowertotal>0;
if econfile.setxiangliangtotal>0 then displayxiangliang(econfile,xianglianggrid);
xiangliang.TabVisible := econfile.setxiangliangtotal>0;
if econfile.setxiebototal>0 then displayxiebo(econfile,xiebogrid);
xiebo.TabVisible := econfile.setxiebototal>0;
mainform.pagecon.Visible := true;
statusbar1.Panels[0].Text := '通讯未开始';
temp := econfile.comm.mode;
if (uppercase(temp)='RTU') then modbusrtu1.Checked:=true;
if (uppercase(temp)='ASCII') then modbusascii1.Checked:=true;
case econfile.comm.portnum of
1: com11.Checked := true;
2: com21.Checked := true;
3: com31.checked := true;
4: com41.checked := true;
else com11.checked := true;
end;
case econfile.comm.parity of
0: paritynone.Checked := true;
1: parityodd.Checked := true;
2: parityeven.checked := true;
end;
case econfile.comm.baudrate of
110: b110.Checked := true;
300: b300.Checked := true;
600: b600.Checked := true;
1200: b1200.Checked := true;
2400: b2400.Checked := true;
4800: b4800.Checked := true;
9600: b9600.Checked := true;
14400: b14400.Checked := true;
19200: b19200.Checked := true;
38400: b38400.Checked := true;
56000: b56000.Checked := true;
57600: b57600.Checked := true;
115200: b115200.Checked := true;
128000: b128000.Checked := true;
256000: b256000.Checked := true;
else
begin
buser.Checked := true;
end;
end; // end case econfile.comm.baudrate
m_address.Items[econfile.comm.rtuaddress-1].Checked := true;
// 初始化通讯相关参数
vacomm1.Close;
vacomm1.Baudrate := changbaudrate(econfile.comm.baudrate);
vacomm1.UserBaudrate := econfile.comm.userbaud;
vacomm1.Databits := changdatabits(econfile.comm.databits);
vacomm1.Stopbits := changstopbits(econfile.comm.stopbits);
vacomm1.Parity := changparity(econfile.comm.parity);
vacomm1.PortNum := econfile.comm.portnum;
sendtimer.Enabled := false;
revtimer.Enabled := false;
sendtimer.Interval := 1;
timerout1.Interval := econfile.comm.timeout;
m_comset.Enabled := true;
// readholdregister(econfile);
// readfifo(econfile);
end;//end with mainform do
end;