Hello! I'm way out of my league here but the company I work for has given me some freedom in researching a way of controlling two of our devices via either Modbus or just signal switching in general. I do have a bit of experience with modbus but only in terms of what it is and how it (in the rough lines) works in conjunction with most automation PLCs.
For this to work we have an Industruino D21G (as a Master device) from an earlier project and I figured I might use that one because it has an RS485 port built-in. This comes at a price though; you also have to use their Indio library which changes Serial to SerialUSB amongst other things. For the modbus to correctly work you also have to be able to set the TxEnable (DE/RE) pin, which I've found most (and specifically the general ArduinoModbus library) do not use.
To make things worse, most of the communication of said devices to control don't conform to the Modbus standard; it uses 8N1 and it's addressing is in decimals, not hexadecimals. Most of the libraries I've came across always format it in hex, that is the ones I was able to get at least to connect. Attached is a list of settings.
My programming skills are... well they exist and I'm able to read it correctly, but they are not by any means expert or intermediate level.
What I'm looking for is an Arduino library which is able to connect correctly and read/write our PCBs with these settings I've mentioned above and attached.
So far I've come across these (and tried all of them):
ArduinoModbus (unable to use due to TxEnablepin? I can't find a way of setting it)
Arduino RS485 library, I've tried directly connecting to it via RS485, I was able to connect but my programming skills are not adequate enough for me to use this library
simplemodbusng on github - this one I was able to connect with but I'm having a really hard time trying to figure out how to get and send data from it
Modbus Master Slave - smarmengol on github - this one doesn't have serial parity and lacks some features in the master branch
ModbusMaster (library channel and github) - This one looks like it can do all the tricks except the TxEnable pin
SensorModbusMaster - originally developped for sensors I was able to get it working while communicating to the PC (via a USB RS485), however upon connecting to our device it stopped working. I think it's due to the hex/decimal difference in the screenshot attached
rs485-asukiaaa - This one also looked promising but when I tried to use the example (edited to our device) I kept getting errors about a variable not being initialised and I haven't been able to figure out how and where
Industruino's example on modbus (linked here) - I tried using this Master's sketch but I have no clue whatsoever on how to alter the code for me to be able to request the data I needed, it's simply a bit confusing and I also have a suspicion it requests data in hex and not decimals
I'm at a loss here, if anyone knows any more libraries I could try which also provide some form of newbie-friendliness (or other threads maybe to enlighten my experience) I'd be super. Duper. Happy.
I had a quick look for an Industruino D21G and found the user manual for it. From what I could tell, you can program it just like any other Arduino type board. Its got an RS485 interface (pin D9 controls the direction of flow).
You can stay with Modbus or you can simply create your own protocol.
I've not played with Modbus libraries but as the it is generally associated with RS485 (as well as ethernet), I would be surprised if there wasn't some functionality in the library to control the direction of flow of the data.
Looking at the ModbusMaster code on github, look at the source code for the RS485 half duplex example in: examples/RS485_HalfDuplex/RS485_HalfDuplex.ino
You should see in the RS485_HalfDuplex.ino file, a couple of functions called preTransmission() and postTransmission(). These 2 functions drive the RE & DE pins to change the RS485 transceiver chip from receive to transmit (i.e preTransmission() ) and transmit to receive (i.e. postTransmission() ).
markd833:
I had a quick look for an Industruino D21G and found the user manual for it. From what I could tell, you can program it just like any other Arduino type board. Its got an RS485 interface (pin D9 controls the direction of flow).
You can stay with Modbus or you can simply create your own protocol.
I have to, because the device I want to talk to is using the modbus protocol.
markd833:
I've not played with Modbus libraries but as the it is generally associated with RS485 (as well as ethernet), I would be surprised if there wasn't some functionality in the library to control the direction of flow of the data.
Looking at the ModbusMaster code on github, look at the source code for the RS485 half duplex example in: examples/RS485_HalfDuplex/RS485_HalfDuplex.ino
You should see in the RS485_HalfDuplex.ino file, a couple of functions called preTransmission() and postTransmission(). These 2 functions drive the RE & DE pins to change the RS485 transceiver chip from receive to transmit (i.e preTransmission() ) and transmit to receive (i.e. postTransmission() ).
I have tried this. At first with their half duplex example I did get some output, yet I have no clue what it actually did read. After I've edited said sketch to include Indio.h and asking about a variable I will know (it is a temperature variable that I can read on the onboard screen); I get a 0 in return as to what I know it should be. (54 in our case) (see screenshot)
As you can also see in the screenshot I'm trying to demand IR bank 7. And only 1 IR and not multiple. (second screenshot shows the what the bank should contain). I've tried variations of the 7: 0x7, 7, 30007 (this one returns an illegal address exception)
markd833:
OK. I wonder why you got an "illegal address exception"?
If i'm reading your images correctly, then to read the water temperature, I would have thought that:
node.readInputRegisters( 30007, 1 );
would work.
I got it working. Apparently being indexed by 1 on the slave side means you actually gotta do -1 on the master side. Also judging by the pics, you'd be right. But apparently asking for
node.readInputRegisters( 6, 1 );
Is the correct one. I've also managed to finally get it to accept DE/EN pins being the same number, for some reason it didn't like that. This post is solved.