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 » Conversion of array to string(Converting array values to string for transferring data using MQTT)
Conversion of array to string [message #1834301] Fri, 06 November 2020 16:46 Go to next message
Pradeep Patel is currently offline Pradeep PatelFriend
Messages: 16
Registered: October 2020
Junior Member
I have created my own SIFB which reads data from I2C port and store data bytes in output array. I want to transfer these data bytes to program executing on PC using MQTT protocol. For using MQTT protocol I want to convert data stored in array to string. Please suggest.
Re: Conversion of array to string [message #1834315 is a reply to message #1834301] Sat, 07 November 2020 05:49 Go to previous messageGo to next message
zhao xiaolong is currently offline zhao xiaolongFriend
Messages: 5
Registered: November 2020
Junior Member
Hello,Pradeep. I saw your other post in the forum, which was about the raspberry PI lighting experiment. I'm also experimenting with raspberry PI, and I've used Python to call the I2C interface. So I want to ask how to call the I2C interface with 4diac. Looking forward to your reply. Thank you very much.
Re: Conversion of array to string [message #1834320 is a reply to message #1834315] Sat, 07 November 2020 07:40 Go to previous messageGo to next message
Pradeep Patel is currently offline Pradeep PatelFriend
Messages: 16
Registered: October 2020
Junior Member
Hello Zhao, I did following:
1. Created my own SIFB as per documentation on 4Diac website. This SIFB should have event inputs like INIT and REQ. Exported this SIFB from 4Diac IDE to have .cpp file.
2. This exported .cpp file will have function "void FORTE_SIFBName::executeEvent(int pa_nEIID)". In this function under "scm_nEventINITID" you can write your code to initialize I2C port. Since it is .cpp file it will not support python and you need to convert your code to equivalent C or C++ code. I used linux calls like IOCTL and Open() functions to initialize I2C port of raspberry PI as raspbian is linux based.
3. In same function under "scm_nEventREQID" you can write read()/write() logic to send command and receive response from I2C device.
4. You need to include these files to forte source code and rebuild your forte for raspberry PI.
5. Write your 4Diac program using your SIFB to access I2C device and test

Hope this helps!
Re: Conversion of array to string [message #1834324 is a reply to message #1834320] Sat, 07 November 2020 09:08 Go to previous messageGo to next message
zhao xiaolong is currently offline zhao xiaolongFriend
Messages: 5
Registered: November 2020
Junior Member
Thank you very much for your reply, which is very helpful to me. I will try to edit FB in this way. I never thought about modifying the.cpp file. It was awesome.
Re: Conversion of array to string [message #1834404 is a reply to message #1834324] Mon, 09 November 2020 19:30 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1584
Registered: January 2014
Senior Member

Hi,

regarding your original question. What data type does your I2C reading FB have? If it is an IEC 61131-3 array. You could write yourself a simple FB and in that us ST to convert each individual element of your array to a string and append it to your full string. For that you can use the IEC 61131-3 conversion and string manipulation functions. All FBs in the IEC 61131-3 lib starting with an F_ are also available as function in algorithm with out the F_ prefix (e.,g F_BOOL_STRING -> var := BOOL_TO_STRING(xx);).
Re: Conversion of array to string [message #1834426 is a reply to message #1834404] Tue, 10 November 2020 08:25 Go to previous messageGo to next message
zhao xiaolong is currently offline zhao xiaolongFriend
Messages: 5
Registered: November 2020
Junior Member
haha, I found that My reply was wrong. sorry!

[Updated on: Tue, 10 November 2020 08:27]

Report message to a moderator

Re: Conversion of array to string [message #1834433 is a reply to message #1834426] Tue, 10 November 2020 10:14 Go to previous message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 1584
Registered: January 2014
Senior Member

no problem. I just was about to write you can also do it C++ but that would not be as nice and portable and therefore didn't want to recommend.
Previous Topic:Sting to BOOL and vice versa not working on raspberry PI
Next Topic:FORTE and OpenDSS
Goto Forum:
  


Current Time: Tue Apr 23 11:12:21 GMT 2024

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

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

Back to the top