Siemens 1200 PLC - Modbus RS-485 Communication With Slave Simulator

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello all and welcome to the first of the intrigued engineers tutorial videos I've put this together as when I was getting into PLC programming my first protocol was the online forums which can best be described as just a hot mess of confusion following this we got the trusted f1 key and granted he goes into a lot of depth and it is really good but it's one of those catch-22 situations I it only really makes sense once you know what you're doing but bear this in mind cuz we will be touching on it later in the video so I've made this video for people like me with no formal training into your Paul but they just need to find a solution to get the job done so speaking of which you click the link you know right here let's be honest it's a pretty nice video it's not gonna be in the training page anytime soon so today we're mushing together Siemens 12:14 PLC and a CB 1241 comms module insert and getting that to talk to a Modbus simulator that was running on my absolute unit ever feel a laptop that's the dual humming the background I'm hoping my microphones not picking up so let's get started with the wiring how do I put this thing together right so here I've drawn out this schematic of how I've wired my module up at the top we've got the 1201 module and underneath is my rs-485 to USB converter we're setting it up in what's called a half duplex or two wire mode for the rs-485 and typically rs-485 is the actual wire and hardware side of stuff and Modbus is the protocol or language if you will that we'll be talking over over that rs485 connection as you can see we've tied the TA and tre terminals together and same on the B side as there's some internal resistors in the 12:41 module that we want to make use of these wires go to the a and B terminals in the rs-485 to USB converter the M is for the common ground and you want to connect this to the ground of whatever you communicating with you may be able to get away without doing this but especially here where I am we got a lot of earthing and grounding issues so it's kind of a must here you can see my actual connection I got the T a tra TB and TRB connections on separate twisted wires and as well as a separate connection for the ground in this example we're not going to be using any ready to send signal so I've left the RTS connector unconnected here you can see the termination in the USB device with the ta and Tre wires into the a terminal and the TB and TRB wires into the B terminal in this setup a little orange wire sticking out there is my ground like said the earthing situation here is a bit of a nightmare so I've got absolutely Oh G in connecting the the ground of the module to the chassis ground of the laptop a final important note is something that took me ages to work out I bought in a cheapo rs-485 to USB converter so for one there is no ground connector and secondly and infuriating ly if it a and B terminals were mislabeled so for the hawk I'd among you you may see I have my ta and tra Y is actually going into the B terminal in this case and vice-versa not gonna say how embarrassing little long it took me to work that one out okey-dokey so as a wiring saw it wasn't that fun now let's get into the guts of her and get this programmed up in step 7 oh dear Paul I'm done with the kids okay so let's get to the program insider stuff so I'm gonna start off in a completely clean sketch but the first thing I'm going to show you is the Modbus simulator so I can I'll put a linked in the description to to where I downloaded this from the way just running a holding register here so we've got 10 values in here from 0 and 9 got most of them static I've got the first one just iterating just through some numbers so we can actually see that we've got a live communication going on for the setup using slave ID 1 I could say we're using a holding register and this is going to come into it so the address here is 0 the plc address is 40,000 and one so remember that quantity 10 is just the number of these guys that's about all you need to really know for this initially all running out other on a half-duplex setup so we don't have any requests to send or anything like that so okay oh it's going to there we go I left it on so in here a serial port this is just my us beat rs485 converter in there so I'm running it 9600 baud rate 8 data bits no parity and one stop bit again I could say no RTS or anything like that enabled and we're in rtu mode not ASCII so there we go that is all set up and running good let's get to the guts or the stuff so it's a completely clean build I want to show you this way just because just the way I like the way I like to set it up just you know kind of overlap in memory bits with clock bits later on but that's just me so if you're better than me at this feel free to do it in a different way so I'm gonna add a new device and it's going to take a while to load sometimes so I might just pause this for you and go in super fast motion find a plc protip as well because i've got a bunch of different analog inputs and outputs on there rather than to specify in each time if you come down here to unspecified PLC I mean I'm running a 12/14 system find the unspecified version of that click ok and then when it comes up we can just auto detect all the stuff on there and it says you a job having to find all the right serial numbers and versions of the right analog inputs outputs digital inputs outputs what CM board you have all that good stuff oh my god oh there we go that was fun right so as it's unspecified we're going to go to detect I gonna make it coffee here we go so have a lot over the Ethernet now I've got my laptop directly plugged in to the PLC ah so he's found I think simple my boss good good good switch times all that detect and because it's found it you should Auto detect all the extra IO I've got on there tada there we go so you can see I got Forex 4 modules on this side and the actual CB 1241 itself on the front that so what I'm gonna do oh my god I still know him there we go is pull up this guy to get the information for him when he loads here we go so in the general first thing what to do is in protection and security is come down here when it wakes up there we go and we're going to turn on permit access to pop games that's one and then you don't have to do this by find it helps a lot is enabling the use of the system memory by so turning that on there we go and also the clock memory business and just me being me I always overwrite these things when the low so I lights put them out of the way so I'm just put one thousand in there so I need four and then this next one's eight so it can set as one thousand and one found Abby dozy so let's open up our program blocks we're just going to do this super simply in the main and you can make it as complicated as you like afterwards but for now we're just going to do a lot of hard coding in there just to give you an idea of how all this goes together and how all that stuff works there we go so here's our main program now I could say I'm not formally trained in this so if anyone's got any comments as to why something works in a certain way then please get in touch right in the comment I'd love to know more but what I found with the with the CM board that we're using and it won't actually take this Modbus RTU blocks it I just have not been able to get it for the life of me to communicate with that so I've been using these older functions down here so what you were going to need anyway before I digress too much is a comm load and that come master now the comm load we want to run just once so they give it its own instance of a data block comm load we only want to run once when the whole program starts up and then the masters the thing that loops and acts like a master reads or writes to the holding register the input register output register whatever we wanted to do and we're going to give that on day of luck as well fantastic kind of looks like we know what we're doing so for all the stuff down here and here I'm going to come to in a minute first off I'm going to make just a a data block itself just to hold all the stuff on this side and keep it all nice and tidy so going to add a new block that's a data block just leave it called data block I'm going to add the names of everything down here that is on this side and I'll get back to you in two shakes of a lamb's tail okay we're back so like I mentioned before I've created this data block inside it is mostly balls and some words just to take the output from these blocks just so we can utilize it in other stuff like to say we're going to keep this really simple so we're not really gonna use most of it so it's gonna put them in here so probably speed this bit up saying it's a bit boring okay so now this is all done we have everything coming out of here and pointing to somewhere in this data block on this side so basically all this means is when something happens and this load block he's done we can get a signal to know that it's done and when it throws an error we can see is throwing an error and what the status of that area is that helps us to debug later so the request this is another reason why I like to initialize the clock bits at the start because there's there's two ways you can do this really there's something called first scan and initial call initial call and sometimes I just found it just doesn't work for me I don't know why it if you know why please let me know that sometimes when on stop it just misses its initial call but the first scan is never actually failed for me so you can see here there mmm $1,000 a row so that's one of the the memory addresses that we initialize when we first started everything up so we'll pop him in there so this should just get one request the first time it starts up there port if you come in here click that and then just find the port that we're using so like I say you know what video it is we're attaching a CB 1241 so there it is click him done board rate as I've already said is 9600 and general standard obviously your stuff might differ I'm using 0 a parrot the MB dB now we want this to point to this instance here so what we want to do is just come on here if we just start typing there we go mb master so what we want to do is put it in there and then click not because it adds this little dot for if you want to go into subsections we don't want to do a subsection so click that none now I've noticed in some other blocks it's a bit of a bug in some of them and it even when you click non-elite leaves that dot in there they can throw up some errors so there we go and we can see db2 there db2 there were happy so that is our load block done for our master and we're going to come to the wreck in a minute but the mb address as i said before in this slave that we're using slave definition our slave ID is 1 now why just get a hard code in here as one but obviously if you've got a whole bunch of things on the bus with different addresses you just use a bit of code to loop through there and iterate through all your all your devices but keeping the super simple that's one now mode this is where I want to talk a bit about the f1 button so if you click anything and press f1 you do get a very good help menu but like I said at the start it's only really good when you know what you're doing I have to give us a little while to load there we go so right so I clicked on the the mb master pressed f1 and we're in and this gives you kind of description of everything so what the wreck is mb address and it does this fit any block and it goes into a lot of depth on everything these are very very helpful because if you're anything like me when you get into something it'll be throwing out all manner of error codes so you can come here read across the error code and start trying to get a bit more information about where you're going wrong and try and fix it so what we want to come into here to do is to have a look at this mode function so the mode click on him now if you're used to Modbus and just getting into it from Siemens side this is where it gets a bit weird so we have our Modbus function calls here we should be used to so one two three four tweet at account the mode itself in Siemens is a bit different so if we want to read an output bit its mode zero if we want to read an input bit its mo 0 if we want to read a holding register its mode 0 its all the sets are basically reading is 0 writing is 1 or 2 depending on well whatever you doing but what the Siemens software actually does is it takes your mode and it takes your Modbus address that you put in and it works out from your mode address what actual function it's going to put in and fire down that cable for the actual Modbus communication so as I said let's start the video we're wanting to start off from reading a holding register which is this guy here so we want to have mode 0 and we want to be reading address loss starting at address 40,000 and one so if we got back into the code so change that mode to zero date your address as we can see in here was starting offset 0 which in reality is 40,000 and one data length again we put this in before so 0 to 9 is 10 and the data pointer so what the data pointer is is it points to the area of memory where you want to read from right - or what is going to look for - to do something with the data so gonna make a new data block on purpose I'm just going to call this register I'm going to show you one of the things that really tripped me up when I was trying to get my head around this initially so what I'm going to do is just create an array what should we call it Wow great this is an array of integers and we're going to make it an array of 10 integers come on Boosh there we go so that's all set up all of these have a Stein value of 0 so we know I were starting from and now if we go back to this we want to point this data pointer to that register so it come in here have a look for a register there is clicking and we want to point it to the array but we don't want to point it to a particular byte in that array so when we get to this bit we don't click on the individual bits we just click none at the top again it hasn't put the dot the end - that's all what working ok press ENTER now this is this is the crucial bit because it all looks good but if we run this it'd be throwing up areas left right and centre about invalid data pointers but we've put it in there so what's what's the issue and again if you know more about this lots of people know a lot more about this than me please get in touch and let me know why but what we have to see is oh right just a block and right-clicking go of properties in the properties in attributes we need to disable this optimize block access and when we disable that yeah this little warning message click OK click OK and now it can actually look at that memory address and point towards it write data to it and read data from it why I don't know but yeah it works if it works it's not stupid so the only thing I left we've got to do is to do this request pulse so what I'm going to do is utilize the fact that we know when this is done so I'm not gonna build in any sort of error recognition you can do it off your own box later cuz it's just simple logic but what we're going to do is create an and gate in LED which is just two of these casts on old school and we're going to put in the order is it in data block so we have a looking data block and we want to have a look when load is done so when that is true or not so it should closed and for this bit because we've initialized the clock pulses as well we can come in here start typing clock and we can look and say ah clock to Hertz there we go so this is going to be pulsing 2 times a second but it's only gonna get through to fire the request when this block is done and that is that that should work so this is now where we need to come to uploading it to to the actual PLC so for uploading it to the PLC just cause a lot of weirdness if you just go straight up here and download it straight to the device because this is a brand new install what we want to do is come up here to PLC 1 right click it and before we do any actual software uploading we want to do hardware and we want to do well let's just do it in two unless compulsory so download to device hardware configuration and they said probably take an age to get its act together again so there might be a bit of fast-forwarding in the idea I know here we go Ethernet connection start the search so it's found it so we're gonna load the hardware I'll come up with a whole bunch of stuff basically say yes to it there we go lewd fantastic so we've got our hardware configuration up there and now we want to put up our software so download to device again software all and here we might have to actually tell it it needs to to stop and take a breather well Alice comes on board here we go so yeah no action we tell it to stop and then we can load it fantastisch so it should all be working so we're gonna go online ever been a monitor this impossible hope I must have started up properly yeah wait for all the greens there we go it is running very slowly today now we can monitor here we go so we can see on our load the first camera fired done is true that's good error is false that's very good and then the sixteen ashtag quadruple zero just means no errors so I'm a happy man coming down to this you can see because this is done is true this is true and now we'll be firing this at two times a second the refresh rate of the monitoring isn't that quick so it's not really picking up that it's two times a second and the done will only be true for one scan in this thing so again we're not going to pick up on the refresh rate but we can see we're not throwing up any error codes status is no error everything's happy so let's go to the register itself have a look at what's going on here so on monitor and these values if I've done my job right should match what is happening in the holding register and it is wishes relief there we go okay so that's reading to a holding register how do we write to a holding register well using what we've just learned is super simple or go offline have a look at the help always good to just cross-check this so that was reading to a holding register let's try and write to a holding register so we come down here ha writing to a holding register that's what we want to do now actual address is the same so forty thousand one forty thousand and one same register but we need to change mode from zero to one so I'm just going to do a bit of housekeeping in my Modbus sim so that's not all to increment it in the market I just causes all sorts of naughtiness may come down here change this mode hard code it to one like I say feel free to make that a variable in fact to be pretty poor if we didn't make it into a variable into a bigger program but yeah we're just keeping this super simple for now we're gonna we download that we've already done the hardware stuff so now we can just throw up this updated file we haven't change anything massive so there we go that's all happy and if we go online again and do some monitoring what's going on in our registers when it wakes up here we go so what's actually happening now is we're writing whatever's in here to here and shot-caller the both the same but if we come in here and change you say that was no whatever - - can see in here first register has changed it - there we go two hours of fun there we go so that is how you read and write from a holding register from a Siemens PLC so I hope that helped keep an eye out for more videos from me coming out soon I want these dual load more around industrial applied engineering so should be fun they fast you back anyway so for the first time thank you very much for watching
Info
Channel: The Intrigued Engineer
Views: 82,083
Rating: undefined out of 5
Keywords: Siemens, PLC, TIA, TIA Portal, Modbus, RS485, Communication, Modbus Slave, Slave Simulator, ladder logic, tutoral, twisted pair, half duplex, RTU, USB to RS485, Step 7
Id: 1fMaw6GATws
Channel Id: undefined
Length: 26min 30sec (1590 seconds)
Published: Sat Jul 04 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.