MBLogic Free Software Project

M

Thread Starter

Michael Griffin

I have a new software project that I have been working on, and I would like to
offer it for review and comment. It is a set of Free Software (GPLv3)
packages, available at the following location:

http://sourceforge.net/projects/mblogic/

The packages consist of the following:

MBServer - This is the main item. It is a combination of servers and clients
in a single integrated system which allows you to automatically poll multiple
remote servers, store the information in a data table, and then poll *that*
data table from another application. Right now, the main protocol supported
is Mobus/TCP, but other protocols can be added. It also supports a
Modbus-like web service. It has a web based status monitoring system, and web
based on-line help.

MBAsyncServer - This is a Modbus/TCP server. It can be useful if you need just
a server and want something simpler than MBServer.

MBPoll - This is a command line Modbus/TCP client. You can use it to read or
write Modbus/TCP servers. It also has a mode which allows you to poll
repeatedly at a specified rate, which can be useful when testing servers.
There is also a corresponding version for the Modbus-like web service.

SimpleClient - This is a library for writing your own Modbus/TCP clients.
There is also a corresponding version for the Modbus-like web service. (Both
of these are included in the MBPoll package.


These are on the second release. For some reason, SourceForge is at this time
only showing the first release on the front page of the project. You have to
click on "Browse all files" to see the second release. The changes between
the first and second release are very minor.

All of the above are written in Python (version 2.5). MBServer also needs the
Twisted communications framework. MBLogic, Python, and Twisted are all Free
Software. All three are multi-platform, and so should run on Linux, MacOS/X,
and MS Windows. MBLogic is developed on and targeted for Linux, but there is
nothing in it so far (or planned) which keeps it from running on other
operating systems.

The web site for the project (http://mblogic.sourceforge.net/) has more
information on the software (including where to download Python and Twisted
if you don't already have them). Most of the details for MBServer though, are
in the on-line help that comes with the package.


At present, I consider these packages to be "beta" grade. I have conducted my
own testing, but I am looking for more people to test them under different
conditions.

MBPoll and MBAsyncServer are complete so far as I can see. MBServer is
complete in so far as all features work, but I do intend to add more features
to it in future though.


The whole project is called MBLogic because the actual goal of the project is
a soft logic system, and the above are just byproducts of it. When complete,
the soft logic system (which is under current development) will be integrated
into MBServer, which means that package will be receiving additional
development to accommodate it.

The "MB" name doesn't actually mean anything other than that I lack
imagination. I needed the servers in order to help develop the soft logic
system, and I was using the Modbus protocol at the time so they got
called "MB". The system is intended to support multiple protocols though, so
it's not actually a "Modbus only" system. I wanted to push the project out
the door though, so the "MB" name has stuck so far.

All of these are Free Software, which means that you can do what you wish with
them, provided that you comply with the terms of the license (GPLv3). If you
are not familiar with the GPL software license, a very rough outline of it is
that you are can copy, sell, redistribute, modify, add to, (etc.) the
software, provided that you give any further recipients of it the complete
source code, and the same terms apply to any derivatives of it you may make
(see the copy of the GPL included with each for the authoritative terms).
 
Thanks for that software. I'm a student from Barcelona (Poltechnichal university of Catalunya), and i do my final project about free SCADA Systems. I have choosed your software, and just today, i have proved MBlogic, but i had a connection problem:

Connected outgoing client PLCUPC.
Lost connection on outgoing client PLCUPC.
Connected outgoing client PLCUPC.
Lost connection on outgoing client PLCUPC.

Any tip?
 
The system is connecting to device PLCUPS, but is then being disconnected by the device. Some devices seem to do this if you poll repeatedly for addresses which don't exist, or for function codes which it doesn't support.


The message: "Connected outgoing client PLCUPC." means the system successfully opened a connection to "PLCUPC".
The message: "Lost connection on outgoing client PLCUPC." means the system was disconnected from the other end.


If you have the system status monitor enabled (port 8080 on the default install), then if you point your web browser at "http://localhost:8080/MBStatusSystem.html" and then click on "Comms" in the menu at the top you will see a communications status web page. The device you are calling "PLCUPS" will be listed in a table along with its communications parameters. The address "localhost" in the above URL assumes your web browser is on the same computer as where you have installed MBLogic. Change that to the appropriate computer IP address if you are monitoring it from another computer.

If you click on the device name (PLCUPS), you will be taken to another web page which shows the configuration details and a fault log at the bottom of the page. If the PLCUPS device is reporting any Modbus exceptions, they will be listed there. Of course if PLCUPS isn't saying *why* it is disconnecting you, then all it will report is that an error occurred.

I would suggest checking the following:

1) Make sure you are talking to the correct IP address on the correct port.

2) Make sure you are using a function code that is supported by the device.

3) Make sure the address and quantity are within the addressable range of the device.

