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: 79
Registered: May 2019
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: 79
Registered: May 2019
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: 49
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 message
joy woo is currently offline joy wooFriend
Messages: 79
Registered: May 2019
Member
thanks a lot, that is indeed 16bit , i just did a experiment :)
Previous Topic:4diac support for my device-stm32f103
Next Topic:anyone implement the canopen on forte?
Goto Forum:
  


Current Time: Tue Jan 28 13:59:01 GMT 2020

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

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

Back to the top