unit loadsave;
{Einstellungen laden und speichern}
interface
uses SMSH, SMSP, WinProcs, WinTypes;
procedure LoadSet(Section:PChar);
procedure SaveRange(Section:PChar);
procedure SaveSet(Section:PChar);
implementation
procedure GetProfileByte(Section,Key:PChar; var B:Byte);
begin
B:=Byte(GetPrivateProfileInt(Section,Key,B,Profile));
end;
procedure GetProfileWord(Section,Key:PChar; var W:Word);
begin
W:=GetPrivateProfileInt(Section,Key,Integer(W),Profile);
end;
procedure GetProfileReal(Section,Key:PChar; var Z:TReal);
var
S:TS31;
ZH: TReal;
begin
Real2S(Z,3,S);
GetPrivateProfileString(Section,Key,S,S,sizeof(S),Profile);
if S2Real(S,ZH) then Z:=ZH;
end;
procedure LoadSet(Section:PChar);
begin
with AMotor do begin
GetProfileByte(Section,'CFlags',CFlags);
GetProfileWord(Section,'PortHWE',PortHWE);
GetProfileWord(Section,'RefW',RefW);
GetProfileWord(Section,'EndW',EndW);
GetProfileWord(Section,'PortEAB',PortEAB);
GetProfileWord(Section,'OnW',OnW);
GetProfileWord(Section,'BrakeW',BrakeW);
GetProfileWord(Section,'PortA',PortA);
GetProfileWord(Section,'PortB',PortB);
end;
with MotorR do begin
GetProfileReal(Section,'MaxSpeed',MaxSpeed);
GetProfileReal(Section,'RefSpeed',RefSpeed);
GetProfileReal(Section,'MaxAccel',MaxAccel);
GetProfileReal(Section,'Refpoint',Refpoint);
GetProfileReal(Section,'LeftBound',LeftBound);
GetProfileReal(Section,'RightBound',RightBound);
GetProfileReal(Section,'StepsPerUnit',StepsPerUnit);
GetProfileReal(Section,'FastRefOfs',FastRefOfs);
GetPrivateProfileString(Section,'UnitName',
UnitName,UnitName,sizeof(UnitName),Profile);
end;
SetMotorStruc;
with Range do begin
GetProfileReal(Section,'Range.From',From);
GetProfileReal(Section,'Range.ToPos',ToPos);
GetProfileReal(Section,'Range.Step',Step);
GetProfileWord(Section,'Range.Wait',Wait);
GetProfileByte(Section,'Range.StepCheck',Byte(StepCheck));
GetProfileByte(Section,'Range.WaitCheck',Byte(WaitCheck));
end;
end;
{------------------------------}
procedure WriteProfileWord(Section,Key:PChar; W:Word);
var
S: TS31;
begin
wvsprintf(S,'%u',W);
WritePrivateProfileString(Section,Key,S,Profile);
end;
procedure WriteProfileHexWord(Section,Key:PChar; W:Word);
var
S: TS31;
begin
wvsprintf(S,'0x%X',W);
WritePrivateProfileString(Section,Key,S,Profile);
end;
procedure WriteProfileReal(Section,Key:PChar; const Z:TReal);
var
S: TS31;
begin
Real2S(Z,3,S);
WritePrivateProfileString(Section,Key,S,Profile);
end;
procedure SaveMotorR(Section:PChar);
begin
with MotorR do begin
WriteProfileReal(Section,'MaxSpeed',MaxSpeed);
WriteProfileReal(Section,'RefSpeed',RefSpeed);
WriteProfileReal(Section,'MaxAccel',MaxAccel);
WriteProfileReal(Section,'Refpoint',Refpoint);
WriteProfileReal(Section,'LeftBound',LeftBound);
WriteProfileReal(Section,'RightBound',RightBound);
WriteProfileReal(Section,'StepsPerUnit',StepsPerUnit);
WriteProfileReal(Section,'FastRefOfs',FastRefOfs);
WritePrivateProfileString(Section,'UnitName',UnitName,Profile);
end;
end;
procedure SaveRange(Section:PChar);
{Der (neue) Bereich darf ohne Authorisierung gespeichert werden}
begin
with Range do begin
WriteProfileReal(Section,'Range.From',From);
WriteProfileReal(Section,'Range.ToPos',ToPos);
WriteProfileReal(Section,'Range.Step',Step);
WriteProfileWord(Section,'Range.Wait',Wait);
WriteProfileWord(Section,'Range.StepCheck',Byte(StepCheck));
WriteProfileWord(Section,'Range.WaitCheck',Byte(WaitCheck));
end;
end;
procedure SaveSet(Section:PChar);
begin
WritePrivateProfileString('Motors',CurrentConfig,'1',Profile);
with AMotor do begin
WriteProfileWord(Section,'CFlags',CFlags);
WriteProfileHexWord(Section,'PortHWE',PortHWE);
WriteProfileHexWord(Section,'RefW',RefW);
WriteProfileHexWord(Section,'EndW',EndW);
WriteProfileHexWord(Section,'PortEAB',PortEAB);
WriteProfileHexWord(Section,'OnW',OnW);
WriteProfileHexWord(Section,'BrakeW',BrakeW);
WriteProfileHexWord(Section,'PortA',PortA);
WriteProfileHexWord(Section,'PortB',PortB);
end;
SaveMotorR(Section);
SaveRange(Section);
end;
end.
Vorgefundene Kodierung: ASCII (7 bit) | 2
|