Request for suggestion regarding Modbus Communication
Home › Forums › MultiConnect OCG › Request for suggestion regarding Modbus Communication
- This topic has 15 replies, 4 voices, and was last updated 13 years, 1 month ago by JM K.
-
AuthorPosts
-
August 30, 2011 at 8:56 pm #2620JM KParticipant
Hi,
I want to use Modbus RTU to communicate with a PLC from the CDP Unit. I am using C to code my application and an EV2 Radio. I would like to know if the mts-io package is anyway helpful to accomplish this. Any suggestions on how to go about establishing communication would be very much appreciated.
Regards,
JM
September 1, 2011 at 2:02 pm #3337KevinModeratorare you looking at Modbus communication for Point to Point or Point to MultiPoint ?
If your PLC supports RS232, you can use the RS232 port on the CDP to communicate with PLC and then implement the Modbus protocol in Linux. There are many open source Modbus protocol library available on the internet.
If your PLC supports only RS485, then you might need to use an external adapter that can convert RS232 to RS485.
Regards,
Kevin
September 7, 2011 at 5:41 pm #3338JM KParticipantDear Kevin,
Thank you for the response. I am looking at Modbus communication from point to point. The PLC I am trying to use supports RS232. I would very much appreciate it if you could let me know of a few popularly used open source Modbus protocol libraries.
Best Regards,
JM
September 9, 2011 at 10:47 pm #3339JM KParticipantHi,
I have come across this modbus library, ‘libmodbus’. I have compiled and installed it on my system. The header file is located in /usr/local/include/modbus. I am using C to develop my code and my header files are located in corecdp-1.1.1/build/tmp/staging/armv5te-corecdp-linux-gunueabi/usr/include. I am confused as how to link the former header file (modbus). In order to bitbake my application successfully do I need to install libmodbus in this location(corecdp-1.1.1/build/tmp/staging/armv5te-corecdp-linux-gunueabi/usr/include)? I would very much appreciate it if someone could answer my question.
September 13, 2011 at 5:58 pm #3340Jesse GillesBlocked< I have come across this modbus library, ‘libmodbus’. I have compiled and installed it on my system.
It looks like there are bitbake recipes to build libmodbus in the OpenEmbedded git repository. I would suggest copying those into your tree and building libmodbus with bitbake.
Jesse
September 13, 2011 at 10:42 pm #3341JM KParticipantHi Jesse,
thank you very much for your response. I have so far been unsuccessful in my search for a compatible bitbake recipe however I will continue to search further. I would very much appreciate it if you could let me know any recipe that you might have across in the repository that could be used to build libmodbus.
Regards,
JM
September 14, 2011 at 3:13 pm #3342Jesse GillesBlockedTry the libmodbus recipes in the master branch of the OpenEmbedded git repository.
You can view them here:
http://git.openembedded.org/cgit.cgi/openembedded/tree/recipes/libmodbus
September 14, 2011 at 10:36 pm #3343JM KParticipantHi Jesse,
thank you very much for the link. When I tried to build libmodbus with the .bb files on the link somehow I have been getting a check sum error. I think I will contact the author of libmodbus on this one. I appreciate your help.
Regards,
JM
September 16, 2011 at 1:12 am #3344Brandon PedersenParticipantThe checksum error does not have to do with libmodbus. It has to do with the recipe. The latest version of bitbake handles checksums in the recipe differently than what we use for core CDP.
Modify the recipe and on the SRC_URI line add “;name=libmodbus” so the line will look like:
SRC_URI = “http://github.com/downloads/stephane/libmodbus/libmodbus-${PV}.tar.gz;name=libmodbus”
On the lines like SRC_URI[md5sum] = “…” change it to SRC_URI[libmodbus.md5sum] = “…”. Do this for both the md5sum and the sha256sum.
Hope that helps
September 16, 2011 at 5:06 pm #3345JM KParticipantHi Brandon,
thank you very much for your response. I modified the .bb file as per your suggestion however I got another error when I tried to bitbake libmodbus.
Here is the response I got:
jm@jm-desktop:~/Desktop/corecdp-1.1.1$ bitbake libmodbus
NOTE: Handling BitBake files: / (7982/7982) [100 %]
Parsing of 7982 .bb files complete (7672 cached, 310 parsed). 7723 targets, 327 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
ERROR: TaskFailed event exception, aborting
ERROR: Build of /home/jm/Desktop/corecdp-1.1.1/user-collection/recipes/libmodbus/libmodbus_3.0.1.bb do_setscene failed
NOTE: Preparing runqueue
NOTE: Executing runqueue
NOTE: Running task 280 of 448 (ID: 1, /home/jm/Desktop/corecdp-1.1.1/user-collection/recipes/libmodbus/libmodbus_3.0.1.bb, do_setscene)
ERROR: Task 1 (/home/jm/Desktop/corecdp-1.1.1/user-collection/recipes/libmodbus/libmodbus_3.0.1.bb, do_setscene) failed with 256
ERROR: ‘/home/jm/Desktop/corecdp-1.1.1/user-collection/recipes/libmodbus/libmodbus_3.0.1.bb’ failed
NOTE: package libmodbus-3.0.1-r15.15: task do_setscene: Started
ERROR: Function staging_helper failed
NOTE: Task failed: (‘function staging_helper failed’, ‘/home/jm/Desktop/corecdp-1.1.1/build/tmp/work/armv5te-corecdp-linux-gnueabi/libmodbus-3.0.1-r15.15/temp/log.staging_helper.13547’)
ERROR: Logfile of failure stored in: /home/jm/Desktop/corecdp-1.1.1/build/tmp/work/armv5te-corecdp-linux-gnueabi/libmodbus-3.0.1-r15.15/temp/log.staging_helper.13547
Log data follows:
| /home/jm/Desktop/corecdp-1.1.1/build/tmp/work/armv5te-corecdp-linux-gnueabi/libmodbus-3.0.1-r15.15/temp/run.staging_helper.13547: line 909: syntax error near unexpected token `else’
| ERROR: Function staging_helper failed
NOTE: package libmodbus-3.0.1-r15.15: task do_setscene: Failed
ERROR: TaskFailed event exception, aborting
ERROR: Build of /home/jm/Desktop/corecdp-1.1.1/user-collection/recipes/libmodbus/libmodbus_3.0.1.bb do_setscene failed
ERROR: Task 1 (/home/jm/Desktop/corecdp-1.1.1/user-collection/recipes/libmodbus/libmodbus_3.0.1.bb, do_setscene) failed with 256
ERROR: ‘/home/jm/Desktop/corecdp-1.1.1/user-collection/recipes/libmodbus/libmodbus_3.0.1.bb’ failed
ERROR: ‘/home/jm/Desktop/corecdp-1.1.1/user-collection/recipes/libmodbus/libmodbus_3.0.1.bb’ failed
jm@jm-desktop:~/Desktop/corecdp-1.1.1$
I modified the filename of the libmodbus_2.0.3.bb to libmodbus_3.0.1 (as 3.0.1 is the latest version of libmodbus) as well as PV = “3.0.1+git${SRCPV}”. I also made sure that I incremented INC_PR each time I bitabked libmodbus along with incrementing PR = “$INC_PR}.x” (where x is the numerical increment). Any suggestions would be very much appreciated. Thank you and have a great day.
Best Regards,
JM
September 19, 2011 at 10:04 pm #3346JM KParticipantDear Brandon,
thank you very much. I managed to successfully build libmodbus using bitbake. Another question I have is after a successful build how do I proceed with including the library, libmodbus in my C program? How to install it as a library that can run on the ARM platform? I would very much appreciate if you could let me know how to go about it. Thank you very much and have a great day.
Best Regards,
JM
September 27, 2011 at 4:14 am #3347Brandon PedersenParticipantSorry, I don’t really do too much C programming so including the library in your code is up to you. I would just develop it locally on your machine including the libraries as needed. Then make sure you are using automake tools to build your project, then you can create a really simple recipe for building your code on the platform as outlined here: http://www.multitech.net/developer/products/cellular-development-platform/development/writing-bitbake-recipes/
To make your recipe complete you will need to add DEPENDS += ” libmodbus ” to the recipe to ensure libmodbus is compiled prior to building your code and when you install your code on the CDP it will automatically require the libmodbus package to be installed as well.
If you just want to quickly install libmodbus on your CDP then after you have built libmodbus (or any new package), follow the steps outlined on this page to grab the package from your development machine: http://www.multitech.net/developer/products/cellular-development-platform/development/setting-up-a-package-feed/
The only thing I would change in that link is the yellow section, you don’t need to include the package in an image and build it, you can simply run ‘bitbake package-index’ and it will update the available packages
September 28, 2011 at 6:01 pm #3348JM KParticipantDear Kevin, Jesse Gilles and Brandon Pedersen. I wanted to take this opportunity to Thank you all for your invaluable suggestions.
Brandon,
thanks a lot for your help. I have written a successful recipe that accomplished the task of creating the modbus.h file in the usr/include directory. I have included modbus.h as a header file as I felt it’d be much easier for application development.
I do have another question related to bitbake. If I wanted to compile more than one file would I write a recipe like this? (here modbuscomm.c and modbus-rtu.c are the two files to be compiled) :
DESCRIPTION = “modbuscomm”
SECTION = “examples”
LICENSE = “GPL”
DEPENDS = “libesmtp libyaml”
PR = “r12”
SRC_URI = “file://mymodbuscomm.c
file://modbus-rtu.c
file://modbus-rtu.h “
S = “${WORKDIR}”
do_compile() {
${CC} ${CFLAGS} ${LDFLAGS} mymodbuscomm.c -o mymodbuscomm
${CC} ${CFLAGS} ${LDFLAGS} modbus-rtu.c -o modbus-rtu.c
}
do_install() {
install -d ${D}${bindir}
install -m 0755 mymodbuscomm ${D}${bindir}
install -m 0755 modbus-rtu ${D}${bindir}
}
I would appreciate it if you could let me know whether this recipe is good. Have a great day.
Best Regards,
JM
September 29, 2011 at 10:36 pm #3349JM KParticipantHi,
I am posting my question again. Please disregard my previous post (question).
I am trying to communicate with a plc which is a modbus slave through a C program. The program just opens and closes the connection as I basically wanted to test this function first before I proceeded any further:
# include “stdio.h”
# include “stdlib.h”
# include “modbus/modbus.h”
#define plc 0x01
int main(void)
{
modbus_param_t mb_param;
modbus_init_rtu(&mb_param,”/dev/ttyS2″,”none”,8,1);
if (modbus_connect(&mb_param) == -1) {
printf(“Not connectedn”);
exit(1);
}
modbus_close(&mb_param);
}
When I compile this program, I am faced with errors:
mymodbuscomm.c: In function ‘main’:
| mymodbuscomm.c:9: error: ‘modbus_param_t’ undeclared (first use in this function)
| mymodbuscomm.c:9: error: (Each undeclared identifier is reported only once
| mymodbuscomm.c:9: error: for each function it appears in.)
| mymodbuscomm.c:9: error: expected ‘;’ before ‘mb_param’
| mymodbuscomm.c:12: error: ‘mb_param’ undeclared (first use in this function)
| ERROR: Function do_compile failed
My bitbake recipe is as follows:
DESCRIPTION = “modbuscomm”
SECTION = “examples”
LICENSE = “GPL”
PR = “r12”
SRC_URI = “file://mymodbuscomm.c
file://modbus.c
file://modbus.h
file://modbus-data.c
file://modbus-rtu.c
file://modbus-rtu.h
file://modbus-tcp.c
file://modbus-tcp.h”
S = “${WORKDIR}”
do_compile() {
${CC} ${CFLAGS} ${LDFLAGS} mymodbuscomm.c -o mymodbuscomm
${CC} ${CFLAGS} ${LDFLAGS} modbus.c -o modbus
${CC} ${CFLAGS} ${LDFLAGS} modbus-data.c -o modbus-data
${CC} ${CFLAGS} ${LDFLAGS} modbus-rtu.c -o modbus-rtu
${CC} ${CFLAGS} ${LDFLAGS} modbus-tcp.c -o modbus-tcp
}
do_install() {
install -d ${D}${bindir}
install -m 0755 mymodbuscomm ${D}${bindir}
install -m 0755 modbus ${D}${bindir}
install -m 0755 modbus-data ${D}${bindir}
install -m 0755 modbus-rtu ${D}${bindir}
install -m 0755 modbus-tcp ${D}${bindir}
}
Any further suggestions on how to go about solving these errors or any suggestions regarding changes to the bitbake recipe would be very much appreciated. Thank you and have a great day.
Best Regards,
JM
October 5, 2011 at 3:58 am #3350Brandon PedersenParticipantLooks like you include statement might be wrong. You are including “modbus/modbus.h” but your recipe copies modbus.h to the working directory so the include should just be “modbus.h”
October 6, 2011 at 10:02 pm #3351JM KParticipantDear Brandon,
thanks for the response. I got it to work.
Best Regards,
JM
-
AuthorPosts
- You must be logged in to reply to this topic.