Author Topic: MODBUS simulation/testing on PC  (Read 32829 times)

Offline jezc

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
MODBUS simulation/testing on PC
« on: September 01, 2009, 03:39:10 PM »
Hi Mark,

Following some comments made by some of your many satisfied customers/users, I was wondering how much of the MODBUS capability was supported on the simulator?

We currently support a subset of the commands for MODBUS RTU over serial line and we're interested in widening this to include MODBUS over IP.

The next question for us is how then to test the additional capability - we have software to independently verify our MODBUS RTU over serial line support but I'm wondering how much need we would have for this for MODBUS over IP?

Basically I guess I'm asking how we can go beyond using the simulation on the PC for testing?
Could we for instance use some of the code in the simulation as the basis for our own MODBUS over IP test software on the PC? Or would we really need to buy some other software to cover this? If so, do you have any recommendations we could follow?

Cheers,
    JezC

Offline mhoneywill

  • Full Member
  • ***
  • Posts: 172
    • View Profile
Re: MODBUS simulation/testing on PC
« Reply #1 on: September 01, 2009, 05:05:45 PM »
Hi Jez,

I'm one of the users of the Modbus module and I can fully use it in the simulator. I use various modbus applications to connected to my simulated device via both serial and Ethernet.

To connected to the device I have used a handy little tester from here
http://omniflow.com/Products/SoftwareDownloads/ModbusTester_install_v2.11.zip

I've also written some simple VB6 programs using this ActiveX control
http://www.modbustools.com/modbus_activex.asp

Note if you are writing your own VB6 programs, you might want to look at the comm32 OCX control, which improves on the standard MSCOMM32.OCX, one key feature is that it supports access to com ports higher than com16. see http://www.comm32.com/

When testing RTU and ASCII protocols on the PC I've been using Com0Com http://com0com.sourceforge.net/ to create virtual serial port pars with one port of the pair connected to my uTasker simulation and the other connected to this simulator http://www.plcsimulator.org

I've also used the terminal emulator Realterm http://realterm.sourceforge.net/ I'm using version V2.0.0.65 from here http://www.i2cchip.com/realterm/
Realterm has a bit of a clunky interface but the killer tool for me is that for a small donation you can get a spy driver that will allow you to spy on communications on a com port (Virtual or real).

Another powerful tool to monitor serial port comms can be found here http://www.serial-port-monitor.com/

Also to answer your question yes you could use the code in uTasker to build your own test masters and clients. But if there was a bug in the uTasker modbus code (heaven forbid ;-) ) you might not be exposing it.

Hope the above helps

Cheers

Martin Honeywill
« Last Edit: June 16, 2010, 08:34:38 AM by mhoneywill »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2979
    • View Profile
    • uTasker
Re: MODBUS simulation/testing on PC
« Reply #2 on: September 01, 2009, 05:12:29 PM »
Hi Jez

The uTasker simulator allows MODBUS RTU/ASCII master/slave and MODBUS TCP master/slave to be simulated/tested.

There are various programs available for testing over TCP - some free ones and some which can be purchased. The wonderful thing about MODBUS TCP however is that Wireshark can interpret the content of such Ethernet frames (displays MODBUS content) and so allows simple verification.

If you look at the uTasker MODBUS User's Guide http://www.utasker.com/docs/MODBUS/uTasker_MODBUS.PDF (chapter 20) you will see that the demo MODBUS project actually tests itself by including a TCP master which establishes a link to a TCP slave and tests MODBUS function queries and commands. The MODBUS TCP slave then routes the received queries to a MODBUS serial master which sends them over the serial interface (ASCII or RTU). By looping the COM ports the query arrives at a MODBUS serial slave which finally responds to the query or executes its commands. The answer is then routed back through the reverse path and arrives at the MODBUS TCP master, where it is displayed and the next test in the sequence kick off.

