-
Notifications
You must be signed in to change notification settings - Fork 53
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
feat: Add TO_<BIT>
conversion functions
#1353
base: master
Are you sure you want to change the base?
Changes from all commits
b3217e3
a9c75e1
5720ec4
6a96c7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,246 @@ | ||
FUNCTION TO_BOOL<T: ANY> : BOOL | ||
VAR_INPUT | ||
in : T; | ||
END_VAR | ||
END_FUNCTION | ||
|
||
FUNCTION TO_BOOL__BYTE : BOOL | ||
VAR_INPUT | ||
in : BYTE; | ||
END_VAR | ||
|
||
TO_BOOL__BYTE := BYTE_TO_BOOL(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_BOOL__WORD : BOOL | ||
VAR_INPUT | ||
in : WORD; | ||
END_VAR | ||
|
||
TO_BOOL__WORD := WORD_TO_BOOL(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_BOOL__DWORD : BOOL | ||
VAR_INPUT | ||
in : DWORD; | ||
END_VAR | ||
|
||
TO_BOOL__DWORD := DWORD_TO_BOOL(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_BOOL__LWORD : BOOL | ||
VAR_INPUT | ||
in : LWORD; | ||
END_VAR | ||
|
||
TO_BOOL__LWORD := LWORD_TO_BOOL(in); | ||
END_FUNCTION | ||
|
||
// ======================================================================================================== // | ||
|
||
FUNCTION TO_BYTE<T: ANY> : BYTE | ||
VAR_INPUT | ||
in : T; | ||
END_VAR | ||
END_FUNCTION | ||
|
||
FUNCTION TO_BYTE__BOOL : BYTE | ||
VAR_INPUT | ||
in : BOOL; | ||
END_VAR | ||
|
||
TO_BYTE__BOOL := BOOL_TO_BYTE(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_BYTE__CHAR : BYTE | ||
VAR_INPUT | ||
in : CHAR; | ||
END_VAR | ||
|
||
TO_BYTE__CHAR := CHAR_TO_BYTE(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_BYTE__WORD : BYTE | ||
VAR_INPUT | ||
in : WORD; | ||
END_VAR | ||
|
||
TO_BYTE__WORD := WORD_TO_BYTE(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_BYTE__DWORD : BYTE | ||
VAR_INPUT | ||
in : DWORD; | ||
END_VAR | ||
|
||
TO_BYTE__DWORD := DWORD_TO_BYTE(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_BYTE__LWORD : BYTE | ||
VAR_INPUT | ||
in : LWORD; | ||
END_VAR | ||
|
||
TO_BYTE__LWORD := LWORD_TO_BYTE(in); | ||
END_FUNCTION | ||
|
||
// ======================================================================================================== // | ||
|
||
FUNCTION TO_WORD<T: ANY> : WORD | ||
VAR_INPUT | ||
in : T; | ||
END_VAR | ||
END_FUNCTION | ||
|
||
FUNCTION TO_WORD__BOOL : WORD | ||
VAR_INPUT | ||
in : BOOL; | ||
END_VAR | ||
|
||
TO_WORD__BOOL := BOOL_TO_WORD(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_WORD__CHAR : WORD | ||
VAR_INPUT | ||
in : CHAR; | ||
END_VAR | ||
|
||
TO_WORD__CHAR := CHAR_TO_WORD(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_WORD__BYTE : WORD | ||
VAR_INPUT | ||
in : BYTE; | ||
END_VAR | ||
|
||
TO_WORD__BYTE := BYTE_TO_WORD(in); | ||
END_FUNCTION | ||
Comment on lines
+103
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you're missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, what happens if I call I think the same-type functions are missing in general. I know it doesn't really make sense to call them, but we should cover it regardless I think - better to err on the safe side. |
||
|
||
FUNCTION TO_WORD__DWORD : WORD | ||
VAR_INPUT | ||
in : DWORD; | ||
END_VAR | ||
|
||
TO_WORD__DWORD := DWORD_TO_WORD(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_WORD__LWORD : WORD | ||
VAR_INPUT | ||
in : LWORD; | ||
END_VAR | ||
|
||
TO_WORD__LWORD := LWORD_TO_WORD(in); | ||
END_FUNCTION | ||
|
||
// ======================================================================================================== // | ||
|
||
FUNCTION TO_DWORD<T: ANY> : DWORD | ||
VAR_INPUT | ||
in : T; | ||
END_VAR | ||
END_FUNCTION | ||
|
||
FUNCTION TO_DWORD__BOOL : DWORD | ||
VAR_INPUT | ||
in : BOOL; | ||
END_VAR | ||
|
||
TO_DWORD__BOOL := BOOL_TO_DWORD(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_DWORD__CHAR : DWORD | ||
VAR_INPUT | ||
in : CHAR; | ||
END_VAR | ||
|
||
TO_DWORD__CHAR := CHAR_TO_DWORD(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_DWORD__WCHAR : DWORD | ||
VAR_INPUT | ||
in : WCHAR; | ||
END_VAR | ||
|
||
TO_DWORD__WCHAR := WCHAR_TO_DWORD(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_DWORD__BYTE : DWORD | ||
VAR_INPUT | ||
in : BYTE; | ||
END_VAR | ||
|
||
TO_DWORD__BYTE := BYTE_TO_DWORD(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_DWORD__WORD : DWORD | ||
VAR_INPUT | ||
in : WORD; | ||
END_VAR | ||
|
||
TO_DWORD__WORD := WORD_TO_DWORD(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_DWORD__LWORD : DWORD | ||
VAR_INPUT | ||
in : LWORD; | ||
END_VAR | ||
|
||
TO_DWORD__LWORD := LWORD_TO_DWORD(in); | ||
END_FUNCTION | ||
|
||
// ======================================================================================================== // | ||
|
||
FUNCTION TO_LWORD<T: ANY> : LWORD | ||
VAR_INPUT | ||
in : T; | ||
END_VAR | ||
END_FUNCTION | ||
|
||
FUNCTION TO_LWORD__BOOL : LWORD | ||
VAR_INPUT | ||
in : BOOL; | ||
END_VAR | ||
|
||
TO_LWORD__BOOL := BOOL_TO_LWORD(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_LWORD__CHAR : LWORD | ||
VAR_INPUT | ||
in : CHAR; | ||
END_VAR | ||
|
||
TO_LWORD__CHAR := CHAR_TO_LWORD(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_LWORD__WCHAR : LWORD | ||
VAR_INPUT | ||
in : WCHAR; | ||
END_VAR | ||
|
||
TO_LWORD__WCHAR := WCHAR_TO_LWORD(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_LWORD__BYTE : LWORD | ||
VAR_INPUT | ||
in : BYTE; | ||
END_VAR | ||
|
||
TO_LWORD__BYTE := BYTE_TO_LWORD(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_LWORD__WORD : LWORD | ||
VAR_INPUT | ||
in : WORD; | ||
END_VAR | ||
|
||
TO_LWORD__WORD := WORD_TO_LWORD(in); | ||
END_FUNCTION | ||
|
||
FUNCTION TO_LWORD__DWORD : LWORD | ||
VAR_INPUT | ||
in : DWORD; | ||
END_VAR | ||
|
||
TO_LWORD__DWORD := DWORD_TO_LWORD(in); | ||
END_FUNCTION | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably also add
TO_BYTE__WCHAR
here and have it behave the same asTO_DWORD__LWORD
. Might be nice if one is dealing with UART.