Sign in to follow this  
Followers 0
soundwave

CJ1M Slave on Existing Modbus Network

43 posts in this topic

Hello All, I wanted some help understanding the concepts involved with an omron PLC acting as a slave on an existing modbus network that contains Allen Bradley and SCADA nodes ( no omrons i believe) I have - CJ1M CPU23, SCU41 comms card, ModbusV5 (thanks to sleepy wombat) , CX-1 with Protocol 1.6. Serial port 1 of the SCU41 card is used as a master that polls two power meters on a new modbus network. I have this program working now and am ready to take the next step which is using Serial Port 2 to connect to an existing modbus network. The PLC will be seen as a slave on this existing network. I plan to connect Serial Port 2 of a SCU41 card ( via a RS232C to 485 converter ) to the existing modbus network. I would be required to send a block of 10 words back to the master when requested. These words will contain power measurements in real time. So the questions are as follows and relate to the PLC being a slave on an existing modbus network. I am not familiar with the modbus protocol but have now had a little experience with the PCMR instruction. -------------------------------------------------------- Assuming I have a modbus node address of 1 in the existing network. The master will send a message statement node 1, read 10 words, from starting address D100, modbus command 03 01 03 0100 10 (probably not the message statement but for now…) 1…………………………………… First of all how do I know when this message is sent so that I can execute the PCMR instruction? Basically I am asking how I listen for this command or does the PCMR do this for me. 2…………………………………….. Once I have heard the broadcast how do I identify it is for me? Or again is this part of the PCMR instruction? 3………………………………….. Lets assume I have verified the data is for me. I then should check that the data address is what I was expecting. I should also check that the number of words does not exceed what I was expecting. I am sure I can specify where and how many address the master can request. And data memory ie Dxxx is the address where i could store both the request for words and words to be transmitted? 4……………………………………. Lets Assume I am happy the request is for a valid address and valid number of words. Would I then execute the PCMR instruction? This would then transmit the number of words requested from the address requested (both previously known) The transmission is complete and I wouldn’t know if the master received the words or not (two wire). But I could test this with a test master at work when i complete the program. ---------------------------------------------------------------------------------------------- As I previously stated I am now a little familiar with the PCMR instruction but I plan to begin a program tomorrow for teh PLC as a slave. I would like a better understanding of what was required before I delve in too deep with the wrong concepts. Thanks Gents,

Share this post


Link to post
Share on other sites
Hi again, Have a look at this protocol... I wrote it to respond to only two specific modbus requests, which may suit your application better than a generic slave. (ie you can specify the modbus requests to which a response will be sent in the matrix, and ignore any other requests)(it also requires less code (both ladder and macro) than implementing a generic Modbus master/slave) The protocol always sends the same two replys (with variable data included) The advantage of this is that the PLC will not send any other data than that intended. You can use the Trace tool to identify the Modbus request to which you wish to reply, then simply write this as a 'receive message'. Hope this helps. s.psw Edited by Nibroc

Share this post


