1 #!/usr/bin/env python |
1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- |
2 # -*- coding: utf-8 -*- |
3 |
3 |
4 #This file is part of Beremiz, a library implementing an IEC 61131-3 editor |
4 #This file is part of Beremiz, a Integrated Development Environment for |
5 #based on the plcopen standard. |
5 #programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
6 # |
6 # |
7 #Copyright (C): Edouard TISSERANT and Laurent BESSARD |
7 #Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
8 # |
8 # |
9 #See COPYING file for copyrights details. |
9 #See COPYING file for copyrights details. |
10 # |
10 # |
11 #This library is free software; you can redistribute it and/or |
11 #This library is free software; you can redistribute it and/or |
12 #modify it under the terms of the GNU General Public |
12 #modify it under the terms of the GNU General Public |
14 #version 2.1 of the License, or (at your option) any later version. |
14 #version 2.1 of the License, or (at your option) any later version. |
15 # |
15 # |
16 #This library is distributed in the hope that it will be useful, |
16 #This library is distributed in the hope that it will be useful, |
17 #but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 #but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
19 #Lesser General Public License for more details. |
19 #General Public License for more details. |
20 # |
20 # |
21 #You should have received a copy of the GNU General Public |
21 #You should have received a copy of the GNU General Public |
22 #License along with this library; if not, write to the Free Software |
22 #License along with this library; if not, write to the Free Software |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
24 |
24 |
438 dialog = wxDirDialog(self , "Choose a project", defaultpath, wxDD_NEW_DIR_BUTTON) |
438 dialog = wxDirDialog(self , "Choose a project", defaultpath, wxDD_NEW_DIR_BUTTON) |
439 if dialog.ShowModal() == wxID_OK: |
439 if dialog.ShowModal() == wxID_OK: |
440 projectpath = dialog.GetPath() |
440 projectpath = dialog.GetPath() |
441 dialog.Destroy() |
441 dialog.Destroy() |
442 try: |
442 try: |
443 if os.path.isdir(projectpath): |
443 if not os.path.isdir(projectpath): |
444 raise Exception |
444 raise Exception |
445 self.BusManagers = {} |
445 self.BusManagers = {} |
446 configpath = os.path.join(projectpath, ".project") |
446 configpath = os.path.join(projectpath, ".project") |
447 if not os.path.isfile(configpath): |
447 if not os.path.isfile(configpath): |
448 raise |
448 raise Exception |
449 file = open(configpath, "r") |
449 file = open(configpath, "r") |
450 lines = [line.strip() for line in file.readlines() if line.strip() != ""] |
450 lines = [line.strip() for line in file.readlines() if line.strip() != ""] |
451 if line[0] != "Beremiz": |
451 if lines[0] != "Beremiz": |
452 file.close() |
452 file.close() |
453 raise Exception |
453 raise Exception |
454 for bus_id, bus_type, bus_name in [line.split(" ") for line in lines]: |
454 for bus_id, bus_type, bus_name in [line.split(" ") for line in lines[1:]]: |
455 id = int(bus_id, 16) |
455 id = int(bus_id, 16) |
456 if bus_type == "CanFestival": |
456 if bus_type == "CanFestival": |
457 manager = NodeManager(os.path.join(base_folder, "CanFestival-3", "objdictgen")) |
457 manager = NodeManager(os.path.join(base_folder, "CanFestival-3", "objdictgen")) |
458 nodelist = NodeList(manager) |
458 nodelist = NodeList(manager) |
459 result = nodelist.LoadProject(projectpath, bus_name) |
459 result = nodelist.LoadProject(projectpath, bus_name) |
504 file = open(cpjfilepath, "w") |
504 file = open(cpjfilepath, "w") |
505 file.write("") |
505 file.write("") |
506 file.close() |
506 file.close() |
507 configpath = os.path.join(self.CurrentProjectPath, ".project") |
507 configpath = os.path.join(self.CurrentProjectPath, ".project") |
508 file = open(configpath, "w") |
508 file = open(configpath, "w") |
|
509 file.write("Beremiz\n") |
509 busidlist = self.BusManagers.keys() |
510 busidlist = self.BusManagers.keys() |
510 busidlist.sort() |
511 busidlist.sort() |
511 for id in busidlist: |
512 for id in busidlist: |
512 bus_infos = self.BusManagers[id] |
513 bus_infos = self.BusManagers[id] |
513 file.write("0x%2.2X %s %s\n"%(id, bus_infos["Type"], bus_infos["Name"])) |
514 file.write("0x%2.2X %s %s\n"%(id, bus_infos["Type"], bus_infos["Name"])) |