Dynamically set RS UNI parameters

Hello everyone, For our projects we always use an RS UNI for RS485 (Modbus RTU). Depending on the type of project we use different modbus slaves with a different baud rate and parity setting. We use a .csv file that is read at the start of the PLCnext engineer project to detemine what slave is used. This way we know what registers to read to get our data. What would be absolutely ideal is to be able to dynamically change the baud rate and the parity settings based on the contents of the .csv file located on the plcnext. This doesn’t have to happen a lot, just once after the PLC boots. Is there a way we can do this? It does not necessarily have to happen in plcnext engineer. If it can be done in C++, python or in another way, that is fine too. Thanks in advance! Edit: I have found the GitHub projects to dynamically set IO on the axiolinebus. But it seems like this only works for digital inputs and digital outputs. Not for other type of axioline modules. Correct me if I’m wrong. (https://github.com/griboldi/Dynamic-Axiobus-Configuration and https://github.com/PLCnext/BusConductor)

Hi, the approach in the two projects you mention might be a possibility, but that is not the best starting point in this case. You can read and write the serial parameters using the PDI_READ and PDI_WRITE function blocks in PLCnext Engineer. In the attached data sheet, section 18 (from page 27) describes the PDI index (hex 0080) and the format of the 16-byte data array containing the serial parameters. You should first try to read the data from this Index, from the Axioline Slot that your RS UNI is installed, with PDI_READ. Once you are happy that you can retrieve the parameters, you can then try changing them and writing them back to the module with PDI_WRITE. Note that you should only write the configuration data once, each time a change is needed. It is strongly advised not to write PDI data cyclically. As for reading CSV data into a PLCnext Engineer project - if you need help with that, please let us know. ~ Martin.

db_en_axl_f_rs_uni_1h_8533_en_06.pdf

Hi Martin, Thanks a lot for your response. I think your approach is better indeed. I am not able to find the PDI_READ and PDI_WRITE functionblocks in PLCnext engineer 2021.0.2 though. Searching doesn’t give any results [attachment]Search_PDI_READ.jpg[/attachment] I also tried downloading the AXL_PDI_7 library from plcnextstore.com, but that is not what I should use I suppose. Especially since someone else posted a screenshot of the functionblock in use: https://www.plcnext-community.net/en/discussions-2-offcanvas/pdi-read-not-work.html

Search_PDI_READ.jpg

Yes, you’re right, AXL_PDI_7 is not necessary in this case. The PDI_READ and PDI_WRITE fbs are included in the PLCnext Controller system library, which you can add to a project by right-clicking on the „Libraries“ branch of the Components tree and selecting „Add Library …“ [attachment]2021-04-28_14-17-57.jpg[/attachment] This library is included by default when you create a new project based on the AXC F x152 project template, which is why I keep forgetting to mention it. Let us know how you get on.

2021-04-28_14-17-57.jpg
{B9034AB2-65BA-4D96-B2E0-B45D04456668}.png
{D96B01FC-D64E-41C7-8BED-BF6F36535D1B}.png

You are so quick! I found the functionblock and played with it for a bit. As far as I know I set it up right (using the PDI_READ manual through the PLCnext engineer help menu). When I download this code to the PLC the output ERROR is always true. Even though I still have to set the REQ input to TRUE manually to activate the functionblock. Whether I activate the FB or not, the errorcodes (STATUS) will always remain 00. So I can’t see what’s going wrong based on the status. Searching the community for „PDI_READ“ only shows the result for this thread and the one I linked in comment #2. Do you know what’s going wrong? Thanks, Tim

PDI_READ_Error.jpg

Hi Tim, What is the data type of the RD_1 variable in your screen shot? I tried ByteArray35 (a built-in array of 35 bytes) and it worked OK. ~ Martin.

image.png
image.png

Hi Martin, I used a word array as the datatype for RD_1, since the manual stated that should work too. I changed it to ByteArray35. Unfortunately that doesn’t change anything. What I find strange is that the Error is already true before REQ has seen a rising trigger. Also the Status output (for status I used a word array as well) does not contain any errocodes. I am using FW2021.0.3 LTS. Also, I created a brand new project (by selecting the AXL F 2152 FW2021) and used only this functionblock in main to make sure this isn’t caused by a problem with my existing project. Unfortunately that results in the exact same [attachment]newProject.jpg[/attachment]

newProject.jpg

I am also using FW 2021.0.3 on AXC F 2152. I initially got the same behaviour you describe when I used INT (not an array) as the variable type for RD_1 - there was an Error, but no Status information. You’re right, a WORD array should work for RD_1 too. I have just changed the type of RD_1 to the same type as the Status variable (i.e. Array of Word), and I don’t get the Error. Now when I change the RD_1 variable to an invalid type (e.g. INT), I get the Error again, but this time with the correct status information (0x09B / 0x00C). Even though there may be some unusual behaviour with the Error/Status outputs, it should still be possible to get the FB working. Can you please take screen shots of (a) the variable table showing the variables on this FB, and (b) the Data Types sheet where you define the Word array for the Status variable?

I’m not sure if I provided screenshot a as you requested since I don’t fully understand what you mean. The situation right now is in the screenshots attached.

a.jpg
b.jpg

OK, I get the same behaviour as you, with those variable types. In your screen shot in reply #4 above, the Status variable was of type „arrWord“. This is correct - the help says this type should be ARRAY OF WORD[2]. In the latest screen shot, the type of this Status variable has changed to „ByteArray35“. Please try changing the type of this Status variable back to the one you used in the earlier screen shot. I think this will solve the problem.

Hi Martin, You are right, the datatype for status has to be a word Array that has to have size 2. Not larger. So I created a datatype and now it works! Thanks a lot! This will make sure we only need to maintain a single project. In a CSV file we can declare what slave we are using and based on that I will be able to change the RS UNI settings. (We read the CSV file using the PBCL_FileCsvRead_1 functionblock from the PLCnext Base Services library). For anyone reading this in the future, in the attachments are my exact settings.

Create datatype.jpg
DataTypes.jpg
Result.jpg