Link to post
Share on other sites
Does the ModbusPM.cxp by sleepy wombat the answer the questions above ???? The following is my limited understanding of the modbus slave routine supplied by sleepy wombat (ModbusPM.cxp ) Starting from the top down… INIT [Program]: ------Common [section]: RUNG 1 I leave the number of words Nbr_PCMR_Word as 2. This specifies the words I am expecting. I change the Slave_Nbr to the node address I am given on the existing network. RUNG 2 The PCMR instruction is listening? It therefore continuously listens by repeatedly executing the instruction. ReadWrite [Program]: ------Read_03_04 [section]: The PCMR instruction in the Common [section] is executed continuously. When the PCMR instruction receives a valid request with my node number the request is executed. An it is stored starting at W0 and looks like W0 ignore W1 address of words requested W2 number of words requested So my action is the first rung RUNG 1 I will move the address requested stored in W0 to the Word_address ( which forms the response) RUNG 2 I will then move a quantity of data from XFER so Number of words – W2 the number of words requested ( I received this in the PCMR instruction) First source word- The first word address is specified in W0 (Indirect addressing !!) First destination- W5 the location where I shall move the words requested RUNG 3 Since we must deal in bytes and not words we multiply the quantity of data requested by two. So we multiply the number in quantity of data by two giving us bytes. This must be required by modbus, right? RUNG 4 We then release port 2 ReadWrite [Program]: ------Write_06 [section]: RUNG 1 The program would ignore this section because I have received a modbus read 03 / 04 statement ReadWrite [Program]: ------Write_10 [section]: RUNG 1 The program would ignore the first rung because again RUNG 2 I assume 1523.09 is enabled because we released P2_Wait_Release earlier. So we therefore execute this instruction. Firstly we move first_data I am unsure on this for now I will ignore. Secondly we move the address specified by the request to the Word_Address we did this before? Thirdly we move a block. Move the number of words specified in Qty_Or_Data starting at W4 to the address specified by the value in Word_address (hence @Word_Address) ReadWrite [Program]: ------Read_01_02[section]: IGNORE ALL RUNGS?? As the request was for words ReadWrite [Program]: ------FORCE_05 [section]: IGNORE ALL RUNGS?? As the request was for words Master_Sample [Program]: ------Setup_Request & Read_03[section]: IGNORE as this is included only for a sample of the master routine and has NOTHING to do with the slave routine ( added as a bonus lets say) Can anyone suggest if I am following this correctly ?? If so do I simply plug this in my program. If so do I only have to specify my node in the existing modbus network? I might change some of the W0 … address to say W400 this would also be alright, ?? yes??

Share this post


Link to post
Share on other sites
Sorry Nibroc !!! Short time between me posting this and you writing a reply. Thanks for your input i will look at this now.

Share this post


Link to post
Share on other sites
Hello Nibroc, I am unfamiliar with the CX-protocol and developing macros. I have only used CX to download the modbusV5 protocols which i used in my master application on serial port 1. I will have a look at your protocol more closely with some literature on hand to help me understand. From you comment i understand how I listen to the port with the protocol macro and in your case you listen for [01] + [04] + [00]... when i hear something i go to the matrix if the recieve message is equal to WordReq then i got to process 4 in modbus slave. Process 4 then sends the WordResp which happens to be data at some location Thanks Nibroc as you said this may be more pratical for me. could you post the code for CX programmer so i have a better idea how to implement? from your protocol i think it will be simply keep the data in address CIO4020 updated for transfer. But do i simply have the PCMR executing continuously like in sleepy wombats ModbusPM?

Share this post


Link to post
Share on other sites
Hello again, please see matching ladder code below... as you can see, there is little ladder programming to do!! Most feild applications do not require a generic protocol, as you generally are requesting/sending the same data from the same locations continuously. I normally take advantage of this to write the simplest protocols possible!! Where possible, I try to make the protocol macro card do the work whilst keeping the ladder code to a minimum. For Example: Your Modbus master application (different post) could also have been completed with a single PMCR call in the ladder code. Three 'Send Messages' would be defined, with three respective 'Receive Messages'. These would be added to a single macro 'Sequence'. Nibroc example.cxp Edited by Nibroc

Share this post


Link to post
Share on other sites
Thanks Nibroc much appreciated, I did find the master protocol a daunting task and was frustrated while trying to handle only three message statements. I was not familiar with CX protocol as i mentioned earlier so the thought of modifying the protocol appeared fraught with danger. After viewing your protocol and now being more familiar with the PCMR instruction i am more comfortable with modbus and will see if i can find time to experiment when i have the desired response. I will also investigate a post by jay anthony i found in the archives that describes the message format for CX protocol, I am at home at the moment without CX, so i will examine in the morning and i will update any success. thanks again

Share this post


Link to post
Share on other sites
I found the link http://forums.mrplc.com/index.php?showtopic=2346&hl= this may have to be pasted in the address bar

Share this post


