ModBUS over RS485

Started by jpacha, May 14, 2013, 02:57:54 PM

Previous topic - Next topic

jpacha

Hi everybody!
I'm new in this and I'm really excited with the possibilities of the A13-Olinuxino (and waiting for dual-core version ...   :P )
I'm developing a project in which I need to communicate with ModBUS slave devices, requesting data, and I have a A13-Olinuxino & MOD-RS485-ISO
The idea is sending a socket via 485 to the device and capture the socket with its response... Can anybody give me a rough guideline with esential steps for doing it?
I was googling for it, I have nt find clear instructions ... and I'm getting stuck with it!
Thank you in advance!

jeroends

have a look at libmodbus (http://libmodbus.org/). This will probably help you a lot further.
Libmodbus includes the needed libs to communicate with modbus devices over rs485 and ethernet. There are also a few examples included in the package and copiles without any problems on the a13 (and imx233). The only thing which you can bump into is that the installer doesn't place the libs in the right place. (have a look at http://leachy.homeip.net/olinuxino/install_dev.html)

BJFreeman

Fulltimer since 89

jpacha

Thanks for your support... I'm working with the approach of the library libmodbus

:P First question: what's the default device for the MOD-RS485ISO? Maybe ttyS0?

BJFreeman

#4
I2C the example in the link will explain

the other solution is to use the connector uart1 and porvide your own RS485 adapter
Fulltimer since 89

jpacha

Quote from: BJFreeman on May 15, 2013, 04:19:00 PM
I2C the example in the link will explain

the other solution is to use the connector uart1 and porvide your own RS485 adapter

I've tried with I2C without success. I've used a simplified version of the i2c code, and it throws the error "-1 of 14 bytes sended  Failed to send data: Communication error on send"

int main(int argc, char **argv)
{
int fd;
unsigned char buffer[14],buffer1[14];

buffer[0] = 0x00;
buffer[1] = 0x09;
buffer[2] = 0x00;
buffer[3] = 0x00;
buffer[4] = 0x00;
buffer[5] = 0x06;
buffer[6] = 0x01;
buffer[7] = 0x04;
buffer[8] = 0x00;
buffer[9] = 0x01;
buffer[10] = 0x00;
buffer[11] = 0x01;
buffer[12] = 0x4c;
buffer[13] = 0x8f;

I2C_Open(&fd, 0x48);

I2C_Send(&fd, buffer, 14);

    I2C_Read(&fd, buffer1, 14);

I2C_Close(&fd);

    printf("PeticiĆ³n: %s\n", buffer);
    printf("Respuesta: %s\n", buffer1);

return 0;
}


Can you help me with this?

jeroends

#6
Ok, had a little time to look more into it.
It's quite simple, first use the i2c part to set the desired direction mode, look at the delivered text file which is at the firmware zip.
Secondly use the serial port to send/receive date over rs485.

ie. ./mod-rs485-iso -c 0xA0 3  this will open your gates toward reading and writing, so when you put something on your serial line, you should recieve it back when the output jumpers are setted.

Please start with the deliverd example code because what I don't know what you 're trying to do with your code?!?

cKon

Hi,
   I am doing a similar thing,have been successful using a usb-485 converter,now want to use the md-rs-485.
Although i saw the open , close , send ,read functions , am confused on how to set the parameters like baudrate , stop bit , end bit and parity.Is it same like how i have done in the serial code?.pardon me if it seems silly,but i really need help.

Regards,

cKon

ozko

I successfully created a few projects with modbus on the android image...
With a lot of help of course :D
but Im using ftdi usb... and premade drivers so its a little easier...
PM me if you are interested :)