LPCBeremiz.py
changeset 708 6ec28dc375cf
parent 706 64a9b509973b
child 715 135566ab0807
equal deleted inserted replaced
707:6880c88e499e 708:6ec28dc375cf
   766 
   766 
   767 #undef __LOCATED_VAR
   767 #undef __LOCATED_VAR
   768 
   768 
   769 """
   769 """
   770 
   770 
       
   771     def Generate_lpc_retain_array_sim(self):
       
   772         """
       
   773         Support for retain array in Simulation
       
   774         """
       
   775         return """/* Support for retain array */
       
   776 #define USER_RETAIN_ARRAY_SIZE 2000
       
   777 #define NUM_OF_COLS    3
       
   778 unsigned char readOK = 0;
       
   779 unsigned int foundIndex = USER_RETAIN_ARRAY_SIZE;
       
   780 unsigned int retainArray[USER_RETAIN_ARRAY_SIZE][NUM_OF_COLS];
       
   781 
       
   782 unsigned int __GetRetainData(unsigned char READ, unsigned int INDEX, unsigned int COLUMN)
       
   783 {
       
   784     if(READ == 1)
       
   785     {
       
   786         if((0<=INDEX) && (INDEX<USER_RETAIN_ARRAY_SIZE) && (0<=COLUMN) && (COLUMN<NUM_OF_COLS))
       
   787         {
       
   788             readOK = 1;
       
   789             return retainArray[INDEX][COLUMN];
       
   790         }
       
   791     }
       
   792 
       
   793     readOK = 0;
       
   794     return 0;
       
   795 }
       
   796 
       
   797 unsigned char __SetRetainData(unsigned char WRITE, unsigned int INDEX, unsigned int WORD1, unsigned int WORD2, unsigned int WORD3)
       
   798 {
       
   799     if(WRITE == 1)
       
   800     {
       
   801         if((0<=INDEX) && (INDEX<USER_RETAIN_ARRAY_SIZE))
       
   802         {
       
   803             retainArray[INDEX][0] = WORD1;
       
   804             retainArray[INDEX][1] = WORD2;
       
   805             retainArray[INDEX][2] = WORD3;
       
   806             return 1;
       
   807         }
       
   808     }
       
   809     
       
   810     return 0;
       
   811 }
       
   812 
       
   813 unsigned char __FindRetainData(unsigned char SEARCH, unsigned int START_IDX, unsigned int END_IDX, unsigned int WORD1, unsigned int WORD2, unsigned int WORD3)
       
   814 {
       
   815     unsigned int i;
       
   816 
       
   817     if((SEARCH==1) && (0<=START_IDX) && (START_IDX<USER_RETAIN_ARRAY_SIZE) && (START_IDX<=END_IDX) && (END_IDX<USER_RETAIN_ARRAY_SIZE))
       
   818     {
       
   819         for(i=START_IDX;i<=END_IDX;i++)
       
   820         {
       
   821             if((retainArray[i][0] == WORD1) && (retainArray[i][1] == WORD2) && (retainArray[i][2] == WORD3))
       
   822             {
       
   823                 foundIndex = i;
       
   824                 return 1;
       
   825             }
       
   826         }
       
   827     }
       
   828 
       
   829     foundIndex = USER_RETAIN_ARRAY_SIZE;    /* Data not found => return index that is out of array bounds */
       
   830     return 0;
       
   831 }
       
   832 
       
   833 /* Since Beremiz debugger doesn't like pointer-by-reference stuff or global varibles, separate function is a must */
       
   834 unsigned char __GetReadStatus(unsigned char dummy)
       
   835 {
       
   836     return readOK;
       
   837 }
       
   838 
       
   839 unsigned int __GetFoundIndex(unsigned char dummy)
       
   840 {
       
   841     return foundIndex;
       
   842 }
       
   843 """
       
   844 
   771     def _Simulate(self):
   845     def _Simulate(self):
   772         """
   846         """
   773         Method called by user to Simulate PLC
   847         Method called by user to Simulate PLC
   774         """
   848         """
   775         self.CurrentMode = SIMULATION_MODE
   849         self.CurrentMode = SIMULATION_MODE
   832            # debugger code
   906            # debugger code
   833            (self.Generate_plc_debugger, "plc_debugger.c", "Debugger"),
   907            (self.Generate_plc_debugger, "plc_debugger.c", "Debugger"),
   834            # init/cleanup/retrieve/publish, run and align code
   908            # init/cleanup/retrieve/publish, run and align code
   835            (self.Generate_plc_common_main,"plc_common_main.c","Common runtime"),
   909            (self.Generate_plc_common_main,"plc_common_main.c","Common runtime"),
   836            # declare located variables for simulate in a black box
   910            # declare located variables for simulate in a black box
   837            (self.Generate_plc_declare_locations,"plc_declare_locations.c","Declare Locations")]:
   911            (self.Generate_plc_declare_locations,"plc_declare_locations.c","Declare Locations"),
       
   912            # declare located variables for simulate in a black box
       
   913            (self.Generate_lpc_retain_array_sim,"lpc_retain_array_sim.c","Retain Array for Simulation")]:
   838             try:
   914             try:
   839                 # Do generate
   915                 # Do generate
   840                 code = generator()
   916                 code = generator()
   841                 if code is None:
   917                 if code is None:
   842                      raise
   918                      raise
  1002         self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
  1078         self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
  1003         self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
  1079         self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
  1004         self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES)
  1080         self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES)
  1005         self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
  1081         self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
  1006     
  1082     
  1007         self.AddToMenuToolBar([(wx.ID_SAVE, wx.ART_FILE_SAVE, _(u'Save'), None),
  1083         self.AddToMenuToolBar([(wx.ID_SAVE, "save.png", _(u'Save'), None),
  1008                                (wx.ID_PRINT, wx.ART_PRINT, _(u'Print'), None)])
  1084                                (wx.ID_PRINT, "print.png", _(u'Print'), None)])
  1009     
  1085     
  1010     def _init_ctrls(self, prnt):
  1086     def _init_ctrls(self, prnt):
  1011         IDEFrame._init_ctrls(self, prnt)
  1087         IDEFrame._init_ctrls(self, prnt)
  1012         
  1088         
  1013         self.Bind(wx.EVT_MENU, self.OnOpenWidgetInspector, id=ID_BEREMIZINSPECTOR)
  1089         self.Bind(wx.EVT_MENU, self.OnOpenWidgetInspector, id=ID_BEREMIZINSPECTOR)
  1062                 self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, 
  1138                 self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, 
  1063                               TYPESTREE, INSTANCESTREE, SCALING)
  1139                               TYPESTREE, INSTANCESTREE, SCALING)
  1064         dialog.Destroy()
  1140         dialog.Destroy()
  1065 
  1141 
  1066     def RefreshFileMenu(self):
  1142     def RefreshFileMenu(self):
       
  1143         MenuToolBar = self.Panes["MenuToolBar"]
  1067         if self.PluginRoot is not None:
  1144         if self.PluginRoot is not None:
  1068             selected = self.TabsOpened.GetSelection()
  1145             selected = self.TabsOpened.GetSelection()
  1069             if selected >= 0:
  1146             if selected >= 0:
  1070                 graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer)
  1147                 graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer)
  1071             else:
  1148             else: