MODBUS is a communication protocol over a variety of  networks such as RS232 and Ethernet which was designed by Modicon.

It has been used widely since last several ten years and FreeMODBUS is a free implementation of this popular MODBUS protocol. 


Recently I wanted to have a tool to share data between some embedded devices over serial connection or ethernet and heard MODBUS can be a starting point for such purpose. So this is the outcome.


This MBServer ( a sample MODBUS TCP server) supports Qt5 but for now no GUI. Later I will put some GUI on it to talk with devices which can support MODBUS. For someone with interests on this can find source tree in the following link.  


https://github.com/seetime/freeMBServer/


How to build:


You need to have Cmake to generate Visual studio C++ project file.


First download source file and enter the root folder


cd <MBServer_root_dir>

mkdir build

cd build

cmake ..


With the project file generated, open it in Visual studio IDE and build and run.

 

For test, I used a MODBUS Diagnostick tool such as Modsak.  



Conclusion.


If someone need to develop application to talk with remote device over serial or Ethernet, MODBUS can be a option for such. This post could be helpful for someone searching or wanting to develop a basic MODBUS server tool. 


Posted by kevino
,

In Qt5, writing Cmake project for building Qt5 opengl app with optional shader seems to be little complicated comparing to previous Qt version(i.e Qt v5.0.2) and took time to figure out how to configure all necessary things. After many hours on this issue, I found one configuration to make possible to building Qt5 opengl app with Cmake and this post is to describe what I did with helps from various internet sources which will be listed below accordingly.


First thing to tell is preconditions before writing sources.


Precondition


1. OS: MS Windows 7

2. Qt version and toolkit: prebuilt Qt 5.1.0 msvc2010_opengl

3. Visual studio 2010

4. Windows SDK should be installed properly. : ie) c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\

5. CMake 2.8.11


If your system is different with the above precondition, CMakeLists.txt should be changed properly. Refer to the example CMakeLists.txt in this post. You can get a hint about how to edit.


Now it is time to introduce source code for building a simple Qt5 opengl shader app. 


Because main purpose to write up this post is to show how to create CMakeLists.txt to compile existing source codes, just copy and create all 3 files referring to this link:  http://qt-project.org/doc/qt-5.0/qtgui/openglwindow.html


And last file CMakeLists.txt.


CMakeLists.txt


Now we have all files to build up Qt5 shader app showing rotating triangle and time to run cmake to create visual studio project file for this app. If you are lucky to complete compilation and launching this app, then you will see a rotating triangle with help of Opengl shader in a window.



One last thing I want to note is that CMAKE_PREFIX_PATH in CMakeLists.txt MUST include proper paths in order to succeed compilation. As you can see in the above example, there are two paths are included.

First path is the location to find all neccessary Qt5 tools and must be same with the path in below picture. Below picture shows Qt Options dialog box in Visual studio 2010 through "Qt5" -> "Qt5 options" which is enabled if you installed visual studio addin for Qt5





Second path in CMAKE_PREFIX_PATH is required to compile with OpenGL library: glu32.lib and opengl32.lib. These files are included in Windows SDK so make sure this before starting compilation and also don't forget to include TARGET_LINK_LIBRARIES in the above example. Otherwise, opengl libraries will not be included in the project file generated by cmake.


Added 2013-09-23.


You may notice below error message on compilation.

Error message=> module machine type 'x64' conflicts with target machine type 'X86'


This error message happens when you create visual studio project file for 32 bit binary and try to compile against 64 bit library. The default behavior of running "cmake .." on 64 bit machine usually generates 32 bit project instead of 64 bit project file so this may cause compilation error.


Solution. Try to generate 64 bit visual studio project file using below command and compile binary with it.

cmake -G "Visual Studio 11 Win64" ..


Below is source code for your convenience.


qt5shader.7z


Posted by kevino
,

This is extended from my previous post: http://kevino.tistory.com/entry/CMakeqt5-Simple-example-for-CMake-QT5-package.


The source files in the above link is intended to be built on Host system and run on local machine. Here I will explain how to cross compile the same source codes  with almost same environment.


In order to develop QT app targeted for Arm embedded system, you need to first prepare Qt5 framework suitable for target board.


For i.MX6 Sabre SDB, refer to the following link: https://community.freescale.com/docs/DOC-94066. If you dont see any error in completing procedures described in the above link, you can find many example binaries created in $(TARGET_rootfs)/opt/qt5/examples and verify by running several examples.


Note. You may not see examples compiled even though you followed all steps. In this case, you can compile the examples manually by running below commands on Host system. If compilation is successful, then verify examples by running those on target board.


$ cd $(QTdir)/qtbase

$ make sub-examples


For now, before running cross compile commands, make sure that the following conditions are all met.


1. Target system is booted via nfs and "/" is mounted on ${TARGET_rootfs) of host system.

2. Qt5 for target board is installed at $(TARGET_rootfs)/opt/qt5 and examples at $(TARGET_rootfs)/opt/qt5/examples.

3. Need to verify whether Qt5 works by running example files and checking QT logo moving in 3D screen.

Target> cd /opt/qt5/examples

Target> ./opengl/hellogl_es2/hellogl_es2


If Qt5 is installed, then lets reuse the project source code which will be converted app for target board.