4) Start with a slow polling rate (cmdtime and repeattime), and increase it only after you have communications working correctly. The times are in milli-seconds.

5) Make sure the retry time (retrytime) is much larger (at least 10 times) than any normal delay. Just make this a very large number (e.g. 10000) to start with.


If you want to experiment with the connection to make sure the field device is reachable, there is another package called "MBTools" which has a command line client. You can use this to poll the end device to see what responses you get.
 
i've use your MBPOLL too, now i want to learn how that program working, coz in my project at my university must know about how modbus can talk with PLC and HMI..

soo..if can..i want a piece of your source code program that using for:
- read/write definition
- send display in row and column like excel

thanks,
dave
 
If what you are looking for is a Python library that you can use for writing your own program, then look in the "mblibs" package that came with MBLogic. That will include a module (directory) called "mbprotocols", which in turn includes something called SimpleClient. The PDF file that comes with it "SimpleClient.pdf" shows how to use the Modbus/TCP library, including examples. The MBPoll program uses an older version of this same library, so while it's a good guide, the parameters for the newer version a bit different.

Here's an example of using SimpleClient2:

Start up Python, and type the following (make sure that the "mbprotocols" directory is a subdirectory of your current directory):

from mbprotocols import ModbusTCPSimpleClient2

Now, let's define our communications parameters:

host = '127.0.0.1'
port = 8502
timeout = 10.0

In this example, I'm assuming that I have a Modbus/TCP server running on my own PC at port 8502. I'm running "mbasyncserver" on my PC for this test. Substitute in the appropriate values if you are using an actual PLC (remember that the standard Modbus/TCP port is 502, not 8502).

Now, let's create an acutal client:

client = ModbusTCPSimpleClient2.ModbusTCPSimpleClient(host, port, timeout)

That should have created a client and opened a connection to the Modbus/TCP server (e.g. PLC). If you got an error such as "socket.error: [Errno 111] Connection refused", then either you have an incorrect parameter, or your server is not accepting connections for some reason.

Now, let's create a message. First, let's define our message parameters:

TransID = 1
UnitID = 1
FunctionCode = 1
Addr = 567
Qty = 8

Now let's send a request:
client.SendRequest(TransID, UnitID, FunctionCode, Addr, Qty)
And receive the response:
TransID, Funct, Address, Qty, Data, ExCode = client.ReceiveResponse()

Let's look at the response:
print TransID, Funct, Address, Qty, ExCode

That should give us the following:
1 1 0 1 0

The data will be in binary format, so we have to translate that to something we can handle more easily.

x = ModbusDataLib.bin2boollist(Data)
print x

We should see the following:
[False, False, False, False, False, False, False, False]

Here is another example where some bits were actually turned on:
[True, False, False, True, False, False, False, True]

That was a simple example of reading some coil values. You can do the same with discrete inputs or registers, and you can also write data.

As for your question about "send display in row and column like excel", I'm afraid you're going to have to explain a bit further what you are trying to do. Are you trying to read from or write to a file? That is quite simple to do, but I'm not really sure just what it is you want to do.
 
Top