Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » 4DIAC - Framework for Distributed Industrial Automation and Control » Convert decimal to binary format with ST
Convert decimal to binary format with ST [message #1819329] Mon, 13 January 2020 10:43 Go to next message
joy woo is currently offline joy wooFriend
Messages: 149
Registered: May 2019
Senior Member
V1 := WORD_TO_BOOL(UINT_TO_WORD(Registers) AND 1);
V2 := WORD_TO_BOOL(UINT_TO_WORD(Registers) AND 2);
V3 := WORD_TO_BOOL(UINT_TO_WORD(Registers) AND 4);
V4 := WORD_TO_BOOL(UINT_TO_WORD(Registers) AND 8);
V5 := WORD_TO_BOOL(UINT_TO_WORD(Registers) AND 16);
V6 := WORD_TO_BOOL(UINT_TO_WORD(Registers) AND 32);
V7 := WORD_TO_BOOL(UINT_TO_WORD(Registers) AND 64);
V8 := WORD_TO_BOOL(UINT_TO_WORD(Registers) AND 128);


I use these above in ST,
but when deploying failed.
Re: Convert decimal to binary format with ST [message #1819340 is a reply to message #1819329] Mon, 13 January 2020 13:59 Go to previous messageGo to next message
joy woo is currently offline joy wooFriend
Messages: 149
Registered: May 2019
Senior Member
wired is , i use if, i am sure the gramma is correct, but can't make it
IF 1>0 THEN
V1 := TRUE;
END_IF
once it remove this, it works, otherwise fails
Re: Convert decimal to binary format with ST [message #1819388 is a reply to message #1819340] Tue, 14 January 2020 10:57 Go to previous messageGo to next message
Kirill Dorofeev is currently offline Kirill DorofeevFriend
Messages: 57
Registered: February 2016
Member
Hi,

first of all I'm not sure if there is WORD_TO_BOOL function and how it is supposed to work. What I would do in ST is something like this:

IF (UINT_TO_WORD(QI) AND 1 ) = 1 THEN
BOOL1 := TRUE;
ELSE
BOOL1 := FALSE;
END_IF;
IF (UINT_TO_WORD(QI) AND 2 ) = 2 THEN
BOOL2 := TRUE;
ELSE
BOOL2 := FALSE;
END_IF;
IF (UINT_TO_WORD(QI) AND 4 ) = 4 THEN
BOOL3 := TRUE;	
ELSE
BOOL3 := FALSE;
END_IF;
IF (UINT_TO_WORD(QI) AND 8 ) = 8 THEN
BOOL4 := TRUE;
ELSE
BOOL4 := FALSE;
END_IF;
...


(btw, word is usually 16 bits, are you sure that you only want 8 bits?).. last thing i had to do with this FB after I exported the code from IDE, is to change in the generated cpp all logical ANDs "&&" to bitwise "&".. not sure, if I did something wrong or is it a type exporter. for that, we need to wait for ST/forte experts :-)
Re: Convert decimal to binary format with ST [message #1819465 is a reply to message #1819388] Thu, 16 January 2020 02:29 Go to previous messageGo to next message
joy woo is currently offline joy wooFriend
Messages: 149
Registered: May 2019
Senior Member
thanks a lot, that is indeed 16bit , i just did a experiment :)
Re: Convert decimal to binary format with ST [message #1821481 is a reply to message #1819465] Thu, 13 February 2020 14:23 Go to previous message
Martin Melik-Merkumians is currently offline Martin Melik-MerkumiansFriend
Messages: 97
Registered: March 2016
Member
WORD_TO_BOOL is not a valid cast, as there is no logical way to determine the result. WORD is a bit-pattern, BOOL is a logical value.

Valid and equivalent code would be
V1 := (UINT_TO_WORD(Registers) AND 1) == 1;
V2 := (UINT_TO_WORD(Registers) AND 2) == 2;
and so on.

Another option would be the recently added bit access operators, which should be available in the develop branch.
Previous Topic:Stopping and starting FB applications under FORTE
Next Topic:Can forte be compile under macos?
Goto Forum:
  


Current Time: Fri Nov 27 21:13:42 GMT 2020

Powered by FUDForum. Page generated in 0.02020 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top