Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: check PLC OS to set new default dir for BSD PLCs #215

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lcls-twincat-motion/Library/Library.plcproj
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,10 @@
<DefaultResolution>Tc2_Utilities, * (Beckhoff Automation GmbH)</DefaultResolution>
<Namespace>Tc2_Utilities</Namespace>
</PlaceholderReference>
<PlaceholderReference Include="Tc3_IPCDiag">
<DefaultResolution>Tc3_IPCDiag, * (Beckhoff Automation GmbH)</DefaultResolution>
<Namespace>Tc3_IPCDiag</Namespace>
</PlaceholderReference>
<PlaceholderReference Include="Tc3_JsonXml">
<DefaultResolution>Tc3_JsonXml, * (Beckhoff Automation GmbH)</DefaultResolution>
<Namespace>Tc3_JsonXml</Namespace>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ VAR_INPUT
// Set to TRUE to cause an extra read.
bRefresh: BOOL;
// Directory where the DB is stored.
sDirectory: STRING := '/Hard Disk/ftp/PMPS/';
sDirectory: STRING := '';
END_VAR
VAR_OUTPUT
{attribute 'pytmc' := '
Expand All @@ -42,6 +42,10 @@ VAR
fbTime : FB_LocalSystemTime := ( bEnable := TRUE, dwCycle := 1 );
fbTime_to_UTC: FB_TzSpecificLocalTimeToSystemTime;
fbGetTimeZone: FB_GetTimeZoneInformation;

fbIPCReg: FB_IPCDiag_Register;
fbCheckOS: FB_IPCDiag_ReadParameter;
sOSName: STRING;
END_VAR
]]></Declaration>
<Implementation>
Expand All @@ -62,9 +66,30 @@ IF rtEnable.Q OR rtRefresh.Q THEN
bExecute := TRUE;
END_IF

IF sDirectory = '' THEN
// Check OS for default directory
fbIPCReg(bExecute:=TRUE);
fbCheckOS(
bExecute:=NOT fbIPCReg.bBusy,
eParameterKey:=E_IPCDiag_ParameterKey.OS_Name,
fbRegister:=fbIPCReg,
);
IF fbCheckOS.bValid THEN
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this includes a check for error, but if there is an error, we won't be flagged.

Copy link
Member Author

@ZLLentz ZLLentz Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. You're right, as-written if we have an error the JSON file will silently never try to load and we might not notice an issue until we check the PMPS diagnostic.

This warrants some revision.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some options that I'm tossing around right now:

  • If there's an error, try again? (a few times?)
  • Go back to the old default?
  • Give an error log message?
  • Fast fault?

Needs some thought

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to opt for 3 tries followed by going back to the old default
This gives us some wiggle room for first-cycle-bs and will give us some normal error messages if the old default was wrong and if the old default was correct then the PLC will load values as normal.

Copy link
Contributor

@nrwslac nrwslac Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this means, if the OS isn't solved and a twincat BSD PLC gets the default directory, fbPmpsFileReader will throw a directory not found error.

fbCheckOS.GetParameter(
pBuffer:=ADR(sOSName),
nBufferSize:=SIZEOF(sOSName),
);
END_IF
IF sOSName = 'TwinCAT/BSD' THEN
sDirectory := '/home/ecs-user/pmpsdb/';
ELSIF sOSName <> '' THEN
sDirectory := '/Hard Disk/ftp/PMPS/';
END_IF
END_IF

MOTION_GVL.fbPmpsFileReader(
io_fbFFHWO:=io_fbFFHWO,
bExecute:=bExecute,
bExecute:=bExecute AND sDirectory <> '',
sSrcPathName:=CONCAT(CONCAT(sDirectory, sPlcName), '.json'),
sPLCName:=sPLCName,
PMPS_jsonDoc=>PMPS_GVL.BP_jsonDoc,
Expand Down