Link to post
Share on other sites
I have tried to convince a superior that Nibrocs protocol is a sensible solution for the PLC simulating a slave in the existing network. He has stated that the PLC should look like a table of address on the modbus network. Your method is practical because the master would poll my PLC for a table of pre - specified data addresses. Once the master had this data it could then extract the information it required. I think the application my superior desires is a PLC that can provide any address and number of words required. I plan to revert back to sleepy wombats code and attempt to gain furthre knowledge. I thank you again nibroc as you have enlightened me on CX protocol and this is a start in the right direction.

Share this post


Link to post
Share on other sites
Hi, Thats OK, the sleeping wombats code is fine and provides access to two of the data areas in the PLC. (I too have implemented similar protocols) I note that the implementation of ModbusPM_V5 code does not check the CRC for data blocks being written to your local PLC (the CJ1) from the master. (could be bad if you are receiving data) In my experience, this type of data exchange is likely to remain fairly static once set up. It is usual to transfer one (or maybe several) 'tables' of data continuously. You can store whichever values you please (words, bits, etc) within the table. Make the transfer table(s) of a size which allows for some future expansion - thus not requiring any changes to communications setups if you wish to pass some extra data at a later date. (Wombats code will suit this fine) It would be unusual and not very efficient to have the master requesting small amounts of data from multiple addresses in the PLC. This could dramatically reduce the speed of your modbus network. Anyway, Good luck.... NIBROC

Share this post


Link to post
Share on other sites
No Success, I was wondering if anyone had tried setting up the master / slave network on the same SCU41 card? Could I then set port 1 as the master and poll port 2 which is a slave to test my ladder?? I believe i can run the PCMR instruction simultaneously on both Serial Ports so serial port 1 -- C1 = #0110 logical port 0, serial port 1, unit 0 serial port 2 -- C2 = #0210 logical port 0, serial port 2, unit 0 I then have logic for serial port 1 to poll node 3 for some data Where node three (sleepy wombats code with node changed to 3) executes at the same time. Is this a valid attempt to test comm. Settings? Or are there some foreseeable dilemmas ? Thanks Nibroc i will have to use sleepys code as time is tight as always. I think only read requests will be made by the existing modbus network which connects to a SCADA system. The SCADA has little control and provides status only as far as i know ( i hate assuming). The project is a standby generator and all the status available would be some power quality words and maybe on/off status so i will try to keep the info tight in the bottom of the table and the table large enough for future expansion. I have tried this now and am getting the rd2 light on the card i will investigate further and post more questions!!

Share this post


Link to post
Share on other sites
OK i think the serial port 1 master communicating to serial port 2 slave might work, Answer 1...................................... Answer 2..................................... And i think i may have seen a glimpse of success. Answering the questions yes they can execute at the same time using the same port ( not physical port ). Now to work out hte table it shall read from should that be CIO? yes i will check...

Share this post


