12/20/2015 2:57 PM | |
Posts: 13 Rating:
|
Hi guys, a quick help is needed. I am receiving unsigned value from a sinamics drive. Eg. EA7F equals 60031, but when I write to int i get value -5005. Would be great if someone have a good trick to convert to INT. Thanks in advance |
12/20/2015 3:21 PM | |
Posts: 5225 Rating:
|
The INT data type does not have that number... |
12/20/2015 3:41 PM | |
Posts: 13 Rating:
|
How to get UINT in Simatic S7-300? |
12/20/2015 3:46 PM | |
Posts: 5225 Rating:
|
ahaaa... Use a WORD and ensure you have IEC check switched off. |
12/20/2015 3:59 PM | |
Posts: 13 Rating:
|
Well I need to know this information in DEC since I need this information to know fault codes from Sinamics drive. Integer value is needed, but drive cannot give me signed int |
12/20/2015 6:18 PM | |
Posts: 13 Rating:
|
Any ideas gents? |
12/20/2015 6:34 PM | |
Posts: 13 Rating:
|
I will forget about this, and rather use DINT. But would be great if there were a way to convert from uint to int without using extra bytes. |
12/20/2015 9:38 PM | |
Posts: 5225 Rating:
|
Per definition: The number "60031" that you spoke of, cannot be handled by INT (16 bit signed number). UINT (unsigned INT) can handle it. The S7-1200 / S7-1500 do have the data type UINT, while the S7-300 in the strict sense does not have this data type. Before Step7 for TIA Portal, we were less worried about getting a UINT number, as we used WORD data type. you could say that WORD is unformatted thus you can decide how it is used.. as INT or UINT. There is a problem however... Example follows: Some LAD code (not actually functional)... When you work with WORD data type for the S7-300... Working with "DEC" as you mentioned.. has to do with how you format the number. It has nothing to do with working with the WORD as data type. Compare action per STL is more flexible... (problem follows)
..there is a problem however. In the above example MW20 is now "forced" to read as an INT. If that happens however, then the UINT#60031 looks like a negative INT number as you mentioned before. I do not know what you are reading from the drive. If it is a bit status, then you should handle the status as a WORD and extract the bits from it as you require. If however you are reading a number you have other considerations. If you only need to compare with == and <> then the WORD type is good enough. But if you need more processing than that, the DINT is the best way to go for the PLC you use. The "waste" of 16 bits is really insignificant in respects to what you gain in having a workable number. I hope these notes are of value to you (..and others). Regards, |
12/21/2015 9:15 AM | |
Posts: 5225 Rating:
|
.. there is one detail I have missed. In STL it is possible to do the following:
|
12/21/2015 9:32 AM | |
Posts: 13 Rating:
|
I understand now. Thank you very much. |
We are working on a new user interface with better overview and more relevance.
Follow us on