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

feat: TO_<NUM> library functions #1334

Closed
wants to merge 5 commits into from
Closed

Conversation

volsa
Copy link
Member

@volsa volsa commented Oct 14, 2024

This PR introduces the TO_<NUM> library function. Under the hood any TO_<NUM> function makes use of the already existing and tested <NUM>_TO_<NUM> functions.

Also, I've decided to isolate the TO_<NUM> functions into a separate file instead of appending them to num_conversion.st, to make discoverability and readability easier.

@volsa volsa changed the title feat: std type conversion functions feat: TO_<NUM> library functions Oct 15, 2024
@volsa volsa marked this pull request as ready for review October 15, 2024 08:18
@volsa volsa requested review from ghaith and mhasel October 15, 2024 08:18
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to keep these generative scripts around? I think they've served their purpose and there is no need to track them via git/keep them in our sources.

Copy link
Member Author

Choose a reason for hiding this comment

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

imo it doesn't hurt to track them in case anything changes in the future where we have to regenerate the ST files but I'm also fine with deleting them. Which one do you prefer?

Copy link
Member

Choose a reason for hiding this comment

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

See comment in the other to_num.py file

Comment on lines 3 to 14
types = [
"SINT",
"USINT",
"INT",
"UINT",
"DINT",
"UDINT",
"LINT",
"ULINT",
"LREAL",
"REAL",
]
Copy link
Member

Choose a reason for hiding this comment

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

It seems like we are missing quite a few types here, i.e. TIME, LTIME, LWORD, (STRING?), etc. I've tried converting a TIME variable to USINT, which will just end up calling TO_USINT__USINT, silently truncating the input down to 8 bits, losing most of the information and returning wrong values.
Are these planned for a different commit?

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'll have to check what CodeSys supports here, but BOOL(?), BYTE, WORD, DWORD and LWORD are (probably) missing here. I forgot about them somehow

@volsa volsa changed the title feat: TO_<NUM> library functions feat: TO_<NUM> library functions Oct 15, 2024
REAL and LREAL for bit / byte types seems to be wrong as of now.
Maybe we need an external keyword here?
@volsa volsa force-pushed the volsa/type-conversion-functions branch from 2988383 to 4082459 Compare October 16, 2024 13:54
@volsa volsa marked this pull request as draft October 16, 2024 13:54
@volsa volsa closed this Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants