Skip to content

Commit

Permalink
Created Pre-release v0.2.0.1
Browse files Browse the repository at this point in the history
+ Added new file and directory general error codes.
+ Added `F_CreateErrorFromStartRange(...)`
+ Updated loggers to use `F_CreateErrorFromStartRange`
  • Loading branch information
fisothemes committed Jun 22, 2024
1 parent 8934b1e commit 7d006ce
Show file tree
Hide file tree
Showing 26 changed files with 120 additions and 42 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ END_METHOD
```

### Logging an Error
To log an error, use the `.LogMessage(...)` method of the `FsError.T_Error` instance. This method takes an error logger. The error can be logged using different loggers, such as the provided ADS logger (`FB_AdsErrorLogger`) and a disk logger (`FB_DiskErrorLogger`) or a custom logger implemented using the `FsError.I_ErrorLogger` interface.
To log an error, use the `LogMessage(...)` method of the `FsError.T_Error` instance. This method takes an error logger. The error can be logged using different loggers, such as the provided ADS logger (`FB_AdsErrorLogger`) and a disk logger (`FB_DiskErrorLogger`) or a custom logger implemented using the `FsError.I_ErrorLogger` interface.
```js
PROGRAM MAIN
VAR
bCreateError,
bLogWithAds,
bLogToDisk : BOOL;
dErrDate : DATE;
todErrTime : TOD;
Err : FsError.T_Error;
dErrDate : DATE;
todErrTime : TOD;
Err : FsError.T_Error;
fbWithAdsLogger : FsError.FB_AdsErrorLogger;
fbToDisk : FsError.FB_DiskErrorLogger('C:\temp\errlog.csv');
fbToDisk : FsError.FB_DiskErrorLogger('C:\temp\errlog.csv');
END_VAR

// Create error.
Expand All @@ -80,10 +80,10 @@ IF bLogToDisk THEN
END_IF

// Get date of error.
dErrDate := Err.Timestamp.GetDate();
dErrDate := Err.Timestamp.GetDate();

// Get time of day of error.
todErrTime := Err.Timestamp.GetTimeOfDay();
todErrTime := Err.Timestamp.GetTimeOfDay();

...

