Andreschrosa Posted November 6, 2008 Share Posted November 6, 2008 I'm implementing a modbus network scan for equipments, this network consists of several IPs, on each IP there are serveral modbus equipments connected. What I want to do is scan the IP adresses from modbus ID 1 to 255, using function 17 to find then, then display the equipment's model name and serial number on a tree list, grouped by their IP adress locations. I'm stuck in the class definitions to group equipments together under their respective IP adresses. I'm creating a class for the equipements thenselves, and another for each group. I want each group to store an array of equipments that are found on that IP. So my doubt is how to create such array of equipments? Also when I create the function add_equipment, is there any way to do it work short of creating a chained list? Is there a chained list structure already in DAQFactory? class Equipment local model local manufacturer local serialnum local modbusadress function get_adress() return modbusadress endfunction endclass class Group local name local equipment equiplist[] local nequips local ip function add_equip(Equipment equip) nequips++ equiplist = endclass Link to comment Share on other sites More sharing options...
AzeoTech Posted November 6, 2008 Share Posted November 6, 2008 If you don't need the advanced features of channels (like persist), then you can just use variables. In general, you should think simple. I can tell that you are a programmer of other languages because of how you tried to declare an array. The thing is, in DAQFactory every variable is an array and there is no strong type casting other than string and number, and even that isn't that strong. If you only store a scalar value, its just an array of 1 element. There are also only two data types, string and number. To store references to an object, you use the number type. So, where you have local equipment equiplist[] you want just local equiplist you don't have to tell DAQFactory what type of object you are going to store in it nor that it will be an array. In fact, you can put different types of objects in the array. Also, again in your function declaration for add_equip, you don't need to tell daqfactory that you are going to pass an equipment class. You only need to tell if its a number or string. Then to add to the array a new object, just do: function add_equip(equip) equiplist.append(equip) endfunction Link to comment Share on other sites More sharing options...
Andreschrosa Posted November 7, 2008 Author Share Posted November 7, 2008 Ok, that makes sense Now I want to get the IP list from a multiline edit box, parse it by ";" do a scan by those IPs for modbus adresses. How do I get how many itens are in the array ipparse after doing parse (I tried ipparse.size() and .length), so I can do a for to run it's lenght? Maybe there is something like file.length() for arrays... global ipnet global ip private ipparse ipparse = parse(ipnet, -1, ";") for(k, k=0, k--) k = ipparse.size() ip = parse (ipparse, k, ",") .... ipnet is a global variable set in the edit box Link to comment Share on other sites More sharing options...
AzeoTech Posted November 7, 2008 Share Posted November 7, 2008 The function you want is numrows(). There is also numcols() and numdepth() if you are doing 2 and 3 dimensional arrays. These are global functions, not member functions of a variable, so its: numrows(ipparse) Link to comment Share on other sites More sharing options...
Andreschrosa Posted November 11, 2008 Author Share Posted November 11, 2008 Thanks, that's what I needed to know. I have another question conserning classes: is it possible to declare classes in another sequence and have it behave like standart DAQFactory classes, with the auto complete option, like when you type the object name. it show up a dropdown list of it's class functions? How would I include a class from another sequence, is it done like including from a external dll? I have those classes I'm designing to store the network data (and later save the structure on a file), please take a look if something is misplaced, specially the creator functions. class group local string name local string equiplist local nequips local string ip function group (string newname, string newip) name = newname nequips = 0 ip = newip endfunction function add_equip(equip) nequips++ equiplist = equiplist.append(equip) endequip function change_name(string newname) name = newname endfunction function get_name() return(name) endfunction function get_equiplist() return(equiplist) endfunction function get_nequips() return(nequips) endfunction function get_ip() return(ip) endfunction endclass class equipment local string model local string manufacturer local serialnum local modbusaddress function equipment(string newmodel, string newmanufactuter, string newserialnum, string newmodbusadress) model = newmodel manufacturer = newmanufacturer serialnum = newserialnum modbusaddress = newmodbusaddress endfunction function get_model() return (model) endfunction function get_manufacturer() return(manufacturer) endfunction function get_serialnum() return(serialnum) endfunction function get_modbusaddress() return(modbusaddress) endfunction endclass Link to comment Share on other sites More sharing options...
AzeoTech Posted November 11, 2008 Share Posted November 11, 2008 No, autocomplete doesn't work through classes. That is one of two reasons why we haven't published the feature. The other is that you can't debug member functions easily. We'll have this rectified by 6.0. As for your code, it looks fine, except that its just: equiplist.append(equip) Append() is a function that adds the value and doesn't return anything. You don't want to assign the result (which is NULL) to anything. Link to comment Share on other sites More sharing options...
Andreschrosa Posted November 11, 2008 Author Share Posted November 11, 2008 thanks, I changed that and created a new class to store all the groups: class project local string grouplist local groupn function project() groupn = 0 endfunction function add_group(group) grouplist.append(group) groupn++ endfunction endclass Trying to test it, but getting a error on line 107: 99 global project = new (project) 100 global groupaux 101 global equipaux 102 103 for(private.i=1, i<2, i++) 104 groupaux = new(group(i,i)) 105 for(private.j=10, j<13, j++) 106 equipaux = new(equipment("equipment"+j,"IMS",j,j+i)) 107 groupaux.add_equip(equipaux) 108 endfor 109 project.add_group(groupaux) 110 endfor Link to comment Share on other sites More sharing options...
AzeoTech Posted November 11, 2008 Share Posted November 11, 2008 1) There is no constructor in DF classes. At least not the way you have it. So doing new(group(i,i)) doesn't work. You have to do new(group), then call an initialization member function. Same with new(equipment) 2) I don't think you need groupn. You can determine how many groups you have by doing numrows(grouplist). 3) Watch you indentation. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.