MBLogic Free Software Project - New Release (MBLogicEngine)

M

Thread Starter

Michael Griffin

I have a new release for my MBLogic Free Software project. This is a new
package called MBLogicEngine. This is a soft logic library which implements
the logic execution functions.

This version is a library, rather than a full stand-alone soft logic system.
It will eventually be integrated into MBServer to provide a complete soft
logic system. It is however also useful as a library which can be embedded
into a PC application, such as a test system that needs auxiliary PLC
functionality (e.g. to control conveyors, part loading, etc.).

This is a development release, and can still be considered alpha. The system
runs reliably, but the API is still subject to change at this time and will
be until it has been integrated into MBServer.

The concept for MBLogicEngine is to closely follow the architecture of
existing popular PLCs. It is also intended to be flexible enough to be easily
re-targetted to produce different versions supporting different styles of
PLCs. The current release closely follows the Koyo DL205 series. This was
selected as a development target because of the broad range of features
present. The overall project however is not limited to this, and it should be
possible to add emulation of other brands of PLC later.

The software is written in Python and should be platform independent. There
are release notes in a ReadMe.txt file. There is also a demo.py file which
shows the features (with explanations) and shows how the libraries can be
embedded into an application.

This release is probably mainly of interest to people who want to experiment
with it at this time as it still contains development debugging code. If
however anyone wishes to use it in a production application, I can strip this
out (it's just a few lines of code).

This is Free Software (GPLv3) and is available at the following location:

http://sourceforge.net/project/showfiles.php?group_id=228414
 
C

Curt Wuollet

That's great, Michael!

If I get some time, I'll take a look. Finally got high speed Internet 2 days ago and it quit tonight, so after switching everything to the new account, I had to switch it back.

Regards
cww
 
P
This is great!

I've just tested mbsyncserver and mbpoll and it works well.

I'm working on a automation project that involves Modbus TCP-communication, primarily between a Wago 750-841 PLC and an Advantec Adam 6051 I/O-device, and mbsyncserver is great when I need to simulate the server/slave at home.

I have a suggestion; could you initiate a wiki so we can get and contribute with help and docs?

And a question; is it possible to configure mbsyncserver so it responds with other than just zeroes?

Good luck with the development!
 
M

Michael Griffin

In reply to Per Stenebo: I see that I need to get my act together and activate some more of the features at SourceForge. I've had a few requests for this.

To get you started though (until I figure out SourceForge), make sure you are using the 2nd release for mbsyncserver and mbpoll. The main download page seems to be stuck at the first release, and you need to go to "browse all files" (or just go to the following release). http://sourceforge.net/project/showfiles.php?group_id=228414

I don't remember if mbsyncserver or mbpoll changed between release 1 and release 2, but there might be some minor bug fixes there.

Secondly, there is some web based documentation at http://mblogic.sourceforge.net/ The MBServer package also has some on-line documentation (from its built-in web server), but that doesn't directly apply to mbsyncserver. There is a page on mbsyncserver however at the link immediately above though.

To give you a direct answer to your question though, mbsyncserver has what I call a "unified" data table. That is, all the data types are overlaid on each other. This means that coil 9 and discrete input 9 are actually the same address, and they are both in register 0 (input and holding registers also overlap). If you write to coil 9 using function 5 (write coil), you should be able to read this back using function 1 (read coils). It will also turn on bit 9 in input and holding registers 0.

For example (starting up the server):

> Example:~/example$ ./mbasyncserver.py -p 8502
> MBAsyncServer version 0.91
> Starting server on port 8502. Tue Aug 5 19:26:02 2008
> Server running...

I started it up on port 8502, because 502 is not user accessable. If you want it to listen on 502, the web page on installation talks about port redirection using iptables. And you'll no doubt be pleased to know that I just fixed a formatting error in an example on that page which I noticed when I referred to it just now.

Here is an example of writing data to coil 9 using function 5:

> Example:~/example$ ./pollmb.py -p 8502 -f 5 -a 9 -q 1 -d 1
> Contacting Modbus host at localhost port 8502 timeout 60.0 sec.
> Sending Modbus function: 5, addr: 9, qty: 1, data: 1 for 1 polls at 1 msec
> 1: Reply was: function: 5, data: ff00

Here is an example of reading it back using function 1 (reading 16 coils starting at coil 0).

> Example:~/example$ ./pollmb.py -p 8502 -f 1 -a 0 -q 16
> Contacting Modbus host at localhost port 8502 timeout 60.0 sec.
> Sending Modbus function: 1, addr: 0, qty: 16, data: 0000 for 1 polls at 1
> msec
> 1: Reply was: function: 1, data: 0000000001000000

I get the same reply if I use function 2.

> Example:~/example$ ./pollmb.py -p 8502 -f 2 -a 0 -q 16
> Contacting Modbus host at localhost port 8502 timeout 60.0 sec.
> Sending Modbus function: 2, addr: 0, qty: 16, data: 0000 for 1 polls at 1
> msec
> 1: Reply was: function: 2, data: 0000000001000000

Here is reading it as a register using function 3:

> Example:~/example$ ./pollmb.py -p 8502 -f 3 -a 0 -q 1
> Contacting Modbus host at localhost port 8502 timeout 60.0 sec.
> Sending Modbus function: 3, addr: 0, qty: 1, data: 0000 for 1 polls
> at 1 msec
> 1: Reply was: function: 3, data: 0200

You get the same result if you use function 4, but I won't repeat that example here.

What I did for testing was to write test scripts in Python to read and write data to mbsyncserver's data table. So I would write to a data table address, and then read it back. I used the SimpleClient library (which was also used to create mbpoll) for this. If you deliberately want to make bad packets, that library gives you direct access to the raw messages through the "MakeRawRequest" and "SendRawRequest" methods. "MakeRawRequest" returns a string, which you can slice however you want, but you need to understand Modbus to know what to change. I didn't post the test scripts because they are ugly hacks which nobody would be able to figure out.

If you don't know Python, you can use bash scripts to call mbpoll with the correct parameters to preset data table addresses. There is a web page on mbpoll with examples. If this is still a problem for you, I can write a script for you.

I used mbsyncserver extensively when I was testing MBServer (which has both servers and multiple clients built into it). One of the things I did was to create a special version of mbsyncserver which had an auxiliary command set which let me do things like tell it to always return an exception (1, 2, 3, or 4). It also let me shut it down remotely. For some tests I would start up as many as 150 copies of mbsyncserver on different ports to simulate different multiple slaves. I didn't post this version, but I still have it if it is useful to you.

I used a "unified" data table for mbsyncserver for the reason that you mention. If they were separate, it wouldn't be possible to use the discrete input or input register area for anything because there would be no way to write to them. I overlay coils/discretes with registers to allow you to read or write an address as either bits or words, according to whatever is most convenient. The first 4096 registers hold the coils and discrete inputs (with 16 coils per register). Registers 4096 to 65535 are just registers.

For MBServer, the data table is separated into two halves. Coils and holding registers are overlaid with each other. Discrete inputs and input registers are overlaid with each other. The inputs and outputs are not overlain because MBServer is a combined server and client. The input areas are expected to be written to by the built-in clients going out and actively polling for data. However, some (256) of the coils are reserved for resetting faults in the built-in clients. This is documented on the web site, and also in the on-line (integrated web server) documentation.

A few more points to bring up are: 1) If you are not using MBServer, you don't need Twisted. mbsyncserver uses the asynccore library instead. This is a standard Python library. MBServer is based on Twisted because it needs the extended capabilities.