First we need to inform CMake that we will use cross compile and CMake dev team already made this solution since Cmake 2.6 version. 


For this, we can create a new cmake module similar to the below and remember its path.


Toolchain-freescale-imx6q.cmake


Now you can run cmake with crosscompile options to build the source codes. Assuming the above setup,


$ cd /home/<userid>/utils/ltib/rootfs/root

$ 7za x sample1.7z

$ cd sample1

$ mkdir build

$ cd build

$ cmake -DCMAKE_TOOLCHAIN_FILE=$(PATH_to_)/Toolchain-freescale-imx6q.cmake ..

$ make



Note. While running cmake, if you notice an error "Failed to find GLESv2 in "", then you can fix this error by modifying Qt5GuiConfigExtras.cmake at /home/<userid>/utils/ltib/rootfs/opt/qt5/lib/cmake/Qt5Gui/.


At 50 lines

- _qt5gui_find_extra_libs(OPENGL "GLESv2;GLESv2;EGL;GAL" "" "")

+ _qt5gui_find_extra_libs(OPENGL "GLESv2;GLESv2;EGL;GAL" ${CMAKE_FIND_ROOT_PATH}/usr/lib/ "")


I dont think this patch is good but it works for me so you can use this until official patch is ready. At least Qt 5.1.0 has this problem.


You can examine the exe file in target machine whether this Qt5 app can be run. If successful, now you are ready to develop Qt5 application running on Target board.




Posted by kevino
,

In the official online document for QT5, qt5 guys say that there is JSON support in Qt5 and all the related API description are listed so any programmer can seek them but no useful example or tutorials are there. I believe they should put more guides how to read and write JSON data sooner or later. For those who seeks any one tutorial, here comes very basic and little code snippet below to show how to read a JSON data.







If you run the above code, then u will see something like as below


QJsonValue(object, QJsonObject({"Alter": 42,"Hobbys": ["Reiten","Golfen","Lesen"],"Kinder": [],"Name": "Mustermann","Partner": null,"Vorname": "Max","männlich": true}) )

"QJsonObject of Inhaber: " QJsonObject({"Alter": 42,"Hobbys": ["Reiten","Golfen","Lesen"],"Kinder": [],"Name": "Mustermann","Partner": null,"Vorname": "Max","männlich": true})

"QJsonObject[Hobbys] of Inhaber: " QJsonValue(array, QJsonArray(["Reiten","Golfen","Lesen"]) )

"QJsonObject of Inhaber/Hobbys: " "Reiten"


Description:

The above JSON document has 5 QJsonObject and each object has a key&value pair. 

To retrieve an object with key "Inhaber" from the QJsonDocument, then we can use d.object().value(QString("Inhaber")).toObject().

if an object have only value without key, then you can refer it as QJsonArray and use the operator [] to access its array.


Hope this will give you any hint how to use JSON support with Qt5.

 

Posted by kevino
,

이번에도 CMake를 이용한 Qt5 용 프로젝트를 구성하는 방법에 대해 소개한다.


새롭게 이전 Qt 4.8버전하고 Qt5버전에서 Cmake 사용방법이 많이 바뀌어서 유의해야 할 부분을 중점으로 보여주기위한 글이므로 실제 프로젝트의 내용은 별거 없고 CmakeLists.txt파일 작성하는 부분을 중점적으로 보면 되겠다. 기본적인 정보는 다음의 링크를 참조해서 만들었다.


http://qt-project.org/doc/qt-5.0/qtdoc/cmake-manual.html#imported-targets


우선 시험 환경은 다음과 같다.


OS: Windows 7

CMake: version 2.8.11

Qt5: version 5.0.2


다른 내용은 별다른 것 없고 CMakeLists.txt를 주목해서 보는데 아래에 전체 소스를 표시하고 있다.


CMakeLists.txt



지금까지 연재해온 Cmake 시리즈와 다른 것은 별로 없고 눈여겨봐야 할 부분은 Visual Studio에서 디버깅시 보통의 경우 Qt5Widgetd.dll파일이 없다면서 실행에 실패할 것인데 이 경우 전역 변수 PATH에 Qt5 디렉토리를 추가해주면 문제가 해결될 것이나, 그렇지 않은 경우 VS용 프로젝트 파일의 설정값을 건드려서 정상동작하도록 만든 부분으로 그 설정은 아래와 같이 해주면 된다.


include(CreateLaunchers)

create_target_launcher(sample1 ENVIRONMENT  "PATH=${QTDIR}/bin")


실제로 동작가능한 프로젝트 파일은 아래에 올려두니 유용하게 쓰시기 바란다.


<추가> Linux에서 Qt5Widgets.cmake를 못찾는다는 오류가 나올때 해결방법

해당 qt5관련 cmake 모듈을 못찾는 경우에 발생한다. 이런 경우 CMAKE_PREFIX_PATH에 해당 위치를 지정해줘야 하는데 형식은 다음과 같다

if(UNIX)

set (CMAKE_PREFIX_PATH  <PATH_to_CmakeModules>)

endif(UNIX)


본인의 경우 다음과 같이 지정해주었다

set (CMAKE_PREFIX_PATH "/home/<userid>/Qt/5.1.0/gcc_64/lib/cmake")



sample1.7z


Posted by kevino
,