PDA

View Full Version : Modbus slave... - it needs to talk...



pacman
12-10-2009, 03:08 PM
I'm 'thinkering' with an idea. A device that has lots of pre-canned messages on a CF card (perhaps stored as wav files). Then you send serially (rs232/485) a modbus write command to a particular register. Prop then plays appropriate wav file.

So send '17d' to proptalker and then prop reads in file 17.wav and spits its out to a speaker.... or perhaps even says '17Say.wav' and displays '17tv.gif' on the video output...

Does anyone have any "I'm a modbus slave and here is register that you can write to" code they want to share?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
=================
The future is in our hands.
Which way to the future?
=================

evanh
12-12-2009, 08:28 AM
I could prolly dig up some example code from other languages/controller.

pacman
12-14-2009, 07:04 AM
Thanks for the offer. I have an 'array' of examples from other languages as well, but was hoping someone had done all the hard spin object stuff for me.

I guess I just got myself another task to go on the "jobs to do over the Christmas break" list - at least this is one I'll enjoy....

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
=================
The future is in our hands.
Which way to the future?
=================

JonnyMac
12-14-2009, 08:31 AM
Are you interfacing with other ModBus devices? If not, you would use any protocol. If yes, you'll have to conform to ModBus standards and write code for ASCII or RTU mode. I've done a tiny bit of research on the latter for industrial apps.

pacman
12-14-2009, 11:12 AM
@ JonnyMac,

Yes the other gear is ModBus. In the majority of applications I'm thinking it would be used in (I have some already in mind in the 'industrial' world I work in) it NEEDS to talk Modbus. And although most of the comms is RTU, I see no real need to stay in RTU. ASCII should be easier (and could probably be sent 'easier' out a standard PLC port).

And yes, I realise it needs to follow the standards, but as I would only be looking at fn06 (IIRC - write single register) then it shouldn't be too hard.... {how's that for famous last words..}

Modbus has so much mindspace that to go any other way (without supporting modbus as a 'default') would make it a very hard sell IMHO.

If it flys then other protocols might be considered in the future (3964R, DMX, WhateverTheCustomerAlreadyHas, etc, etc)

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
=================
The future is in our hands.
Which way to the future?
=================

JonnyMac
12-14-2009, 11:48 AM
So... you need a ModBus receiver, right? You're expecting something on the buss to send a "write" command to your device and then you "talk"? I don't have any way of sending ModBus to a Propeller but I am interested in writing a ModBus/RTU receiver driver for possible customer applications with a new product I'm developing (has a built-in RS-485 port).

The trick -- though not difficult -- will be mapping all the possible addresses the *could* be in a ModBus device to what you actually want to support. How were you thinking of handling that?

pacman
12-14-2009, 12:24 PM
JonnyMac said...
So... you need a ModBus receiver, right?


Yep


JonnyMac said...
You're expecting something on the buss to send a "write" command to your device and then you "talk"?


Two gold stars so far...


JonnyMac said...
I don't have any way of sending ModBus to a Propeller but I am interested in writing a ModBus/RTU receiver driver for possible customer applications with a new product I'm developing (has a built-in RS-485 port).


Lots of apps on the net to allow you to send modbus to a remote device. PM me if you need help finding them - some are good (and free) and some are rubbish.


JonnyMac said...
The trick -- though not difficult -- will be mapping all the possible addresses the *could* be in a ModBus device to what you actually want to support. How were you thinking of handling that?


No gold star for me http://forums.parallax.com/images/smilies/confused.gif I'm not sure what your asking here. The modbus specification allows you support a limited set of both commands and data registers. Not supporting all of them is perfectly OK. In actual fact ALL of the gear I use only supports a limited set of the complete modbus spec. No device I have used {to date} has supported all the spec... Typically you just get an exception code back (the most common I get is 03, but 01 and 02 make frequent appearances as well) if you do something 'bad'

For my application, I only need to other (master) device to be able to send to one of my registers. Lets call it 40001. Provided the remote master device stuffs a number in that register, then I 'play' that numbered message. Once played I would clear register 40001 to zero. I would have a default ID of {say} 7 - probably configurable via jump links (no links = 7, 1 link = 8, 2 links = 9, you get the idea)

The only other extension to this would be to add a single register that can be read by the master device (it issues a fn03) that gives a status back. eg: 0 is not playing message, 9999 = error, any other number is number of message being played. This status idea is not fully 'thinked' out at this stage (so any insight would be appreciated).

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
=================
The future is in our hands.
Which way to the future?
=================

JonnyMac
12-14-2009, 12:54 PM
Keep in mind that I'm new to this and am likely ill-informed. I just download the ModBus spec and will have a look. My goal is to create a generic driver. When I do I'll let it fly.

If you've got a recommendation of a PC app that I can work with (in Windows) I'd be thrilled.

Tubular
12-14-2009, 01:06 PM
There are pre built "modbus test" programs for the PC end, to send out a packet and view the response. I'll dig up some links.

For the receiving end on the Prop, the Modbus Spec makes the packet format easy to understand. Just be careful with the coil/register offsets having base 1... I think the first coil is at address 0001 instead of 0000, so its easy to miss by one.

I have some receiver code in Basic somewhere if you get stuck, but I think once you look at the Spec you'll be fine

Tubular
12-14-2009, 06:51 PM
Here's a couple to Modbus simulators that look ok. Not the same as the one I used to use (can't for the life of me remember the name of that one)

www.win-tech.com/html/modbus1.htm (http://www.win-tech.com/html/modbus1.htm)
www.hmisys.com/ (http://www.hmisys.com/)

Nick Mueller
12-14-2009, 08:39 PM
You can always implement just the subset you need for your application. You can even hardcode a single register if you want.
The only thing you should implement completely is sending negativ answers (command not implemented, register out of range etc.).
Then the slave-ID should be settable.
Timing-constrains should be observed to detect errors.

The easiest way is to start with ASCII because it is more readable. When that works, switch to RTU. RTU is a requirement, ASCII can be implemented. I can handle both, it's quite easy. Internally, I translate ASCII to RTU. Only difference is timing (detecting the start of a message) and the checksum. Replies are assembled in RTU and translated to ASCII if needed.

You also need to be able to select Baud-rates. And keep in mind, that RS232 is *not* the default!

I've written an almost complete Modbus-slave on the Propeller in Imagecraft's C with an RS232-interface. Then I ran out of HUB-RAM. http://forums.parallax.com/images/smilies/smile.gif
Anyhow, it works. Do a search for Modbus here in the forum. Sorry, won't publish code, but willing to answer any question.

I have tried some Modbus-test programs, but then I wrote my own simple one in C. I didn't want to pay ca$h.


HTH,
Nick

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!

The DIY Digital-Readout for mills, lathes etc.:
YADRO (http://www.yadro.de)

Reset_Vector
12-15-2009, 01:51 AM
Hi Pacman

I've implemented an "MODBUS slave" on a propeller powered PLC .
You can send command from a host to the propeller using the standard basic functions :

-03 (Read Holding registers)
-16 (Preset multiple registers)
-32 (derivative usage of func 16 for downloading the ladder program into the PLC)

So you can write or read "registers", but you can make as you want as you have decoded the MODBUS function.

The MODBUS reception is made by a dedicated COG and use fullduplexserial.spin object.

You can easely expand the functions.
I had to extract the MODBUS code from my source and I will post it on the forum, but give me a few time.

Best regards

Dave Matthews
11-01-2010, 10:10 PM
Thanks for your Code! I found it in another thread...

Dave KI4PSR