Expand Down
Binary file added builds/FsError_0.2.0.1.library
Binary file not shown.
12 changes: 10 additions & 2 deletions src/FisoThemes Error Library.tsproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@
<CLSID ClassFactory="TcPlc30">{08500001-0000-0000-F000-000000000064}</CLSID>
<Contexts>
<Context>
<Id>1</Id>
<Name>Default</Name>
<Id NeedCalleeCall="true">0</Id>
<Name>PlcTask</Name>
<ManualConfig>
<OTCID>#x02010040</OTCID>
</ManualConfig>
<Priority>21</Priority>
<CycleTime>10000000</CycleTime>
</Context>
</Contexts>
<TaskPouOids>
<TaskPouOid Prio="21" OTCID="#x08502041"/>
</TaskPouOids>
</Instance>
</Project>
</Plc>
Expand Down
4 changes: 4 additions & 0 deletions src/FsError/DUTs/E_GeneralErrorCode.TcTLEO
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ TYPE E_GeneralErrorCode :
ERR_FILE_ALREADY_EXISTS := 1104, // File already exists
ERR_FILE_TOO_LARGE := 1105, // File size exceeds the maximum allowed size
ERR_FILE_FORMAT_UNSUPPORTED := 1106, // Unsupported file format
ERR_FILE_NOT_OPEN := 1107, // File isn't open
ERR_FILE_INVALID_HANDLE := 1108, // File handle is invalid
{endregion}
{region "Directory Errors (1150-1199)"}
Expand All @@ -123,6 +125,8 @@ TYPE E_GeneralErrorCode :
ERR_DIRECTORY_PERMISSION_DENIED := 1153, // Directory operation permission denied
ERR_DIRECTORY_NOT_EMPTY := 1154, // Directory is not empty
ERR_DIRECTORY_ALREADY_EXISTS := 1155, // Directory already exists
ERR_DIRECTORY_NOT_OPEN := 1157, // Directory isn't open
ERR_DIRECTORY_INVALID_HANDLE := 1158, // Directory handle is invalid
{endregion}
{region "Cache Errors (1200-1249)"}
Expand Down
5 changes: 4 additions & 1 deletion src/FsError/FsError.plcproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<CombineIds>true</CombineIds>
<Company>FisoThemes</Company>
<Title>FsError</Title>
<ProjectVersion>0.1.0.0</ProjectVersion>
<ProjectVersion>0.2.0.1</ProjectVersion>
<LibraryCategories>
<LibraryCategory xmlns="">
<Id>{dd9b7bed-6894-42d1-82c5-149be3e6aacd}</Id>
Expand Down Expand Up @@ -101,6 +101,9 @@
<Compile Include="POUs\Errors\F_CreateError.TcPOU">
<SubType>Code</SubType>
</Compile>
<Compile Include="POUs\Errors\F_CreateErrorFromStartRange.TcPOU">
<SubType>Code</SubType>
</Compile>
<Compile Include="POUs\Loggers\FB_AdsErrorLogger.TcPOU">
<SubType>Code</SubType>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ END_VAR]]></Declaration>
E_GeneralErrorCode.ERR_FILE_ALREADY_EXISTS: GetDescription := 'File already exists.';
E_GeneralErrorCode.ERR_FILE_TOO_LARGE: GetDescription := 'File size exceeds the maximum allowed size.';
E_GeneralErrorCode.ERR_FILE_FORMAT_UNSUPPORTED: GetDescription := 'Unsupported file format.';
E_GeneralErrorCode.ERR_FILE_NOT_OPEN: GetDescription := 'File isn$'t open.';
E_GeneralErrorCode.ERR_FILE_INVALID_HANDLE: GetDescription := 'File handle is invalid.';
// Directory Errors (1150-1199)
E_GeneralErrorCode.ERR_DIRECTORY_NOT_FOUND: GetDescription := 'The specified directory was not found.';
Expand All @@ -125,6 +127,8 @@ END_VAR]]></Declaration>
E_GeneralErrorCode.ERR_DIRECTORY_PERMISSION_DENIED: GetDescription := 'Directory operation permission denied.';
E_GeneralErrorCode.ERR_DIRECTORY_NOT_EMPTY: GetDescription := 'Directory is not empty.';
E_GeneralErrorCode.ERR_DIRECTORY_ALREADY_EXISTS: GetDescription := 'Directory already exists.';
E_GeneralErrorCode.ERR_DIRECTORY_NOT_OPEN: GetDescription := 'Directory isn$'t open.';
E_GeneralErrorCode.ERR_DIRECTORY_INVALID_HANDLE: GetDescription := 'Directory handle is invalid.';
// Cache Errors (1200-1249)
E_GeneralErrorCode.ERR_CACHE_MISS: GetDescription := 'Cache miss occurred.';
Expand Down
7 changes: 4 additions & 3 deletions src/FsError/POUs/Errors/F_CreateError.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<TcPlcObject Version="1.1.0.1">
<POU Name="F_CreateError" Id="{6245ffe2-0c4b-0378-2c63-08c56849c572}" SpecialFunc="None">
<Declaration><![CDATA[// Create errors with specified parameters and sets the timestamp to the local time.
FUNCTION F_CreateError : FB_Error
FUNCTION F_CreateError : T_Error // Instance of created error.
VAR_INPUT
ipDescriptor : I_ErrorDescriptor; // Error descriptor.
Code : T_ErrorCode; // Error code.
Expand All @@ -14,11 +14,12 @@ VAR
nHighResTimestamp : ULINT;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[// Get highres local timestamp.
<ST><![CDATA[// Get high res. local timestamp.
nResult := SysTimeRtc.SysTimeRtcConvertUtcToLocal(
SysTimeRtc.SysTimeRtcGet(nResult),
nLowResTimestamp);
// Add milliseconds to high res. timestamp.
nHighResTimestamp := TO_ULINT(nLowResTimestamp)*1000
+
(TO_ULINT(LTIME()) MOD TO_ULINT(LTIME#1S)) / TO_ULINT(LTIME#1MS);
Expand Down
39 changes: 39 additions & 0 deletions src/FsError/POUs/Errors/F_CreateErrorFromStartRange.TcPOU
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1">
<POU Name="F_CreateErrorFromStartRange" Id="{d5f028a0-24ee-0f73-1be1-cd20ce46f9c4}" SpecialFunc="None">
<Declaration><![CDATA[// Create errors with specified parameters and sets the timestamp to the local time from a starting range.
// Some error descriptors have ranges for error codes.
// If the code is 0 an unraised error is created.
FUNCTION F_CreateErrorFromStartRange : T_Error // Instance of created error.
VAR_INPUT
ipDescriptor : I_ErrorDescriptor; // Error descriptor.
StartRange : T_ErrorCode; // Error code starting Range.
Code : T_ErrorCode; // Error code.
END_VAR
VAR
fbMutError : FB_MutableError;
nResult,
nLowResTimestamp : DWORD;
nHighResTimestamp : ULINT;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[// Get high res. local timestamp.
nResult := SysTimeRtc.SysTimeRtcConvertUtcToLocal(
SysTimeRtc.SysTimeRtcGet(nResult),
nLowResTimestamp);
// Add milliseconds to high res. timestamp.
nHighResTimestamp := TO_ULINT(nLowResTimestamp)*1000
+
(TO_ULINT(LTIME()) MOD TO_ULINT(LTIME#1S)) / TO_ULINT(LTIME#1MS);
// Set muttable error.
fbMutError.SetDescriptor(ipDescriptor)
.RaiseError(SEL(Code <> 0, 0, StartRange + Code))
.SetTimestamp(nHighResTimestamp);
// Return as immutable error.
F_CreateErrorFromStartRange := fbMutError;]]></ST>
</Implementation>
</POU>
</TcPlcObject>
5 changes: 3 additions & 2 deletions src/FsError/POUs/Loggers/FB_AdsErrorLogger.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ eResult := Tc2_System.ADSLOGSTR(
TO_STRING(ipError.Code));
IF eResult <> 0 THEN
Error := F_CreateError(
GVL_ErrorDescriptors.fbAdsReturnCodes,
Error := F_CreateErrorFromStartRange(
GVL_ErrorDescriptors.fbGeneralErrorCodes,
E_GeneralErrorCode.ERR_ADS_RETURN_CODE_BEGIN,
eResult);
END_IF]]></ST>
</Implementation>
Expand Down
37 changes: 24 additions & 13 deletions src/FsError/POUs/Loggers/FB_DiskErrorLogger.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ END_VAR]]></Declaration>
IF eResult = E_CodesysCmpError.ERR_OK THEN RETURN; END_IF
Error := F_CreateError( GVL_ErrorDescriptors.fbGeneralErrorCodes,
E_GeneralErrorCode.ERR_CODESYS_BEGIN + eResult);]]></ST>
Error := F_CreateErrorFromStartRange(
GVL_ErrorDescriptors.fbGeneralErrorCodes,
E_GeneralErrorCode.ERR_CODESYS_BEGIN,
eResult);]]></ST>
</Implementation>
</Method>
<Method Name="CreateLogEntry" Id="{a64b81cf-7222-08ce-2b93-1933ad3b8e24}" FolderPath="Internal\">
Expand Down Expand Up @@ -228,14 +230,21 @@ END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[Flush := THIS^;
IF NOT THIS^.IsOpen THEN RETURN; END_IF
IF NOT THIS^.IsOpen THEN
Error := F_CreateError(
GVL_ErrorDescriptors.fbGeneralErrorCodes,
E_GeneralErrorCode.ERR_FILE_NOT_OPEN);
RETURN;
END_IF
eResult := SysFile.SysFileFlush(THIS^._Handle);
IF eResult = E_CodesysCmpError.ERR_OK THEN RETURN; end_if
Error := F_CreateError( GVL_ErrorDescriptors.fbGeneralErrorCodes,
E_GeneralErrorCode.ERR_CODESYS_BEGIN + eResult);]]></ST>
Error := F_CreateErrorFromStartRange(
GVL_ErrorDescriptors.fbGeneralErrorCodes,
E_GeneralErrorCode.ERR_CODESYS_BEGIN,
eResult);]]></ST>
</Implementation>
</Method>
<Method Name="Invoke" Id="{59e699e2-7a12-01ea-1ac7-9de854c5852e}">
Expand Down Expand Up @@ -274,9 +283,10 @@ nBytesWritten := SysFile.SysFileWrite(
// Check for errors.
IF eResult <> E_CodesysCmpError.ERR_OK THEN
Error := F_CreateError(
Error := F_CreateErrorFromStartRange(
GVL_ErrorDescriptors.fbGeneralErrorCodes,
E_GeneralErrorCode.ERR_CODESYS_BEGIN + eResult);
E_GeneralErrorCode.ERR_CODESYS_BEGIN,
eResult);
END_IF
// Check if writter is busy.
Expand All @@ -286,9 +296,10 @@ bIsBusy := Error.IsNotRaised AND nBytesWritten = 0;
IF NOT bIsBusy AND Error.IsNotRaised AND THIS^._bAutoFlush THEN
eResult := SysFile.SysFileFlush(THIS^._Handle);
IF eResult <> E_CodesysCmpError.ERR_OK THEN
Error := F_CreateError(
Error := F_CreateErrorFromStartRange(
GVL_ErrorDescriptors.fbGeneralErrorCodes,
E_GeneralErrorCode.ERR_CODESYS_BEGIN + eResult);
E_GeneralErrorCode.ERR_CODESYS_BEGIN,
eResult);
END_IF
END_IF]]></ST>
</Implementation>
Expand Down Expand Up @@ -350,10 +361,10 @@ bIsBusy := eResult = E_CodesysCmpError.ERR_OK AND THIS^._Handle = SysTypes.RTS_I
IF bIsBusy OR eResult = E_CodesysCmpError.ERR_OK THEN RETURN; END_IF
Error := F_CreateError( GVL_ErrorDescriptors.fbGeneralErrorCodes,
E_GeneralErrorCode.ERR_CODESYS_BEGIN + eResult);
]]></ST>
Error := F_CreateErrorFromStartRange(
GVL_ErrorDescriptors.fbGeneralErrorCodes,
E_GeneralErrorCode.ERR_CODESYS_BEGIN,
eResult);]]></ST>
</Implementation>
</Method>
<Method Name="SetDelimiter" Id="{c65adf51-c44e-0bc1-1c26-85c083bc7d41}">
Expand Down
6 changes: 4 additions & 2 deletions src/FsError/POUs/PLAYGROUND.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ END_VAR]]></Declaration>
IF bCreate THEN
bCreate := FALSE;
Err := F_CreateError(GVL_ErrorDescriptors.fbGeneralErrorCodes,
E_GeneralErrorCode.ERR_ADS_RETURN_CODE_BEGIN + E_AdsReturnCode.ADSERR_DEVICE_INVALIDCONTEXT);
Err := F_CreateErrorFromStartRange(
GVL_ErrorDescriptors.fbGeneralErrorCodes,
E_GeneralErrorCode.ERR_ADS_RETURN_CODE_BEGIN,
E_AdsReturnCode.ERR_NOERROR);
END_IF
IF bLog THEN Err.LogMessage(fbToDisk, bIsBusy => bLog, Error => DiskLogErr); END_IF
Expand Down
4 changes: 2 additions & 2 deletions src/FsError/Project Information/F_GetVersion.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ VAR_INPUT
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[F_GetVersion.iMajor := 0;
F_GetVersion.iMinor := 1;
F_GetVersion.iMinor := 2;
F_GetVersion.iBuild := 0;
F_GetVersion.iRevision := 0;
F_GetVersion.iRevision := 1;
]]></ST>
</Implementation>
</POU>
Expand Down
2 changes: 1 addition & 1 deletion src/FsError/Version/Global_Version.TcGVL
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// This function has been automatically generated from the project information.
VAR_GLOBAL CONSTANT
{attribute 'const_non_replaced'}
stLibVersion_FsError : ST_LibVersion := (iMajor := 0, iMinor := 1, iBuild := 0, iRevision := 0, nFlags := 0, sVersion := '0.1.0.0');
stLibVersion_FsError : ST_LibVersion := (iMajor := 0, iMinor := 2, iBuild := 0, iRevision := 1, nFlags := 0, sVersion := '0.2.0.1');
END_VAR
]]></Declaration>
</GVL>
Expand Down
23 changes: 14 additions & 9 deletions src/FsError_Test/FsError_Test.plcproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@
<Namespace>TcUnit</Namespace>
</PlaceholderReference>
</ItemGroup>
<ItemGroup>
<None Include="FsError_Test.tmc">
<SubType>Content</SubType>
</None>
</ItemGroup>
<ProjectExtensions>
<PlcProjectOptions>
<XmlArchive>
<Data>
<o xml:space="preserve" t="OptionKey">
<Data>
<o xml:space="preserve" t="OptionKey">
<v n="Name">"&lt;ProjectRoot&gt;"</v>
<d n="SubKeys" t="Hashtable" ckt="String" cvt="OptionKey">
<v>{192FAD59-8248-4824-A8DE-9177C94C195A}</v>
Expand Down Expand Up @@ -106,13 +111,13 @@
</d>
<d n="Values" t="Hashtable" />
</o>
</Data>
<TypeList>
<Type n="Hashtable">System.Collections.Hashtable</Type>
<Type n="OptionKey">{54dd0eac-a6d8-46f2-8c27-2f43c7e49861}</Type>
<Type n="String">System.String</Type>
</TypeList>
</XmlArchive>
</Data>
<TypeList>
<Type n="Hashtable">System.Collections.Hashtable</Type>
<Type n="OptionKey">{54dd0eac-a6d8-46f2-8c27-2f43c7e49861}</Type>
<Type n="String">System.String</Type>
</TypeList>
</XmlArchive>
</PlcProjectOptions>
</ProjectExtensions>
</Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 7d006ce

Please sign in to comment.