Sign in to follow this  
Followers 0
BenJones

ModBUS and CRC code

39 posts in this topic

Hello there, quick question. I've set up a kWh meter with ModBUS protocol and it works fine. This was done in ladder as stated in the manual for the RS485ADP card. The code is attaached and works fine. I'm now trying to set up the communications for a controller for a chiller and cant get the comms to work. My thinking was just that I use the same code (as before for the kWh meter) but just change the stop bit, parity and baud rate to that of what is specified in the controller manual. In the controller manual it shows some CRC code. Do I have to program this or is all this comms stuff all done in the ladder code which I've already done ? My second question is...how do I wire it to the device ? All it says on the controller is +ve and -ve, so which one of the paris do I wire to these from the card. I've attached a diagram of how I've wired the card. I know that this is the correct way to wire the card. Many thanks in advance for any replies, Ben Modbus_comms.bmp Modbus_comms2.bmp Edited by BenJones

Share this post


Link to post
Share on other sites
Hi. When you use the ADPRW instructions you don't have to use the CRC commands, they are automaticly appplied with the ADPRW instructions. You should be able to simply use the same program that you have used before. The wiring for RS485 are always a bit confusing since there is no specific standard and the HW manufacturers use different wiring, but you'll just have to test it. Try both ways....

Share this post


Link to post
Share on other sites
Ben, First, a sense of deja vu does not leave me, because the same question I've seen on the forum. On the other hand, the information you have brought the issue is too muddled and insufficient to clearly understand what network you want to build and what kind of help you expect. That I see, is not normal to connect devices with dissimilar communication protocols in one network.

Share this post


Link to post
Share on other sites
Thank you for your replies. I'm using the same protocol (RTU modbus) and comms settings for all modules on the same network so there shouldn't be a problem there (the same Baud rate stop bits, parity etc). The comms settings are stated as the same in both the manual for the kWh meter and the chiller controller. The program works fine for the kWh meters. So, I have disconnected the kWh meters and only connected the chiller controller to the RS485 card. Same program used, same comm's settings and all I changed was the modbuss holding register address from where I read the data. Still cant get comms to the device. The problem I have is that the manufacturer has not specified the slave modbus address of the device, so I'm going through manually with the PLC program to try and work the modbus address out (tedious!). Any idea if theres a way of scanning for this address automatically with the PLC ? I've tried to put a counter in (to count from 1 to 247) but it stops sending data at about slave number 20 for some reason. Thanks for any comments in advance. Ben Edited by BenJones

Share this post


Link to post
Share on other sites
Check out ModScan32 for debugging Modbus comm. You can download it from their website: http://www.win-tech.com/html/demos.htm I know it's an old software, but it's really (REALLY) simple to use and does it's job.

Share this post


Link to post
Share on other sites
Kaare, Thank you for the link ! Very helpful ! I've downloaded and installed the software. When the software is open is shows COMM1 on the bottom left. I've inserted a D-SUB 9 to the back of the PC to COM PORT 1. I have soldered 2 wires onto pins 2 and 3 for the send and recieve. Is this the correct way to do it ? I know which registers to look in (40263) so I've gone to 'Holding Register', but it hasn't yet found the device. I shall keep trying. Thanks again, Ben

Share this post


Link to post
Share on other sites
You also need one wire for the ground (PIN 5).....

Share this post


Link to post
Share on other sites
Ok Kaare, The modbus slave device only has two inputs (+ve and -ve), how shall I ground the 0v on pin 5 ?

Share this post


Link to post
Share on other sites
Strange..... Are you sure that the slave device is a RS232 device??

Share this post


Link to post
Share on other sites
Hi ! No, its an RS485 connection. I have a USB-RS485 converter to go into the PC. I've set this to COM port 1 and all the comms settings (baud rate etc). I'n not sure which pins to connect on the D-SUB 9. I think I must have to wire 4 pins (TDx- to RDx- and TDx+ to RDx+). Is that correct ? I've looked on the internet and the RS485 pinouts for RDx+, RDx-, TDx+ and TDx- seem to change. I'll try and dig out the wiring diagram of the RS485 converter. Thanks again

Share this post


Link to post
Share on other sites
RS485 are sometimes a bit confusing since different vendors name the pins in different ways.... You'll just have to try the different connections, and possibly also try to switch + and -....

Share this post


Link to post
Share on other sites
Hello, Kaare, thanks for your replies...I managed to get it all sorted in the end. It was quite satisfying when it all started to work I then spent 2 days trying to get communication with another device (kWh meter) and then found out that it uses RS232 communication rather than RS485...not surprising it didn't work ! (I was told by my boss that it was 485 rather than 232, but then I checked the serial number and it was in fact 232! ) I have a question...is it possible to multidrop lots of RS232 slaves on a RS485 network using an RS485/RS232 converter for each slave ? It RS232 uses the MODBUS protocol. The master is an Fx3u485 ADP card. I have a feeling that a cheap RS485/RS232 converter wouldn't work and that a new PLC RS232 card will be required. Am I correct ? Ben Edited by BenJones

