Arduino Modbus Slave

Hi All- I'm attempting to use the modbus slave library from here: http://sites.google.com/site/jpmzometa/arduino-mbrt/arduino-modbus-slave

Unfortunately I such a noob I'm not seeming to implement it correctly. The zip contains modbuslave.h and modbuslave.cpp. I am used to loading a .pde file. the .h file has what looks like a arduino sketch. But when i paste it into IDE and try to compile it throws all kinds of errors. It also calls(includes) the .h file so that seems circular and not correct to me.

I've been reading and googling for a bunch of hours now and each time I think I get it I dont.

Can somebody give me some tips to get this to actually compile so I can get to the next step in my hobby project? :'(

so every time im about to put this thing back on the shelf for another few months I break through.
I was able to get this to compile: using modbusslave from here: http://www.tucsni.nl/jee/
in modbusslave.cpp theres a sample sketch. After commenting out the … it compiles.

#include <ModbusSlave.h>
//Arduino sketch example with 2 holding regs:

void setup() 
{
        /* Modbus setup example, the master must use the same COM parameters */
        /* 115200 bps, 8N1, two-device network */
        regs[MB_REG0]=123;
        regs[MB_REG1]=456;
        init_mb_slave(115200, 'n', 0);
}


void loop() 
{
    /* This is all for the Modbus slave */
    start_mb_slave(MB_SLAVE, regs, MB_REGS);

    /* your code goes here */
 //   ...
    /* handle write event */
    if (written.num_regs) {
   ///     ....
        written.num_regs=0;
    }
}

whoo hoo.

Now obviously I’m supposed to put something in the “your code here” areas.

Sooooo, what goes there?
If I could find any kind of docs or somewhere to start but my searches dont bringup anything helpful.
My end game is to communicate with Mango

For posterity's sake: http://mango.serotoninsoftware.com/forum/posts/list/0/567.page#2721 is a full working example on Arduino ModBusSlave and Mango.

Thanks for the walkthrough, this made everything really easy.

Just wondering if you know how to bring back more than one variable. I have tried setting up a second register eg. regs[MB_REG1]=x,

but it seems to make Mango Unresponsive and my comm port disappears under the data source settings.

I like the mango interface, but bringing back only one variable seems like a waste.

Any ideas?

I got as far as writing that tutorial and realized I didnt want to use Mango. Switched to PHP serial and havent looked back. The mango forums are pretty good. you may want to ask over there.

Thanks anyways, I will give that a try.