This is only possible in the simulator since it allows the TCP master to send to a slave at its own IP address (which is not normally possible) but the same test works if the master is on a second board (or second simulator) and communicates with a different IP address. The demo project can therefore also be used as a TCP master to test remote TCP slaves (with or without the routing via a further MODBUS serial link) - either in the form of the simulator running or the code running on a real hardware. All transactions can be easily followed by Wireshark.

The uTasker MODBUS module was in fact developed without any further MODBUS SW support; purely allowing it to test itself as described above. However the project was also used in parallel in a small number of Beta projects (these were real industrial developments) where a number of bugs were indeed found along the way and then corrected as appropriate. However the bugs were often things that were also not necessarily obvious even if working with a PC based MODBUS test SW since the communication was generally correct but the content not (the MODBUS protocol analyzer can't tell if the content has an incorrect value - eg. a coil is signaled at state '1' when it was really at state '0') so there was no great need for anything else.

One further advantage of this setup for real development is that when a break point is set in the slave code the TCP communication doesn't breakdown, or the MODBUS master timeout because no response is quickly received (this is because the master is also frozen!!). In fact this is a major advantage in comparison to working with a MODBUS analyzer during this phase of the work. For other tests there is however no reason not to use a MODBUS test program/analyzer if found useful.

There is quite a list of MODBUS test programs on the MODBUS org site: http://www.modbus.org/tech.php

The MODBUS solution is otherwise quite (or very?) comprehensive (apart from a couple of public functions which have never been used yet - mainly read and write of records: full list of supported and non-supported public functions ate in Appendix A). I think that the fact that it is fully configurable to perform both master and/or slave functions on multiple serial and/or TCP interfaces, as well as its almost unlimited routing and gateway capabilities (note that I didn't think up these uses but instead there were quite a variety of such requirements in the first Beta projects alone) makes it very attractive.

The project is also a living project with any new functionality ideas or needs being added when and if possible (for example the project now also supports slave ASCII serial operation on a USB CDC interface - also a real project requirement, which in fact only required an addition 3 program lines in the MODBUS module itself, but of course the available of CDC class in the uTasker USB section).

Regards

Mark




Offline jezc

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: MODBUS simulation/testing on PC
« Reply #3 on: September 01, 2009, 10:24:32 PM »
Hi Mark & Martin,

Many thanks to you both for such complete and helpful responses!

It certainly sounds like there's plenty of options for us to use to validate/test the MODBUS over IP operation - I guess the first step is to get the licenses sorted so that we can test the capability on a dev kit for ourselves!

I can hardly wait to sort this out and see how well it works for our applications!

Thanks to you both once again - the support puts many commercial products to shame!

Cheers,
    JezC

Offline jezc

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: MODBUS simulation/testing on PC
« Reply #4 on: October 03, 2009, 07:52:14 PM »
Hi Mark,

I've been trying to run the standard modbus_app.c in the simulator as a starting point (using the LP23xx project configured for Olimex LPC2478 dev board).

I've installed COM0COM (as my laptop doesn't have any real serial ports) as well as Wireshark, and I can see the MODBUS packets on the Ethernet connection in Wireshark but so far I've not managed to see these being forwarded onto the serial port or any responses to these packets.

Can you please suggest what steps I've missed out? I'm sure it's something basic (probably with the serial ports & COM0COM) that I've (not) done.

Any help will be most welcome!

Cheers,
    JezC

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2979
    • View Profile
    • uTasker
Re: MODBUS simulation/testing on PC
« Reply #5 on: October 04, 2009, 10:32:16 AM »
Hi Jez

I just took the LPC23XX project and added the MODBUS module.
In config.h I activated MODBUS by enabling USE_MODBUS (SERIAL_INTERFACE was already defined).
In app_hw_lpc23xx I checked the UART settings and found them to be as follows:
MODBUS_UART_0   2 - SERIAL_PORT_2   11
MODBUS_UART_1   3 - SERIAL_PORT_3   12
DEMO_UART 0 - SERIAL_PORT_0   4


These are setting the two MODBUS serial ports (as used by the MODBUS demo application) to UARTs 2 and 3 on the chip and the debug output to UART 0 [note that some chips with only 2 UARTs need to disable DEMO_UART when testing MODBUS so that the 2 available ones can be used for it].

The MODBUS serial ports are being mapped to COM ports 11 and 12. On my PC I have com0com performing a virtual loop back between these two. When I run this I get the expected result.

Check carefully that your com0com configuration matches the set up and change either accordingly if this is not the case.
To check just the UART transmission I find it useful to set the serial MODBUS port to ASCII mode and then open a terminal emulator on COM 12 - then anything sent over MODBUS serial port 0 (over COM 11) will be seen in the terminal. The loop back will of course not work since the terminal is blocking it, but it is good to verify that data is really being sent.

Also watch debug output (on the debug output or via TELNET) since there is some MODBUS debug out, such as when a slave doesn't respond.

Regards

Mark

Offline jezc

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: MODBUS simulation/testing on PC
« Reply #6 on: October 04, 2009, 09:11:43 PM »
Hi Mark,

Brilliant - I'd got the serial port setup wrong, reverting back to the original settings and re-configuring COM0COM to suit has done the trick!

I can now see both the MODBUS queries and responses in Wireshark - great!

Thanks - feel a bit daft for not sorting this out for myself.

Cheers,
    JezC

Offline shelest

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: MODBUS simulation/testing on PC
« Reply #7 on: October 26, 2010, 08:33:43 PM »
I use Modbus Reader for testing RTU and TCP. See www.kurysoft.com

Offline mhoneywill

  • Full Member
  • ***
  • Posts: 172
    • View Profile
Re: MODBUS simulation/testing on PC
« Reply #8 on: October 27, 2010, 07:42:45 AM »
Does this mean you also have Modbus Constructor? I use the mbaxp.ocx control from here http://www.modbustools.com/modbus_activex.asp and have made my own tools in VB6.

For a free tool I use http://omniflow.com/Products/SoftwareDownloads/ModbusTester_install_v2.11.zip

Cheers

Martin

Offline HDowns

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: MODBUS simulation/testing on PC
« Reply #9 on: November 24, 2010, 07:22:32 AM »
Another serial port monitor software has the MODBUS RTU/ASCII slave/mater emulation plugin. Allows to debug MODBUS traffic in the sniffer mode too. Recommend.

--
Helen

Offline carlos789

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: MODBUS simulation/testing on PC
« Reply #10 on: October 02, 2015, 10:43:17 PM »
Hi Mark:
I am using Keil compiler, and the project compiles fine.
But wanting to simulate the project with Visual Studio, leave the following errors:

1>------ Build started: Project: uTasker, Configuration: uTasker Kinetis plus GNU build Win32 ------
1>kinetis.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
1>modbus_app.obj : error LNK2019: unresolved external symbol _fnMODBUS_transmit referenced in function _fnMODBUSuserFunction
1>modbus_app.obj : error LNK2019: unresolved external symbol _fnMODBUS_Master_send referenced in function _fnModbusTest
1>modbus_app.obj : error LNK2019: unresolved external symbol _fnInitialiseMODBUS_port referenced in function _fnInitModbus
1>Tty_drv.obj : error LNK2019: unresolved external symbol _fnRetrigger_T1_5_monitor referenced in function _fnSciRxByte
1>WinSim.obj : error LNK2001: unresolved external symbol _fnMODBUS
1>.\uTasker___Win32_uTasker_Kinetis_plus_GCC_build\uTasker.exe : fatal error LNK1120: 5 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I need to add something?
Cheers
Carlos


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2979
    • View Profile
    • uTasker
Re: MODBUS simulation/testing on PC
« Reply #11 on: October 02, 2015, 11:57:44 PM »
Carlos

If Keil builds correctly you must have the Modbus files at the correct location (in uTasker\MODBUS\). Make sure that you have overwritten any dummy files there to be sure.
Also open the file in VS from its file explorere to ensure that it is using the correct one (and not the dummy one used as a place-holder).
Finally, command a re-build to ensure that the new file is being compiled and the linker should then find these missing functions.

Regards

Mark