Share this post


Link to post
Share on other sites
You can use cheap RS232/RS485 converters to connect several RS232 devices. You will need 1 converter per slave, and you must ensure that each slave has it's own unique station number (Slave number / station number / slave ID). See attached picture.

Share this post


Link to post
Share on other sites
As far as I can recall; Modbus has a "broadcast" option. This is NOT recommended for your application but I guess it would have helped with finding the address of the unit in the first place. The diagram kaare_t has shown will work nicely - luckilly for you Modbus uses addresses in its datagram and is not simply a Point-to-point protocol.

Share this post


Link to post
Share on other sites
Thanks guys ! Thats great news. I can see these converters coming in very useful for the future when needing to multidrop RS232 slaves ! The converter arrived in the post today. Instructions for wiring are in chinese. I've got the slave working as RS232 so not worried about how to wire that. The converter on the RS485 side has a T/R+, T/R-, GND and +Vcc but it has no power supply. Do you think the converter will need to be powered (+Vcc connected to 5V) ?

Share this post


Link to post
Share on other sites
It's hard to say if the converter needs 5VDC (or 12VDC or 24VDC) but most likely it has to be powered....

Share this post


Link to post
Share on other sites
Ok thanks Kaare. Doesnt seem to work at the moment. Tried powering it, tried holding the RTS line at +Vcc. Hmmm. Will persist.

Share this post


Link to post
Share on other sites
Think I'm going to have to go down the route of getting an RS232 card (FX3u_232ADP_MB) as I cant get the 232 - 485 converter woking. This is the converter : http://www.sourcingmap.com/rs232-rs485-converter-p-7278.html?currency=GBP&utm_source=google&utm_medium=froogle&utm_campaign=ukfroogle I think this is because the 232 side of the converter needs a RTS line activated (maybe as well as CTS etc) and all I have from the RS232 MODBUS slave device is a 3 wire null model connection (only Rx, Tx and Gnd). I really dont completely understand how this converter works and what is requires to send recieve signal but tried to power it with 12V and cant recieve anything data to the PLC. If anytone has any ideas of how to get it to work please let me know. If i dont hear anything in the next couple of days, consider this cse closed and I'll just buy another PLC card. Best wishes to you all, Ben

Share this post


Link to post
Share on other sites
You can activate RTS/CTS by doing the following "Short-Cuts" in the 9Pin Dsub connector: 1-4-6 7-8 Try that on both the slave device and on the converter side....

Share this post


Link to post
Share on other sites
Already tried 'shorting' those pins on the converter side. The problem is that the slave device only has 3 wires emenating from it ! Only Rx, Tx and Gnd, so I cannot 'short' any of those pins together ! I've ordered an RS232 card...the simpler way Many thanks Kaare again !! Ben

Share this post


Link to post
Share on other sites
You are going to run into problems with the RS232 interface if your distance between PLC and device is > 15m. This distance is according to the standard RS232 specification. Also, you won't be able to have multiple devices if the PLC has a RS232 interface. Have a look at Moxa's A52/A53 (Transio A5253). Its inexpensive and has ALL the terminals you need.

Share this post


Link to post
Share on other sites
Hi thanks for that. You're correct. Ran into problems immediately ! The FX3u supports 2 connected cards (channel 1 and channel 2) but you can't run both clannels at the same time. Which is shoot. I didn't realise this. So I've got 6 slaves running on the RS485 network and one on the RS232. Not the best ! I've asked for a quote for the converter so that I can run them all on the 485 network. I'll order a converter like the one you mentioned. Thanks, Ben

Share this post


Link to post
Share on other sites
You can run both channels at the same time (simultanously). Use two RS2 instructions, 1 for channel1 and the second for channel2.

Share this post


Link to post
Share on other sites
But only single channel can be used with preprogrammed possibilities of Modbus communication. The second channel can be used with the function block to Modbus protocol master/or slave communication. Therefore the last will operate only if PLC work in Run mode.

Share this post


Link to post
Share on other sites
Brilliant, I was wondering what the RS2_M function block was for. If I can get both of these cards to run at the same time when the PLC is in RUN mode then my problem is sorted. Ok, I'll try and progrma the RS2_M function block then for CH2 (RS232 comms). The RS485 (CH1) card has been set up to read 6 slaves and works fine. This was done by using MOV commands and the ADPRW_READ function block. It says in the help file that it is used for 'No-protocol' mode (whatever that is). Will this still work if ModBUS protocol is used for both cards ? The only thing I'm worried about is that is says this in the manual for RS232 / RS485 comms "When both flags (B0 of D8401 and B0 of D8421) are turned on, priority will be given to CH1 and CH2 will no longer operate ! ?? See attachment. Many Thanks, Ben COMMS manual.bmp Edited by BenJones

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0