2) pollws is similar to mbpoll, but it won't talk to mbsyncserver. mbsyncserver is purely a Modbus/TCP server. pollws implements a Modbus-like web service protocol that I created. It does work with MBServer. This web service is of no interest to you for what you are presently doing however.

3) I am presently working on a soft logic library (MBLogicEngine). That will be integrated into MBServer as an optional sub-system to provide a complete soft logic system. I have most of the instructions and addressing modes done, and am working on the more difficult ones now. MBLogicEngine is also on the downloads page.

I have an additional point on this subject. MBServer ships with an example configuration file that sets it up into "loopback" mode. That is, there are 8 built-in clients configured which read and write the server's own data table. That is the same program "loops back" into itself. There is one client for each supported Modbus function.

This isn't actually a useful configuration. It was done to allow a set of client configurations to be demonstrated without requiring other servers to be available. To use it, you need to put in a realistic configuration. As it is, some of the addresses are being overwritten by these clients.

The status server is configured at port 8080. Once you have started up MBServer, you can access the help pages by pointing your web server to "http://localhost:8080" . The first part of the web page gives the current status of each of the servers and clients. The links to the help pages are at the bottom of the main status page. If you want to see the configuration and fault log for an individual client, just click on the appropriate connection name in the client list.

However, if all you need is a server for testing, mbasyncserver is simpler as the only configuration is a command line parameter indicating what port you wish to use. MBServer has a lot more capabilities which aren't needed just for simulating an I/O module.
 
Top