Modbus programming

A

Thread Starter

anyone

hello sir,
myself nachiket, just a student of engg college.

I've been given a project on modbus and hence contains a master and a slave. I wish to write a program for the communication betwen them. The packet formation, error check, recieving, transmission etc. I request you to help me by just tellin whether it is possible to write such a program in c and which library does it use....

thanking you for your kind support.
 
Yes it is possible to write such a program in C. For building the packets, you will just need a copy of the Modbus specification (see the link at the top of http://www.modbus.org/tech.php) and ordinary C instructions which let you manipulate bytes.

For sending and receiving, you will need a serial port or Ethernet socket library (depending on which type of Modbus you use).

 
M

mehdi chourib

hi,
I am actually developing modbus/tcp in c ...
But I don't understand one thing ...are u searching for one protocol here or would you help people who use to develop modbus?

regards
M.C.
 
M

Mehdi chourib

The 1st link doesn't work, can't you put the modbus/tcp project on server that you give the adress....thank you in advance...
 
The first link works fine. You just have to remove the space character from between the "Modbus" and the ".html" portions of it.

Spaces are a normal problem when posting URLs. Most web forums will automatically insert spaces into very long strings (e.g. URLs) to avoid disrupting the page formatting (so your web browser can wrap the words instead of trying to widen the page).

 
i m also engg. student using modbus for communication between microcontroller and pc.......
i m not getting how to use c language for modbus protocol......
should i need some form of simulation s/w?
can i use VB ??
please help me out.........
 
To the various students asking questions: Before you start writing a program, you first have to design the program. Start writing down point by point what you need to do. Take each of those points and add detail to them.

When you have a list of things your program needs to do, you will have criteria by which to judge what software to use to write your program.

To make Modbus messages, you need a programming language that will let you make strings or arrays of bytes. Be careful when using any Microsoft software. They use non-standard character sets and different parts of their OS use different ones (it's a bit of a mess). You need to be able to manipulate each actual *byte* value in an array of bytes.

To make a Modbus message, you figure out what string of byte values you need by reading the Modbus spec (read it, it has good explanations). Then you need to figure out how to write a software function to put that message together. This part shouldn't be hard. If you were writing it in Python, it would be one line of code (not counting error checking of parameters). Decoding a reply is the same thing, but in reverse (but you have to do a bit more checking of the results for errors). If you are writing it in something like VB it probably would take a lot more code to do the same thing, but the principle is the same.

To send the messages, you will need either a serial I/O library or an Ethernet socket library, depending upon whether you are using Modbus/RTU, Modbus/ASCII, or Modbus/TCP. In either case, you are just sending the message that you previously constructed. It's just like sending your name (except your name isn't a valid Modbus message). Receiving the reply is the same, except in reverse.

As for the rest of your program (whatever it does), I can't comment on that.
 
M

Mehdi chourib

Hello,

Thank you for the 2 links you have sent me, but it is writen in C++ and unfortunly my pic microcontroller supports C language only.
Do yo have the same protocole read in C?
Thank you in advance.

Regards,
Mehdi Chourib.
 
>unfortunly my pic microcontroller
>supports C language only.

That isn't a problem.
Simply convert the C++ code to ANSI-C.
- methods become functions
- class variables become static variables

The disadvantage of using ANSI-C will be,
that there will only be 1 modbus connection possible if you simply do what i said above.

You can also have any number of modbus if you define a typedef struct for the class variables and use that struct in every call to the functions. Thus your ANSI-C functions can operate on the (formerly) class variables.
 
I wrote client and server programs in Visual Basic that uses a PC com port (RS232) to communicate via Modbus with a Modicon Micro PLC.

These programs outline the basis for the Modbus protocol and should be easily translated to other programming languages.

Follow the link below to get the program examples.
http://www.protechs-online.com/programming.htm
 
sir,
my qestion is similar to previos ones. am doing a project on implementing MODBUS protocol for interfacing ATmega32 to PC.
Assuming i know nothing abt implementing a protocol. pls giude me as to hw to proceed.
I went thru the data sheets but dont seem to understand much.. i knw little abt USART commn which we use here.. setting the baud rates is fine.. if i hav the msg format for modbus/rtu hw should i be going ahead...
i tried to get info frm various sources, but in vain. i donno if am thinking in rite direction, am confused.. if u think its feasible pls pls pls do reply. thanking you...
 
Top