netdomain Posted September 27, 2011 Report Posted September 27, 2011 Hi All, I have a project which requires me to add / change / delete records in plc. I was looking at "DIM" , GETR, SETR, functions in PLC. I can't find how to add or delete existing record once I use the DIM function to define a record. For example. I have 10 records. Each record consists of 4 words. If I start from D0, then D0, D1, D2, D3 is one record...... D4, D5, D6, D7 is second record. Now.... If I want to delete record # 2.... will the entire data shift up automatically? or How will I delete the record ? Hope someone is smarter than me :) Thanks Tom
Andy_P Posted October 3, 2011 Report Posted October 3, 2011 Nope, you can't do that. Once an area of memory is declared as a record table with x number of records in it, it stays at that size. I presume you could re DIM the table, but that would involve shifting all the data yourself first, which destroys the need for a record table that the PLC controls in the first place. You will probably be better off rolling your own mechanism for this instead of using DIM, SETR and GETR, in my opinion.
netdomain Posted October 4, 2011 Author Report Posted October 4, 2011 Thankyou, Is there a way to sort the records ? Lets say I want to sort them using 1st word in each record?
james_applied Posted October 6, 2011 Report Posted October 6, 2011 I wish there was some automatic functions for this. However you will must likely end up doing lots of PLC code to do this yourself. From memmory mine invoolded comparing two records and swapping them. Working though the list would eventually put them all in order. Depending on how mixed up they are to start with and how big the list is will change the speed.
Michael Walsh Posted October 6, 2011 Report Posted October 6, 2011 Unless I missed it, the PLC type is not mentioned in this post. If you are using the CJ2, there are many new functions added that will help you. The RSORT (Unsigned one-word record sort) or a similar instruction would do the trick for you. Good luck.
netdomain Posted October 7, 2011 Author Report Posted October 7, 2011 Thankyou! Yes we are using CJ2 Processor. I already considered using RSort, but my records are 4 words each. RSort is meant for sorting only 1 word record. Any tricks for using RSort with multiple word record?
Michael Walsh Posted October 7, 2011 Report Posted October 7, 2011 (edited) This is not correct. RSORT can be used with records that are up to 1024 words in size and up to 32,758 records. RSORT sorts the records based on a single 16 bit word that is part of the record, but the record can be large. The 16 bit word can be anywhere in the record also, it does not have to be the first word. See the picture below which is taken from the help file on RSORT in CXP: There is also RSORT2 and RSORT4 which will search records (again, they can be large). RSORT2 will sort the records based on a 32 bit value within the record and RSORT4 will sort the records based on a 64-bit value somewhere within the record. Edited October 7, 2011 by Michael Walsh
netdomain Posted October 8, 2011 Author Report Posted October 8, 2011 Hi Michael, Thankyou very much for help! I tried RSort in Emulation mode, but it did not work. Can you test this function to see if it works? I defined a 10 record (1 word per record) ( D0, D1..... upto D10) then I entered random numbers in D0 to D10. Then used RSort (with parameters set first). But RSort doesn't sort anything. Can you test this fucntion to see it works please? Thankyou
Michael Walsh Posted October 8, 2011 Report Posted October 8, 2011 (edited) Apparently, the simulator does not work with this function. Perhaps not any of the table sort / search instructions. I just tested the attached code in the simulator and it did not seem to work. I put the exact same code in a CJ2H and it worked fine. See the attached code for an example of how to do your sort. RSORTtest.cxp Of course a 1 word sort is not exactly using the power of this function. To make it look at 4 word records (I believe what you are actually trying to do), make D51 (in this example) equal to 4, then it will look at the first word in each record, with each record being 4 words in length (D0 - D39). Good luck. Edited October 8, 2011 by Michael Walsh
netdomain Posted October 18, 2011 Author Report Posted October 18, 2011 Thankyou very much Michael, IT WORKED!!! THANKYOU THANKYOU!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now