Async Modbus

Hi mates! I need your help.

Using an Arduino Mega to build an Electrical Submersible Pump Fuzzy Controller.

The application implements a modbus master to query peripherals in one serial port, and a modbus slave to answer scada system in the other port.

No problems so far, but whenever any of the peripherals becomes unresponsive, the synchronicity of the master modbus makes the system hang waiting for response, thus delaying the control program and missing scada requests.

What do i need? An asynchronous modbus master implementation, so that i could query peripherals and move on, and treat the results later on data arrival or timeout, but without hanging waiting for response.

Any directions?

Thanks in advance. Best regards.

Maybe something is deadlocking (e.g. writing to UART when inside I2C event). You need to figure out what it is or show the code.

Looking at a MCP2551 CAN transceiver

http://ww1.microchip.com/downloads/en/DeviceDoc/20001667G.pdf

I can see it looks a lot like an RS485 transceiver... which brings us to the next issue, what sort of bus is being used. At least the Fuzzy part of the design is clear.

"Fuzzy", really is that a good meme to mix with "Electrical Submersible Pump Controller".

Sounds like a poor implementation of the modbus library, either within your program or within the library. Which library would that be?

I have modbus setup to scan for new devices on the bus, which means it frequently attempts to connect to devices that do not exist. The same unit also provides data to the serial monitor and SD card, and I don’t have an issue with missing data while waiting to timeout on devices that are not responsive (do not exist).

adwsystems: Sounds like a poor implementation of the modbus library, either within your program or within the library. Which library would that be?

I have modbus setup to scan for new devices on the bus, which means it frequently attempts to connect to devices that do not exist. The same unit also provides data to the serial monitor and SD card, and I don't have an issue with missing data while waiting to timeout on devices that are not responsive (do not exist).

I am pretty sure you are right and that you have the solution, we just need to clarify the problem. Could you try to guide me thru this?

The modbus master lib im using is this: https://sites.google.com/site/jpmzometa/arduino-mbrt/arduino-modbus-master

And here is the relevant part of my code (i believe so):

... ModbusMaster master; ... void setup () { ... Serial1.begin(9600); ... }

void loop { ... static uint8_t result;

master.begin(PIT_MDB_ADDR, Serial1);

// slave: read (6) 16-bit registers starting at register 2 to RX buffer result = master.readHoldingRegisters(PIT_MAP_FIRST_REG, PIT_MAP_SIZE);

// do something with data if read is successful if (result == master.ku8MBSuccess) { //do some basic stuff } ... }

Could you suggest something? Also i just found an improved (maybe) implementation of the lib in:

https://github.com/andresarmento/modbus-arduino Maybe i should check its docs. EDIT: nevermind. doc says master is under devel since 2015.

Check this library, it implements the master using a polling, so non-blocking. It might fit your needs. The best: the same library also implements the slave part, so you don’t need the space for two libraries.

pylon: Check this library, it implements the master using a polling, so non-blocking. It might fit your needs. The best: the same library also implements the slave part, so you don't need the space for two libraries.

Thanks mate! gonna test it asap and tell the results!