Link to post
Share on other sites
Hello soundwave, You will need to use a different 'logical port' for each of your physical ports, as the each 'logical port' can only perform one duty at a time. (and we don't want to wait until it is free) IE try: Logical Port 0 for Serial Port 1. Logical Port 1 for Serial Port 2. This will allow them to operate more independantly, and not need to wait for the logical port to be free. (There are 7 Logical ports available (or eight?)). Each logical port has a respective 'busy' flag. There should be no problem running both ports at the same time. Nibroc

Share this post


Link to post
Share on other sites
Yes you are right using the same logical port for both operations meant the instruction did work but randomly over a great length of time. I must therefore change the logical port, Thanks Nibroc. Just in time to i started opening the Cx - protocol operation manual, Yuk!!

Share this post


Link to post
Share on other sites
.... (only open the manual if all else fails!! me too) logical port flags are as below.... NIBROC

Share this post


Link to post
Share on other sites
Ok so i changed the logical port number on the slave (serial port 2) to number 1. I changed the input contacts also to reflect logical port 1 operating. I should not have to change the protocol macro, right? There was a quirk in the master program i did for serial port 1. The always on contacts would cause the PCMR instruction to execute incorrectly. I therefore placed a timer to execute the PCMR instruction when the timer expired. In your experience have you used a PCMR instruction on a timer? is this a bad idea particularly for the slave application because when the PCMR port is not executing I could miss a transmission. Or would the protocol macro hold this data for me until the next transmission ?

Share this post


Link to post
Share on other sites
Hi, I did note that you used a timer to (different post) pass your 'tokens' in your master program. This should not be nessary - why not use the falling edge of the 'protocol macro executing' flag to pass the token. This takes the token passing timers out of the equation, and will allow true sequential operation. Your recycling timer (T1000) appears to pass tokens every 100mS with no regard to the completion of protocol macros, thus the program will not cycle thru the nodes properly. See the attached example (i have not tested this)... It should not be necessary to use a timer, when the 'logical port available' flag is on and 'protocol macro executing' flag is off, you can execute PMCR immediately. Nibroc ExampleII.cxp

Share this post


Link to post
Share on other sites
THANKS Nimroc !!!!!!!! This is much appreciated i had a quick look before i left work. Having been slaving 12hr days lately. The reason i used the timer was because the PCMR instruction kept freezing up and the PCMR execution flag would stay on. I did not get to the bottom of this but the timer appeared to release the port more effectively. I tried several methods including a counter that would be incremented on a finish sequence, then a simple if finished release token to the next PCMR instruction all failed!! I will use your code tommorow as I am spending some of a long weekend at the office which pains me. On the same note the slave application on serial port 2 showed the same signs. I basically had the PCMR executing instruction followed by a logical port contact then the PCMR instruction itself. The PCMR instruction again froze. I inserted a p_on in front of both contacts and changed it from normally open to normally closed contacts and the transmission worked hurray!. when reverting to p_on normally open the transmission would work for one sequence then freeze again. I do not understand at the moment but hope to get to the bottom of this tommorow. Again all your time and experience is appreciated and your knowledge has not been wasted, but has saved me stress that come with a deadline. This is by far the most complex section of the programming. The next steps will be a heaven send when this works!!!!! I will post again tommorow but again thanks for your time and replies and patience with a beginner.

Share this post


Link to post
Share on other sites
sorry just clearing up the last post my slave on serial port 2 worked intermittently on the same network as serial port 1 basically -----------------Serial Port 1 (master) | | |----------------PM500 schneider power meter (slave) | | |--------------------Serial port 2 (slave) I would move data from the PM500 into memory address. The poll of serial port 2 would copy this data to W0 (sleepy wombat) and send this information back to serial port 1 (master) i saw this working intermittently. Where intermittently means when I changed the P_On contacts online from normally closed --> to normally open --> to normally closed …..etc

Share this post


Link to post
Share on other sites
Hi, Will be away from the net 4 the wkend so good luck... (plenty of other people here can help...) perhaps your fellow aussies Brother Bob or the Sleeping Womble will be about... NIB

Share this post


Link to post
Share on other sites
Hello All, I am still having some issues with the slave program. The symptoms are the port freezing up ( I think) and the ladder logic therefore unable to execute other PCMR statements. I tested Nibrocs code on my PLC and again had issues. I inserted a timer that would delay the execution of the read statements for 10s at startup and success!! So basically I used a timer to inhibit all PCMR instructions until a power on delay of 10s had elapsed. This only worked for the master program however. The slave program still executes one PCMR instruction at start up and then cannot be executed again. The code is attached. I believe the symptoms of port 1 and port 2 are strikingly similar and there may be something I have overlooked. OMRON_CPU23___REV_E4___Works_once_when_i_cycle_power.cxp

Share this post


Link to post
Share on other sites
So What could be wrong? I have checked the error codes as shown in attachment. Everything seems to be running ok. The connection must be good as i do get that initial data transfer before the port stops operating as expected.

Share this post


Link to post
Share on other sites
I downloaded the latest ModbusV5 and transferred to the PLC ensuring my communication settings on both ports were identical (8 bits , No parity, 1 stop) the only difference is maximum length (200 versus 1000) the protocol is also attached. I can communicate so again I have ruled this out. The only thing left is my ladder which as Nibroc showed is fairly poor at this stage. Adapted___ModbusPM_v5______12_6_2005.psw

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