--- a/FirmwareUpdateDialog.py Wed Apr 11 13:06:58 2018 +0200
+++ b/FirmwareUpdateDialog.py Tue Dec 18 14:43:49 2018 +0100
@@ -29,91 +29,64 @@
This class is the dialog for firmware update parameters selection
- def _init_ctrls(self, parent):
- wx.Dialog.__init__(self, parent=parent, size=wx.Size(600, 250), title=_('Firmware Update'))
+ def __init__(self, parent): + wx.Dialog.__init__(self, parent=parent, title=_('Firmware Update')) # Widgets for the update image file selection
- self.StaticTextFirmwareUpdateImageFile = wx.StaticText(label=_('Update image file:'), parent=self)
self.TextCtrltFirmwareUpdateImageFile = wx.TextCtrl(self)
- self.TextCtrltFirmwareUpdateImageFile.SetMinSize((440, -1))
self.ButtonFirmwareUpdateImageFile = wx.Button(label=_('Add image file'), parent=self)
self.Bind(wx.EVT_BUTTON, self.OnButtonFirmwareUpdateImageFile, id=self.ButtonFirmwareUpdateImageFile.GetId())
- # Widgets for the update type
- self.StaticTextFirmwareUpdateType = wx.StaticText(label=_('Update type:'), parent=self)
- self.RadioButtonFirmwareUpdateTypeLinuxKernel = wx.RadioButton(self, -1,
- _('Linux kernel'), (10, 10), style=wx.RB_GROUP)
- self.RadioButtonFirmwareUpdateTypeLinuxDTB = wx.RadioButton(self, -1,
- _('Linux DTB'), (10, 30))
- self.RadioButtonFirmwareUpdateTypeRootFs = wx.RadioButton(self, -1,
- _('Root file system'), (10, 50))
# Widgets for the chunks size
- self.StaticTextFirmwareUpdateChunksSize = wx.StaticText(label=_('Chunks size in KiB:'), parent=self)
- self.SpinCtrlFirmwareUpdateChunksSize = wx.SpinCtrl(parent=self , size = (60, -1))
+ self.SpinCtrlFirmwareUpdateChunksSize = wx.SpinCtrl(parent=self) self.SpinCtrlFirmwareUpdateChunksSize.SetRange(1, 1024)
self.SpinCtrlFirmwareUpdateChunksSize.SetValue(256)
- # Widgets for the reboot option
- self.CheckBoxFirmwareUpdateReboot = wx.CheckBox(label=_('Reboot after update'), parent=self)
self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
- self.MainSizer = wx.FlexGridSizer(cols=1, rows=2)
- self.SizerFirmwareUpdateImageFile = wx.FlexGridSizer(cols=2, rows=2, hgap=10, vgap=10)
- self.SizerFirmwareUpdateTypeChunks = wx.FlexGridSizer(cols=2, rows=4, hgap=10, vgap=10)
- self.MainSizer.Add(self.SizerFirmwareUpdateImageFile, flag=wx.EXPAND)
- self.MainSizer.Add(self.SizerFirmwareUpdateTypeChunks, flag=wx.EXPAND)
+ self.SizerFirmwareUpdateImageFile = wx.FlexGridSizer(cols=2, rows=1) + self.SizerFirmwareUpdateImageFile.AddGrowableCol(0) + self.SizerFirmwareUpdateImageFile.AddGrowableRow(0) - # Make the main sizer rows and columns growable
- self.MainSizer.AddGrowableCol(0)
- self.MainSizer.AddGrowableRow(0)
- self.MainSizer.AddGrowableRow(1)
+ self.SizerFirmwareUpdateImageFile.Add(self.TextCtrltFirmwareUpdateImageFile, + flag=wx.LEFT|wx.EXPAND) + self.SizerFirmwareUpdateImageFile.Add(self.ButtonFirmwareUpdateImageFile, + flag=wx.RIGHT|wx.ALIGN_RIGHT) + self.SizerFirmwareUpdateImageFileBoxSizer = wx.StaticBoxSizer(wx.StaticBox(self, label=_('Update image file:')), wx.VERTICAL) + self.SizerFirmwareUpdateImageFileBoxSizer.AddSizer(self.SizerFirmwareUpdateImageFile, flag=wx.EXPAND) - # Populate Update image file sizer
- self.SizerFirmwareUpdateImageFile.Add(self.StaticTextFirmwareUpdateImageFile, border=20,
- self.SizerFirmwareUpdateImageFile.Add((0,0))
- self.SizerFirmwareUpdateImageFile.Add(self.TextCtrltFirmwareUpdateImageFile, border=20,
- self.SizerFirmwareUpdateImageFile.Add(self.ButtonFirmwareUpdateImageFile, border=20,
- flag=wx.RIGHT|wx.ALIGN_RIGHT)
+ self.RadioBoxFirmwareUpdateTypeChunks = wx.RadioBox( + self, -1, _('Update type:'), wx.DefaultPosition, wx.DefaultSize, + [_('Linux kernel'), _('Linux DTB'), _('Root file system')], + self.RadioBoxFirmwareUpdateTypeChunks.SetSelection(2) - # Populate Sizer for update type and chunks size
- self.SizerFirmwareUpdateTypeChunks.Add(self.StaticTextFirmwareUpdateType, border=20,
- self.SizerFirmwareUpdateTypeChunks.Add(self.StaticTextFirmwareUpdateChunksSize, border=20,
- self.SizerFirmwareUpdateTypeChunks.Add(self.RadioButtonFirmwareUpdateTypeLinuxKernel, border=20,
- self.SizerFirmwareUpdateTypeChunks.Add(self.SpinCtrlFirmwareUpdateChunksSize, border=20,
- self.SizerFirmwareUpdateTypeChunks.Add(self.RadioButtonFirmwareUpdateTypeLinuxDTB, border=20,
- self.SizerFirmwareUpdateTypeChunks.Add(self.CheckBoxFirmwareUpdateReboot,border=20,
- self.SizerFirmwareUpdateTypeChunks.Add(self.RadioButtonFirmwareUpdateTypeRootFs, border=20,
- self.SizerFirmwareUpdateTypeChunks.Add(self.ButtonSizer, border=20, flag=wx.ALIGN_RIGHT|wx.RIGHT)
+ self.SizerFirmwareUpdateSizeChunks = wx.StaticBoxSizer(wx.StaticBox(self, label=_('Chunks size in KiB:')), wx.VERTICAL) + self.SizerFirmwareUpdateSizeChunks.Add(self.SpinCtrlFirmwareUpdateChunksSize, - # Make the rows and columns growable
- self.SizerFirmwareUpdateImageFile.AddGrowableCol(0)
- self.SizerFirmwareUpdateImageFile.AddGrowableCol(1)
- self.SizerFirmwareUpdateImageFile.AddGrowableRow(0)
- self.SizerFirmwareUpdateImageFile.AddGrowableRow(1)
- self.SizerFirmwareUpdateTypeChunks.AddGrowableCol(0)
- self.SizerFirmwareUpdateTypeChunks.AddGrowableCol(1)
+ self.SizerFirmwareUpdateChunks = wx.FlexGridSizer(cols=2, rows=1) + self.SizerFirmwareUpdateChunks.AddGrowableCol(0) + self.SizerFirmwareUpdateChunks.AddGrowableCol(1) + self.SizerFirmwareUpdateChunks.Add(self.RadioBoxFirmwareUpdateTypeChunks, flag=wx.EXPAND|wx.RIGHT, border=20) + self.SizerFirmwareUpdateChunks.Add(self.SizerFirmwareUpdateSizeChunks, flag=wx.EXPAND) + self.MainSizer = wx.FlexGridSizer(cols=1, rows=3) + self.MainSizer.AddGrowableCol(0) + self.MainSizer.AddGrowableRow(1) + self.MainSizer.AddSizer(self.SizerFirmwareUpdateImageFileBoxSizer, flag=wx.EXPAND|wx.LEFT|wx.TOP|wx.RIGHT, border=20) + self.MainSizer.AddSizer(self.SizerFirmwareUpdateChunks, flag=wx.EXPAND|wx.LEFT|wx.TOP|wx.RIGHT, border=20) + self.MainSizer.AddSizer(self.ButtonSizer, flag=wx.ALIGN_RIGHT|wx.ALL, border=20) + self.MainSizer.SetSizeHints(self) self.SetSizer(self.MainSizer)
- def __init__(self, parent):
- self._init_ctrls(parent)
def OnButtonFirmwareUpdateImageFile(self, event):
dlg = wx.FileDialog(self, _("Choose a firmware image file"), expanduser("~"), "", "*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
@@ -125,17 +98,11 @@
return self.TextCtrltFirmwareUpdateImageFile.GetValue()
def GetFirmwareUpdateType(self):
- if self.RadioButtonFirmwareUpdateTypeLinuxKernel.GetValue() == True:
- elif self.RadioButtonFirmwareUpdateTypeLinuxDTB.GetValue() == True:
- elif self.RadioButtonFirmwareUpdateTypeRootFs.GetValue() == True:
+ res = self.RadioBoxFirmwareUpdateTypeChunks.GetSelection() + if res == wx.NOT_FOUND: return self.SpinCtrlFirmwareUpdateChunksSize.GetValue()*1024
- return self.CheckBoxFirmwareUpdateReboot.GetValue()
--- a/HostFirmwareUpdater.py Wed Apr 11 13:06:58 2018 +0200
+++ b/HostFirmwareUpdater.py Tue Dec 18 14:43:49 2018 +0100
@@ -33,109 +33,98 @@
-WAIT_BEFORE_FEED_SEC = 5
UPDATE_SCRIPT_TIMEOUT = 600
class HostFirmwareUpdater(object):
# Create a new HostFirmwareUpdater
- def __init__(self, _connector, firmwareImagePath, updateType, chunksSize, reboot, logger):
+ def __init__(self, controller, firmwareImagePath, updateType, chunksSize, dialog): - self._connector = _connector
self.firmwareImagePath = firmwareImagePath
self.updateType = updateType
self.chunksSize = chunksSize
- self.logger.write(_("HostFirmwareUpdater init.\n"))
- self.threadUpdateScript = None
- self.runUpdateScriptStatus = None
- self.runUpdateScriptTextError = None
+ self.controller = controller + self.controller.logger.write(_("HostFirmwareUpdater init.\n")) # Reset HostFirmwareUpdater internal variables
- self.logger.write(_("HostFirmwareUpdater update.\n"))
+ self.controller.logger.write(_("HostFirmwareUpdater update.\n")) self.firmwareImageFile = open(self.firmwareImagePath, "rb")
self.imageData = self.firmwareImageFile.read()
self.firmwareImageFileSize = os.stat(self.firmwareImagePath).st_size
- self.logger.write(_("Firmware image %s size: %d\n")%(self.firmwareImagePath, self.firmwareImageFileSize))
+ self.controller.logger.write(_("Firmware image %s size: %d\n")%(self.firmwareImagePath, self.firmwareImageFileSize)) # Note Pyro exceptions are already caught by catcher_func and PyroCatcher in PyroProxyProxy
# Create the necessary files on the target
self._CreateFirmwareImageFileSizeFile()
self._CreateFirmwareImageFileSizeMD5File()
self._CreateFirmwareImageFileMD5File()
- # Create and start the thread for the update script
- self.threadUpdateScript = threading.Thread(target=self._RunUpdateScript)
- self.threadUpdateScript.start()
- # Waiting some time for the update script launching
- self.logger.write(_("Waiting %s s until the update script is running...\n")%WAIT_BEFORE_FEED_SEC)
- sleep(WAIT_BEFORE_FEED_SEC)
+ # start the update script + status, textError = self.controller._connector.RunUpdateScript(self.updateType) + raise Exception(textError) # The update script is now running: Feeding the update script with firmware image data
- # Wait the end of the script
- self.threadUpdateScript.join(timeout = UPDATE_SCRIPT_TIMEOUT)
- # Here, the update is successful, reboot?
def _CreateFirmwareImageFileSizeFile(self):
# Note Pyro exceptions are already caught by catcher_func and PyroCatcher in PyroProxyProxy
- status, textError = self._connector.CreateFirmwareImageFileSizeFile(self.firmwareImageFileSize)
+ status, textError = self.controller._connector.CreateFirmwareImageFileSizeFile(self.firmwareImageFileSize) raise Exception(textError)
def _CreateFirmwareImageFileSizeMD5File(self):
# Note Pyro exceptions are already caught by catcher_func and PyroCatcher in PyroProxyProxy
self.firmwareImageFileMD5Size = hashlib.md5("%s\n"%self.firmwareImageFileSize).hexdigest()
- self.logger.write(_("Firmware image size md5: %s\n")%(self.firmwareImageFileMD5Size))
- status, textError = self._connector.CreateFirmwareImageFileSizeMD5File(self.firmwareImageFileMD5Size)
+ self.controller.logger.write(_("Firmware image size md5: %s\n")%(self.firmwareImageFileMD5Size)) + status, textError = self.controller._connector.CreateFirmwareImageFileSizeMD5File(self.firmwareImageFileMD5Size) raise Exception(textError)
def _CreateFirmwareImageFileMD5File(self):
# Note Pyro exceptions are already caught by catcher_func and PyroCatcher in PyroProxyProxy
self.firmwareImageFileMD5 = hashlib.md5(self.imageData).hexdigest()
- self.logger.write(_("Firmware image %s md5: %s\n")%(self.firmwareImagePath, self.firmwareImageFileMD5))
- status, textError = self._connector.CreateFirmwareImageFileMD5File(self.firmwareImageFileMD5)
+ self.controller.logger.write(_("Firmware image %s md5: %s\n")%(self.firmwareImagePath, self.firmwareImageFileMD5)) + status, textError = self.controller._connector.CreateFirmwareImageFileMD5File(self.firmwareImageFileMD5) raise Exception(textError)
- def _RunUpdateScript(self):
- # Put the update script run status in class attributes because,
- # since we are in a child thread, exceptions thrown in this one are painful to catch.
- # The update script run status will be checked on joining this thread.
- self.runUpdateScriptStatus, self.runUpdateScriptTextError = self._connector.RunUpdateScript(self.updateType)
# Check if a multiple chunks transfer is needed
if self.firmwareImageFileSize <= self.chunksSize :
# Only a single chunk transfer is needed
chunksSize = self.firmwareImageFileSize
- self.logger.write(_("Single chunk transfer\n"))
+ self.controller.logger.write(_("Single chunk transfer\n")) # Multiple chunks transfer is needed
chunksSize = self.chunksSize
- self.logger.write(_("Multiple chunks transfer\n"))
+ self.controller.logger.write(_("Multiple chunks transfer\n")) # Start the image transfer
while transferedBytes < self.firmwareImageFileSize:
+ # User feedback as percentage + keepGoing, _skip = self.dialog.Update( + transferedBytes * 100 / self.firmwareImageFileSize) + textError = _("Canceled") + raise Exception(textError) chunkData = self.imageData[transferedBytes:transferedBytes + chunksSize]
- self.logger.write(_("Transfer chunk, size: %d\n")%(chunksSize))
- status, textError = self._connector.RunFeedPipe(chunkData, isLastChunk, chunksSize)
+ status, textError = self.controller._connector.RunFeedPipe(chunkData, isLastChunk, chunksSize) transferedBytes = transferedBytes + chunksSize
# Detect if the next chunk is the last chunk
if (self.firmwareImageFileSize - transferedBytes) <= self.chunksSize:
@@ -143,11 +132,10 @@
# Check the transfer and the update status
- if self.runUpdateScriptTextError != "" and not self.runUpdateScriptStatus:
- textError = "Update script message: " + self.runUpdateScriptTextError + "\n" + textError
raise Exception(textError)
- self.logger.write(_("Firmware update log: \n\n") + textError + "\nFirmware update successful.")
+ self.dialog.Update(100,_("Firmware update successful.")) + self.controller.logger.write(_("Firmware update log: \n\n") + textError + "\nFirmware update successful.\n") - def _RebootTarget(self):
- self._connector.RebootTarget()
+ def RebootTarget(self): + self.controller._connector.RebootTarget() --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCBACnet.py Tue Dec 18 14:43:49 2018 +0100
@@ -0,0 +1,12 @@
+from __future__ import absolute_import +from bacnet import bacnet as BacnetModule +from bacnet.bacnet import RootClass +from LPCArch import GetLPCArch +BacnetModule.BACNET_VENDOR_ID = 1071 +BacnetModule.BACNET_VENDOR_NAME = "Smarteh Company" +BacnetModule.BACNET_DEVICE_MODEL_NAME = GetLPCArch() --- a/LPCBus.py Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCBus.py Tue Dec 18 14:43:49 2018 +0100
@@ -24,7 +24,8 @@
for section in ["decl", "init", "retrieve", "publish", "cleanup"]}
-LPCBusLDFLAGS = { "MC9:On Board" : "-lmbrtu" }
+# This is in case some bus has some special LDFLAGS +LPCBusLDFLAGS = {} # ex: { "MC9:On Board" : "-lonboard" } from plcopen.structures import LOCATIONDATATYPES
--- a/LPCBus/MC9_Devices_cleanup.c Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCBus/MC9_Devices_cleanup.c Tue Dec 18 14:43:49 2018 +0100
@@ -1,6 +1,8 @@
+rt_task_resume(&UART_task); rt_task_delete(&UART_task);
rt_task_join(&UART_task);
-gpio_close(RS485_GPIO_dev);
rt_mutex_delete(&UART_WriteMutex);
rt_mutex_delete(&UART_ReadMutex);
--- a/LPCBus/MC9_Devices_decl.c Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCBus/MC9_Devices_decl.c Tue Dec 18 14:43:49 2018 +0100
@@ -5,9 +5,9 @@
-#include <native/task.h>
-#include <native/mutex.h>
-#include <native/timer.h>
+#include <alchemy/task.h> +#include <alchemy/mutex.h> +#include <alchemy/timer.h> @@ -20,146 +20,6 @@
-/*------------------------- GPIO -------------------------------------*/
-/* from armadeus/target/packages/as_devices/c/as_gpio* */
-# define ERROR(fmt, ...) printf(fmt, ##__VA_ARGS__)
-//# define ERROR(fmt, ...) /*fmt, ##__VA_ARGS__*/
- int pin_file; /* pin file for 2.6.29 interface*/
-struct gpio_device *RS485_GPIO_dev;
-static int write_file_bool(int fd, int value)
- ret = write(fd, value?"1":"0", 1);
- ERROR("write error\n");
- if (lseek(fd, 0, SEEK_SET) < 0) {
- ERROR("lseek error\n");
-static struct gpio_device *gpio_open(int aGpioNum)
- struct gpio_device *dev;
- export_file = open("/sys/class/gpio/export", O_WRONLY);
- ERROR("Can't open /sys/class/gpio/export\nBe sure that gpiolib is under your kernel\n");
- snprintf(buf, BUFF_SIZE, "%%d", aGpioNum);
- retval = write(export_file, buf, strlen(buf));
- ERROR("/sys/class/gpio/export can't be written\n");
- snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%%d/direction", aGpioNum);
- gpio_dir_fd = open(buf, O_WRONLY);
- ERROR("Can't open gpio%%d direction\n", aGpioNum);
- ret = write(gpio_dir_fd, "out", 3);
- ERROR("Error writing direction\n");
- snprintf(buf, BUFF_SIZE, "/sys/class/gpio/gpio%%d/value", aGpioNum);
- pin_file = open(buf, O_RDWR);
- ERROR("Can't export gpio number %%d\n", aGpioNum);
- dev = malloc(sizeof(struct gpio_device));
- ERROR("Can't allocate gpio_device structure\n");
- dev->port_num = aGpioNum;
- dev->pin_file = pin_file;
-static int gpio_close(struct gpio_device *aDev)
- ERROR("device is NULL\n");
- unexport_file = open("/sys/class/gpio/unexport", O_WRONLY);
- if (unexport_file < 0) {
- ERROR("Can't open /sys/class/gpio/unexport\nBe sure that gpiolib is under your kernel\n");
- snprintf(buf, BUFF_SIZE, "%%d", aDev->port_num);
- retval = write(unexport_file, buf, strlen(buf));
- ERROR("/sys/class/gpio/unexport can't be written\n");
-static int gpio_set_pin_value(struct gpio_device *aDev, int aValue)
- int pin_file = aDev->pin_file;
- retval = write_file_bool(pin_file, aValue);
- ERROR("Can't write value\n");
-#define TransmitMode() gpio_set_pin_value(RS485_GPIO_dev, 1)
-#define RecieveMode() gpio_set_pin_value(RS485_GPIO_dev, 0)
/*--------------------------- Serial Port handling ---------------------------*/
int openserial(char *devicename, unsigned long baudrate)
@@ -210,8 +70,6 @@
@@ -270,6 +128,7 @@
static RT_TASK UART_task;
static RT_MUTEX UART_WriteMutex;
static RT_MUTEX UART_ReadMutex;
+static int UART_task_active; void UART_task_proc(void *arg)
@@ -278,7 +137,11 @@
static uint64_t lastCommTime=0;
- while (rt_task_sleep_until(TM_INFINITE) == -EINTR){
+ while (UART_task_active){ // Communicate only with initialised UART devices
if(uartPortDevices[i] != NULL)
@@ -443,7 +306,6 @@
@@ -455,21 +317,10 @@
tcflush(UART_fd, TCIOFLUSH);
if(write(UART_fd, tmp, uartBufSize) != uartBufSize){
- /* Sleep until transmission completes + 0.5ms safety */
- while(rt_task_sleep_until(
- now + rt_timer_ns2ticks(
- 1000000000LL * uartBufSize * 10 / uartBaudrate
- /* Turn to listen mode*/
FD_ZERO(&set); /* clear the set */
FD_SET(UART_fd, &set); /* add our file descriptor to the set */
@@ -495,9 +346,6 @@
- /* Turn to transmit mode*/
/* Copy received buffer */
if((count == uartBufSize) && (tmp[uartBufSize-TAIL_LEN] == address)){
if(ChecksumValid((unsigned char*)tmp+1, uartBufSize)){
--- a/LPCBus/MC9_Devices_init.c Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCBus/MC9_Devices_init.c Tue Dec 18 14:43:49 2018 +0100
@@ -1,6 +1,5 @@
char *serialdev = "/dev/ttyAPP1";
-int RS485_GPIO_NUM = 102;
uartDevWriteBuf_plc_state = EMPTY;
uartDevReadBuf_plc_state = EMPTY;
@@ -27,12 +26,6 @@
if((err = rt_mutex_create (&UART_ReadMutex, "UART_ReadMutex")))
-RS485_GPIO_dev = gpio_open(RS485_GPIO_NUM);
- fprintf(stderr, "Error while initializing RS485 GPIO.\n");
UART_fd = openserial(serialdev, uartBaudrate); /* uartBaudrate is initialized from Composer */
fprintf(stderr, "Error while initializing %%s.\n", serialdev);
@@ -44,7 +37,9 @@
InitUartPortDevices_shortBuffer();
-if((err = rt_task_create(&UART_task, "UART_task", 0, 50, T_JOINABLE)))
+if((err = rt_task_create(&UART_task, "UART_task", 0, 0, T_JOINABLE))) if((err = rt_task_start(&UART_task, &UART_task_proc, NULL)))
--- a/LPCBus/MC9_Devices_publish.c Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCBus/MC9_Devices_publish.c Tue Dec 18 14:43:49 2018 +0100
@@ -12,5 +12,5 @@
uartDevWriteBuf_plc_state = FULL;
- rt_task_unblock(&UART_task);
+ rt_task_resume(&UART_task); --- a/LPCBus/MC9_OnBoard_cleanup.c Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCBus/MC9_OnBoard_cleanup.c Tue Dec 18 14:43:49 2018 +0100
@@ -1,14 +1,6 @@
-rt_task_delete(&RTU_UART_task);
-rt_task_join(&RTU_UART_task);
-rt_task_delete(&RTU_task);
-rt_task_join(&RTU_task);
-rt_mutex_delete(&RTU_BuffMutex);
-gpio_close(RTU_GPIO_dev);
- rt_dev_close(onboardbusfd);
--- a/LPCBus/MC9_OnBoard_decl.c Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCBus/MC9_OnBoard_decl.c Tue Dec 18 14:43:49 2018 +0100
@@ -1,10 +1,5 @@
-#include <native/task.h>
-#include <native/mutex.h>
-#include <native/timer.h>
/*------------------------- GPIO -------------------------------------*/
@@ -21,7 +16,6 @@
int pin_file; /* pin file for 2.6.29 interface*/
-struct gpio_device *RTU_GPIO_dev;
struct gpio_device *RUN_LED_dev;
struct gpio_device *CAN0_EN_dev;
@@ -153,204 +147,16 @@
-#define REG_DISCRETE_START 0 /**< Input discrete start address */
-#define REG_DISCRETE_NREGS 1024 /**< 1024 bits (type: single bit, Read only) */
-#define REG_COILS_START 0 /**< Coils start address */
-#define REG_COILS_NREGS 1024 /**< 1024 bits (type: single bit, Read/Write) */
-#define REG_INPUT_START 0 /**< Input registers start address */
-#define REG_INPUT_NREGS 1024 /**< 1024 words (type: 16-bit word, Read only) */
-#define REG_HOLDING_START 0 /**< Holding registers start address */
-#define REG_HOLDING_NREGS 1024 /**< 1024 words (type: 16-bit word, Read/Write) */
-#define MAX_MOD_RTU_DEVICES 16
-typedef struct _mbRtuRdHoldingRegs {
- unsigned short startAddr;
-typedef struct _mbRtuRdDiscInputs {
- unsigned short startAddr;
-// unsigned short* buffer;
-typedef struct _mbRtuRdCoils {
- unsigned short startAddr;
-typedef struct _mbRtuWrSingleCoil {
- unsigned short startAddr;
-typedef struct _mbRtuWrCoils {
- unsigned short startAddr;
-typedef struct _mbRtuRdInputRegs {
- unsigned short startAddr;
-typedef struct _mbRtuWrSingleReg {
- unsigned short startAddr;
-typedef struct _mbRtuWrMultiRegs {
- unsigned short startAddr;
-typedef struct _mbRtuSlaveConfig {
- unsigned char slaveAddr;
- mbRtuRdDiscInputs rdDiscInputs;
- mbRtuWrSingleCoil wrSingleCoil;
- mbRtuRdInputRegs rdInputRegs;
- mbRtuRdHoldingRegs rdHoldingRegs;
- mbRtuWrSingleReg wrSingleReg;
- mbRtuWrMultiRegs wrMultiRegs;
+/* TODO : DELETE !... but keep this until composer stops sending code snippets for mbrtu */ MB_PAR_ODD = 0, /**< ODD parity. */
MB_PAR_EVEN = 1, /**< Even parity. */
MB_PAR_NONE = 2 /**< No parity. */
-mbRtuSlaveConfig mbRtuSlaveDev[MAX_MOD_RTU_DEVICES];/**< Tables containing information about connected Modbus network devices (initialized by Composer) */
-commTimer mbRtuDevTim[MAX_MOD_RTU_DEVICES]; /**< Table of timers (one for each position) */
-short usRegInputValue[REG_INPUT_NREGS]; /**< Array of Modbus input registers */
-short usRegHoldingValue[REG_HOLDING_NREGS]; /**< Array of Modbus holding registers */
-char ubCoilValue[REG_COILS_NREGS/8]; /**< Array of Modbus coils (8 coils per byte) */
-char ubRegDiscreteValue[REG_DISCRETE_NREGS/8]; /**< Array of Modbus discrete inputs (8 inputs per byte) */
unsigned long mbBaudRate = 115200; /**< Modbus baud-rate setting: 9600, 19200, 38400, 57600, 115200 */
eMBSerialParity mbParity = MB_PAR_NONE; /**< Modbus parity setting: odd, even, none */
-/* prototypes for functions defined in shared library */
-int mbmrtu_init(unsigned long ulBaudRate, eMBSerialParity eParity);
-void mbmrtu_BusUpdate(int);
-int mbmrtu_cleanup(void);
-static RT_TASK RTU_UART_task;
-static RT_TASK RTU_task;
-static RT_MUTEX RTU_BuffMutex;
-void LockMBRTUBuffer(void){
- while ( rt_mutex_acquire(&RTU_BuffMutex, TM_INFINITE ) == -EINTR);
-void UnLockMBRTUBuffer(void){
- rt_mutex_release(&RTU_BuffMutex);
- void*(*RTU_UART_task_proc)(void *);
-} MB_xeno_task_adaptor_t;
-static MB_xeno_task_adaptor_t MB_xeno_task_adaptor_data;
-void MB_xeno_task_adaptor(void* param)
- MB_xeno_task_adaptor_t *d = param;
- d->RTU_UART_task_proc(d->xSerHdl);
-int CreateMBRTUSerialTask(
- void*(*RTU_UART_task_proc)(void *),
- MB_xeno_task_adaptor_data.RTU_UART_task_proc = RTU_UART_task_proc;
- MB_xeno_task_adaptor_data.xSerHdl = param;
- if((err = rt_task_start(&RTU_UART_task,
- &MB_xeno_task_adaptor_data)) != 0)
-#define nsTOus(ns) (ns/1000L)
-#define nsTOms(ns) (ns/1000000L)
-#define INVALID_RTU_ADDR 255 /* Used when no Modbus RTU slave device is present */
-static void mbmrtu_BusUpdate_proc(void *param){
- while (rt_task_sleep_until(TM_INFINITE) == -EINTR){
- for(i=0;i<MAX_MOD_RTU_DEVICES;i++)
- if(mbRtuSlaveDev[i].slaveAddr != INVALID_RTU_ADDR)
- if(mbRtuDevTim[i].status != TIM_DISABLED)
- actTime = (uint64_t)nsTOms(rt_timer_read());
- mbRtuDevTim[i].actValue += actTime - mbRtuDevTim[i].oldTime;
- mbRtuDevTim[i].oldTime = actTime;
- if(mbRtuDevTim[i].actValue < mbRtuDevTim[i].toValue)
- mbRtuDevTim[i].status = TIM_EN_RUNNING;
- mbRtuDevTim[i].status = TIM_EN_EXPIRED;
- /* Check if communication depends on timer - if it does, check timer status */
- if((mbRtuDevTim[i].status == TIM_DISABLED) || (mbRtuDevTim[i].status == TIM_EN_EXPIRED))
- /* If timer is enabled, reset it's value, otherwise keep it disabled */
- if(mbRtuDevTim[i].status != TIM_DISABLED)
- mbRtuDevTim[i].actValue = 0; /* Reset timer value */
- mbRtuDevTim[i].status = TIM_EN_RUNNING;
- else /* Keep timer disabled */
- mbRtuDevTim[i].status = TIM_DISABLED;
-void TransmitMode(void){
- gpio_set_pin_value(RTU_GPIO_dev, 1);
-void RecieveMode(int us){
- while(rt_task_sleep_until(
- now + rt_timer_ns2ticks(1000LL*us)
- gpio_set_pin_value(RTU_GPIO_dev, 0);
#define MAX_ONBOARD_DEVICES 2
#define ONBOARD_READ_BUFSIZE 30
--- a/LPCBus/MC9_OnBoard_init.c Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCBus/MC9_OnBoard_init.c Tue Dec 18 14:43:49 2018 +0100
@@ -1,13 +1,7 @@
-#define ONBOARDDEVFILENAME "onBoard"
+#define ONBOARDDEVFILENAME "/dev/rtdm/onBoard" -bzero(&usRegInputValue , sizeof(usRegInputValue ));
-bzero(&usRegHoldingValue , sizeof(usRegHoldingValue ));
-bzero(&ubCoilValue , sizeof(ubCoilValue ));
-bzero(&ubRegDiscreteValue, sizeof(ubRegDiscreteValue));
-bzero(&mbRtuSlaveDev , sizeof(mbRtuSlaveDev ));
-bzero(&mbRtuDevTim , sizeof(mbRtuDevTim ));
bzero(&onBoardReadBuf , sizeof(onBoardReadBuf_t ));
bzero(&onBoardWriteBuf , sizeof(onBoardWriteBuf_t ));
@@ -28,41 +22,22 @@
gpio_set_pin_value(CAN1_EN_dev, 0);
#endif /* CAN1_EN_GPIO_0_17 */
-RTU_GPIO_dev = gpio_open(111);
- fprintf(stderr, "Error while initializing RTU GPIO.\n");
-if((err = rt_mutex_create (&RTU_BuffMutex, "RTU_BuffMutex")))
-if((err = rt_task_create(&RTU_UART_task, "RTU_UART_task", 0, 50, T_JOINABLE)))
-mbmrtu_init(mbBaudRate, mbParity);
-if((err = rt_task_create(&RTU_task, "RTU_task", 0, 50, T_JOINABLE)))
-if(rt_task_start(&RTU_task, mbmrtu_BusUpdate_proc, NULL))
for(i=0; i<MAX_ONBOARD_DEVICES; i++) {
switch(onBoardDev[i][1]) {
- onboardbusfd = rt_dev_open(ONBOARDDEVFILENAME, 0);
+ onboardbusfd = open(ONBOARDDEVFILENAME, 0); printf("can't open %%s rtdm device, %%s\n", ONBOARDDEVFILENAME,
strerror(-onboardbusfd));
- err = rt_dev_ioctl(onboardbusfd, RTSMT_ONBOARD_RTIOC_INIT, &onBoardBusInit);
+ err = ioctl(onboardbusfd, RTSMT_ONBOARD_RTIOC_INIT, &onBoardBusInit); printf("error while RTSMT_ONBOARD_RTIOC_INIT, %%s\n", strerror(-err));
- rt_dev_close(onboardbusfd);
--- a/LPCBus/MC9_OnBoard_publish.c Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCBus/MC9_OnBoard_publish.c Tue Dec 18 14:43:49 2018 +0100
@@ -1,12 +1,6 @@
-rt_task_unblock(&RTU_task);
- rt_dev_ioctl(onboardbusfd, RTSMT_ONBOARD_RTIOC_WRITE, &onBoardWriteBuf);
+ ioctl(onboardbusfd, RTSMT_ONBOARD_RTIOC_WRITE, &onBoardWriteBuf); --- a/LPCBus/MC9_OnBoard_retrieve.c Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCBus/MC9_OnBoard_retrieve.c Tue Dec 18 14:43:49 2018 +0100
@@ -1,8 +1,6 @@
- rt_dev_ioctl(onboardbusfd, RTSMT_ONBOARD_RTIOC_READ, &onBoardReadBuf);
+ ioctl(onboardbusfd, RTSMT_ONBOARD_RTIOC_READ, &onBoardReadBuf); --- a/LPCBus/MC9_Right_cleanup.c Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCBus/MC9_Right_cleanup.c Tue Dec 18 14:43:49 2018 +0100
@@ -1,1 +1,1 @@
-rt_dev_close(rightbusfd);
--- a/LPCBus/MC9_Right_init.c Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCBus/MC9_Right_init.c Tue Dec 18 14:43:49 2018 +0100
@@ -1,4 +1,4 @@
-#define DEVICEFILENAME "rightbus"
+#define DEVICEFILENAME "/dev/rtdm/rightbus" bzero(&rightReadBuf, sizeof(rightReadBuf_t));
bzero(&rightWriteBuf, sizeof(rightWriteBuf_t));
@@ -10,17 +10,17 @@
-rightbusfd = rt_dev_open( DEVICEFILENAME, 0);
+rightbusfd = open( DEVICEFILENAME, 0); printf("can't open %%s rtdm device, %%s\\n", DEVICEFILENAME,
-err = rt_dev_ioctl(rightbusfd, RTSMT_RTIOC_INIT, &rightBusInit);
+err = ioctl(rightbusfd, RTSMT_RTIOC_INIT, &rightBusInit); printf("error while RTSMT_RTIOC_INIT, %%s\\n",
- rt_dev_close(rightbusfd);
--- a/LPCBus/MC9_Right_publish.c Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCBus/MC9_Right_publish.c Tue Dec 18 14:43:49 2018 +0100
@@ -1,2 +1,2 @@
-rt_dev_ioctl(rightbusfd, RTSMT_RTIOC_WRITE, &rightWriteBuf);
+ioctl(rightbusfd, RTSMT_RTIOC_WRITE, &rightWriteBuf); --- a/LPCBus/MC9_Right_retrieve.c Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCBus/MC9_Right_retrieve.c Tue Dec 18 14:43:49 2018 +0100
@@ -1,2 +1,2 @@
-rt_dev_ioctl(rightbusfd, RTSMT_RTIOC_READ, &rightReadBuf);
+ioctl(rightbusfd, RTSMT_RTIOC_READ, &rightReadBuf); --- a/LPCCanFestival.py Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCCanFestival.py Tue Dec 18 14:43:49 2018 +0100
@@ -12,17 +12,6 @@
from canfestival.SlaveEditor import SlaveEditor
from canfestival import canfestival
-defaultGetCFLAGS = canfestival.local_canfestival_config.getCFLAGS
-defaultGetLDFLAGS = canfestival.local_canfestival_config.getLDFLAGS
- return str(defaultGetCFLAGS(*args))
- return str(defaultGetLDFLAGS(*args))
-canfestival.local_canfestival_config.getCFLAGS = getCFLAGS
-canfestival.local_canfestival_config.getLDFLAGS = getLDFLAGS
--- a/LPCExtension.py Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCExtension.py Tue Dec 18 14:43:49 2018 +0100
@@ -13,20 +13,20 @@
# _lpcmanager_path, arch, etc are defined here because
# globals() of LPCManager.py are passed to extentions
-features.libraries=[('Native', 'NativeLib.NativeLibrary')]
+features.libraries=[('Native', 'NativeLib.NativeLibrary', True)] return os.path.join(_lpcmanager_path, 'Pous', "pous"+name+".xml")
if arch in PLC_MC9_module:
- features.libraries += [('Python', 'py_ext.PythonLibrary'),
- ('RTC', SimplePOULibraryFactory(_poulibpath("RTC")))]
+ features.libraries += [('Python', 'py_ext.PythonLibrary', True), + ('RTC', SimplePOULibraryFactory(_poulibpath("RTC")), True)] elif arch in PLC_GOT_module:
- features.libraries += [('Python', 'py_ext.PythonLibrary'),
- ('RTC', SimplePOULibraryFactory(_poulibpath("RTC"))),
- ('GOT', SimplePOULibraryFactory(_poulibpath("GOT")))]
+ features.libraries += [('Python', 'py_ext.PythonLibrary', True), + ('RTC', SimplePOULibraryFactory(_poulibpath("RTC")), True), + ('GOT', SimplePOULibraryFactory(_poulibpath("GOT")), True)] - features.libraries += [('LPC', SimplePOULibraryFactory(_poulibpath("LPC")))]
+ features.libraries += [('LPC', SimplePOULibraryFactory(_poulibpath("LPC")), True)] # --------- Configuration Tree Nodes (CTN) catalog extension ------------
@@ -34,8 +34,10 @@
_oldcatalog = features.catalog
catalog_index = dict(zip(zip(*_oldcatalog)[0],_oldcatalog))
wanted_beremiz_features = [catalog_index[feature]
- for feature in ["modbus", "c_ext", "py_ext"]]
+ for feature in ["c_ext", "py_ext", "wxglade_hmi"]] features.catalog = wanted_beremiz_features + [
+ ('bacnet', _('Bacnet support'), _('Map located variables over Bacnet'), 'LPCBACnet.RootClass'), + ('modbus', _('Modbus'), _('Map located variables over Modbus'), 'LPCModbus.RootClass'), ('LPCBus', _('LPC bus'), _('Support for Smarteh modules'), 'LPCBus.LPCBus'),
('CanOpen', _('CANOpen'), _('Support for CANopen'), 'LPCCanFestival.LPCCanOpen')]
@@ -44,9 +46,18 @@
-from LPCconnector import LPC_connector_factory
+from functools import partial -connectors.connectors["LPC"] = lambda: LPC_connector_factory
+# On demand monkey patching +def CustomWAMPFactory(*args, **kwargs): + from connectors import WAMP + from WampAuthentication import WampSession + return WAMP._WAMP_connector_factory(WampSession, *args, **kwargs) +connectors.connectors["WAMP"] = lambda:CustomWAMPFactory +# from LPCconnector import LPC_connector_factory +# connectors.connectors["LPC"] = lambda: LPC_connector_factory # --------- Targets/Toolchains Extension ------------
@@ -64,3 +75,14 @@
"code": {"plc_MC9_main.c": targets.targets["Xenomai"]["code"]["plc_Xenomai_main.c"],
"plc_MC9_main_retain.c": os.path.join(_lpcmanager_path,
"MC9target", "plc_MC9_main_retain.c")}}
+# --------- Custom columns function Extension ------------ +from WampOptionsEditor import WampOptionsCellEditor +from py_ext.PythonEditor import PythonEditor +from wxglade_hmi import WxGladeHMI +from WxGladeEditor import WxGladeEditor +WxGladeHMI.EditorType = WxGladeEditor +PythonEditor.COLUMNS_TYPE = {'Options': WampOptionsCellEditor} --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LPCModbus.py Tue Dec 18 14:43:49 2018 +0100
@@ -0,0 +1,10 @@
+from __future__ import absolute_import +from modbus.modbus import _ModbusRTUclientPlug, _ModbusRTUslavePlug, RootClass +wrong_uart_name = "ttyS0" +good_uart_name = "ttyAPP3" +_ModbusRTUclientPlug.XSD = _ModbusRTUclientPlug.XSD.replace(wrong_uart_name,good_uart_name) +_ModbusRTUslavePlug.XSD = _ModbusRTUslavePlug.XSD.replace(wrong_uart_name,good_uart_name) --- a/LPCProjectController.py Wed Apr 11 13:06:58 2018 +0200
+++ b/LPCProjectController.py Tue Dec 18 14:43:49 2018 +0100
@@ -9,9 +9,9 @@
from LPCArch import PLC_module
from FirmwareUpdateDialog import FirmwareUpdateDialog
-from dialogs import DiscoveryDialog
from HostFirmwareUpdater import HostFirmwareUpdater
+from plcopen.types_enums import ComputeConfigurationResourceName @@ -21,9 +21,17 @@
+LPCDefaultMethods = ProjectController.DefaultMethods.copy() +LPCDefaultMethods["_UpdateFw"]=False +LPCMethodsFromStatus = ProjectController.MethodsFromStatus.copy() +LPCMethodsFromStatus["Started"]["_UpdateFw"] = True +LPCMethodsFromStatus["Stopped"]["_UpdateFw"] = True +LPCMethodsFromStatus["Empty"]["_UpdateFw"] = True class LPCProjectController(ProjectController):
StatusMethods = ProjectController.StatusMethods + LPCStatusMethods
+ DefaultMethods = LPCDefaultMethods + MethodsFromStatus = LPCMethodsFromStatus def __init__(self, frame, logger, buildpath, arch):
@@ -59,7 +67,7 @@
dirname = ops(extrafilespath)[-1]
for name in os.listdir(extrafilespath):
zf.write(opj(extrafilespath, str(name)), opj(dirname, str(name)), zipfile.ZIP_DEFLATED)
- zf.write(self._builder.exe_path, self._builder.exe)
+ zf.write(self._builder.bin_path, self._builder.bin) zf.write(opj(self._getBuildPath(), 'lastbuildPLC.md5'), 'lastbuildPLC.md5')
self.logger.write(_("xEye export file created at: %s\n") % output_file_path)
@@ -107,7 +115,7 @@
ProjectController.AddProjectDefaultConfiguration(self, config_name, res_name)
self.SetEditedResourceInfos(
- self.ComputeConfigurationResourceName(config_name, res_name),
+ ComputeConfigurationResourceName(config_name, res_name), @@ -162,7 +170,6 @@
imageFilePath = dialog.GetFirmwareImageFile()
updateType = dialog.GetFirmwareUpdateType()
chunksSize = dialog.GetChunksSize()
- reboot = dialog.GetReboot()
if answer == wx.ID_CANCEL:
@@ -198,49 +205,6 @@
self.logger.write(_("Chunks size : %d KiB\n") % chunksSize)
- self.logger.write(_("Reboot after update : %s\n") % ("Yes" if reboot else "No"))
- # Get the target PLC URI
- # Check if an uri is already configured in the Beremiz project
- uri = self.BeremizRoot.getURI_location()
- if uri is not None and uri != "":
- self.logger.write(_("PLC URI configured in the Beremiz project will be used: %s\n") % uri)
- # PLC URI is not configured in the Beremiz project
- # Launch Service Discovery dialog
- self.logger.write(_("PLC URI is not configured in the Beremiz project. Launching the Discover dialog\n"))
- dialog = DiscoveryDialog(self.AppFrame)
- answer = dialog.ShowModal()
- # Nothing choosed or cancel button
- if uri is None or answer == wx.ID_CANCEL:
- self.logger.write_error(_("Connection canceled!\n"))
- self.logger.write_error(_("Firmware update canceled!\n"))
- self.firmwareUpadateIsRunning = False
- # Get connector from uri
- self._SetConnector(connectors.ConnectorFactory(uri, self))
- self.logger.write_error(_("Exception while connecting %s!\n") % uri)
- self.logger.write_error(traceback.format_exc())
- self.logger.write_error(_("Firmware update canceled!\n"))
- self.firmwareUpadateIsRunning = False
- # Did connection success ?
- if self._connector is None:
- self.logger.write_error(_("Connection failed to %s!\n") % uri)
- self.logger.write_error(_("Firmware update canceled!\n"))
- self.firmwareUpadateIsRunning = False
- self.logger.write(_("Connected.\n"))
# Last confirmation before firmware update
answer = wx.MessageBox(_('Are you sure to launch the firmware update for the selected PLC?'),
_('Firmware Update'), wx.YES_NO | wx.CENTRE | wx.NO_DEFAULT,
@@ -249,20 +213,52 @@
self.logger.write_error(_("Firmware update canceled!\n"))
self.firmwareUpadateIsRunning = False
+ # do we still have a connection ? + if self._connector is None: + self.logger.write_error(_("Firmware update canceled because connection lost!\n")) + self.firmwareUpadateIsRunning = False + dlg = wx.ProgressDialog(_("Firmware update"), + _("Updating firmware, please wait."), # Lauch the firmaware update on the remote PLC
- updater = HostFirmwareUpdater(self._connector, imageFilePath, updateType, chunksSize, reboot, self.logger)
+ updater = HostFirmwareUpdater(self, imageFilePath, updateType, chunksSize, dlg) self.logger.write_error(str(e) + "\n")
- self.logger.write_error(_("Firmware update canceled!\n"))
+ self.logger.write_error(_("Firmware update failed!\n")) + if not dlg.WasCancelled(): + dlg.Update(100, _("Firmware update failed!\n(%s)"%str(e))) self.firmwareUpadateIsRunning = False
+ answer = wx.MessageBox(_('Firmware update requires reboot to complete. Reboot PLC now?'), + _('Firmware Update'), wx.YES_NO | wx.CENTRE | wx.NO_DEFAULT, + self.logger.write(_("Rebooting PLC.\n"))
- self.firmwareUpadateIsRunning = False
--- a/MC8ProjectController.py Wed Apr 11 13:06:58 2018 +0200
+++ b/MC8ProjectController.py Tue Dec 18 14:43:49 2018 +0100
@@ -768,14 +768,11 @@
self.AbortTransferTimer = None
+ # FIXME: MC8 doesn't know how to deal with any of this... Method called by user to flash the firmware of the PLC
- from FirmwareUpdateDialog import FirmwareUpdateDialog
- from dialogs import DiscoveryDialog
- from HostFirmwareUpdater import HostFirmwareUpdater
if self.firmawreUpadateIsRunning == True:
self.logger.write_error(_("Firmware update is already running!\n"))
--- a/MC9target/XSD Wed Apr 11 13:06:58 2018 +0200
+++ b/MC9target/XSD Tue Dec 18 14:43:49 2018 +0100
@@ -1,9 +1,9 @@
- <xsd:attribute name="Compiler" type="xsd:string" use="optional" default="arm-none-linux-gnueabi-gcc"/>
- <xsd:attribute name="CFLAGS" type="xsd:string" use="optional" default="--sysroot=../arm-none-linux-gnueabi-apf28 -I../arm-none-linux-gnueabi-apf28/usr/include/xenomai -D_GNU_SOURCE -D_REENTRANT -DHAVE_RETAIN -Wall -pipe -D__XENO__ -Wno-unused-but-set-variable -Wno-unused-function -Wno-unused-variable"/>
- <xsd:attribute name="Linker" type="xsd:string" use="optional" default="arm-none-linux-gnueabi-gcc"/>
- <xsd:attribute name="LDFLAGS" type="xsd:string" use="optional" default="--sysroot=../arm-none-linux-gnueabi-apf28 -lnative -lxenomai -lpthread -lrtdm"/>
+ <xsd:attribute name="Compiler" type="xsd:string" use="optional" default="arm-unknown-linux-gnueabi-gcc"/> + <xsd:attribute name="CFLAGS" type="xsd:string" use="optional" default="--sysroot=../arm-linux-gnueabi-apf28 -DHAVE_RETAIN -pipe -Wno-unused-but-set-variable -Wno-unused-function -Wno-unused-variable -I../arm-linux-gnueabi-apf28/usr/include/xenomai/cobalt -I../arm-linux-gnueabi-apf28/usr/include/xenomai -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os -D_GNU_SOURCE -D_REENTRANT -fasynchronous-unwind-tables -D__COBALT__ -I../arm-linux-gnueabi-apf28/usr/include/xenomai/alchemy -D__COBALT_WRAP__ "/> + <xsd:attribute name="Linker" type="xsd:string" use="optional" default="arm-unknown-linux-gnueabi-gcc"/> + <xsd:attribute name="LDFLAGS" type="xsd:string" use="optional" default="--sysroot=../arm-linux-gnueabi-apf28 -lpthread -Wl,--no-as-needed -Wl,@../arm-linux-gnueabi-apf28/usr/lib/cobalt.wrappers -Wl,@../arm-linux-gnueabi-apf28/usr/lib/modechk.wrappers -lalchemy -lcopperplate -L../arm-linux-gnueabi-apf28/usr/lib -lcobalt -lmodechk -lpthread -lrt "/> <xsd:attribute name="XenoConfig" type="xsd:string" use="optional"/>
--- a/MC9target/plc_MC9_main_retain.c Wed Apr 11 13:06:58 2018 +0200
+++ b/MC9target/plc_MC9_main_retain.c Tue Dec 18 14:43:49 2018 +0100
@@ -1,10 +1,10 @@
-#include <native/event.h>
-#include <native/mutex.h>
+#include <alchemy/event.h> +#include <alchemy/mutex.h> #include <rtdm/spi_apf28_rtdm_ioctl.h>
+#include <xenomai/init.h> -#define TEST_SPI_BUS_NUMBER 2
/* SPI configurable parameters */
/* --------------------------- */
@@ -60,24 +60,24 @@
- if (rt_dev_ioctl(fd_spi, RTDM_SPI_LOCK_CS_SET, &uint) < 0) {
+ if (ioctl(fd_spi, RTDM_SPI_LOCK_CS_SET, &uint) < 0) { printf("Failed to lock CS\n");
- status = rt_dev_write(fd_spi, rcmd, ARRAY_SIZE(rcmd));
+ status = write(fd_spi, rcmd, ARRAY_SIZE(rcmd)); fprintf(stderr, "Failed to send read command. ERR : %d\n", status);
- if (rt_dev_ioctl(fd_spi, RTDM_SPI_LOCK_CS_SET, &uint) < 0) {
+ if (ioctl(fd_spi, RTDM_SPI_LOCK_CS_SET, &uint) < 0) { printf("Failed to unlock CS\n");
- size = rt_dev_read(fd_spi, buf, len);
+ size = read(fd_spi, buf, len); fprintf(stderr, "Failed to read %d bytes on the SPI bus. size : %d\n",
@@ -89,7 +89,7 @@
int SPI_Write(void *buf, unsigned int len){
- status = rt_dev_write(fd_spi, buf, len);
+ status = write(fd_spi, buf, len); fprintf(stderr, "Failed to write memory. ERR : %d\n", status);
@@ -103,7 +103,7 @@
/* Open the SPI RTDM device */
- if ((fd_spi = rt_dev_open("spi_apf28_rtdm", TEST_SPI_BUS_NUMBER)) < 0) {
+ if ((fd_spi = open("/dev/rtdm/spi_apf28_rtdm", 0)) < 0) { printf("rt_spi_open error\n");
@@ -112,66 +112,66 @@
uint = TEST_SPI_CLK_PHASE;
- if (rt_dev_ioctl(fd_spi, RTDM_SPI_CLKPHASE_SET, &uint) < 0) {
+ if (ioctl(fd_spi, RTDM_SPI_CLKPHASE_SET, &uint) < 0) { printf("Failed to configure the clock phase\n");
- if (rt_dev_ioctl(fd_spi, RTDM_SPI_CLKPHASE_GET, &uint) < 0) {
+ if (ioctl(fd_spi, RTDM_SPI_CLKPHASE_GET, &uint) < 0) { printf("Failed to get the clock phase\n");
uint = TEST_SPI_CLK_POLARITY;
- if (rt_dev_ioctl(fd_spi, RTDM_SPI_CLKPOLARITY_SET, &uint) < 0) {
+ if (ioctl(fd_spi, RTDM_SPI_CLKPOLARITY_SET, &uint) < 0) { printf("Failed to configure the clock polarity\n");
- if (rt_dev_ioctl(fd_spi, RTDM_SPI_CLKPOLARITY_GET, &uint) < 0) {
+ if (ioctl(fd_spi, RTDM_SPI_CLKPOLARITY_GET, &uint) < 0) { printf("Failed to get the clock polarity\n");
- if (rt_dev_ioctl(fd_spi, RTDM_SPI_FREQ_SET, &ulong) < 0) {
+ if (ioctl(fd_spi, RTDM_SPI_FREQ_SET, &ulong) < 0) { printf("Failed to configure the frequency\n");
- if (rt_dev_ioctl(fd_spi, RTDM_SPI_FREQ_GET, &ulong) < 0) {
+ if (ioctl(fd_spi, RTDM_SPI_FREQ_GET, &ulong) < 0) { printf("Failed to get the frequency\n");
uint = TEST_SPI_BITS_PER_WORD;
- if (rt_dev_ioctl(fd_spi, RTDM_SPI_BITSPERWORD_SET, &uint) < 0) {
+ if (ioctl(fd_spi, RTDM_SPI_BITSPERWORD_SET, &uint) < 0) { printf("Failed to configure the BPW\n");
- if (rt_dev_ioctl(fd_spi, RTDM_SPI_BITSPERWORD_GET, &uint) < 0) {
+ if (ioctl(fd_spi, RTDM_SPI_BITSPERWORD_GET, &uint) < 0) { printf("Failed to get the BPW\n");
uint = TEST_SPI_CHIPSELECT1;
- if (rt_dev_ioctl(fd_spi, RTDM_SPI_CHIPSELECT_SET, &uint) < 0) {
+ if (ioctl(fd_spi, RTDM_SPI_CHIPSELECT_SET, &uint) < 0) { printf("Failed to configure the chip select\n");
- if (rt_dev_ioctl(fd_spi, RTDM_SPI_CHIPSELECT_GET, &uint) < 0) {
+ if (ioctl(fd_spi, RTDM_SPI_CHIPSELECT_GET, &uint) < 0) { printf("Failed to get the chip select\n");
/* DMA usage definition */
uint = TEST_SPI_DMA_BYTES_MIN;
- if (rt_dev_ioctl(fd_spi, RTDM_SPI_DMA_SET, &uint) < 0) {
+ if (ioctl(fd_spi, RTDM_SPI_DMA_SET, &uint) < 0) { printf("Failed to configure the DMA threshold\n");
- if (rt_dev_ioctl(fd_spi, RTDM_SPI_DMA_GET, &uint) < 0) {
+ if (ioctl(fd_spi, RTDM_SPI_DMA_GET, &uint) < 0) { printf("Failed to get the DMA threshold\n");
@@ -194,7 +194,7 @@
- status = rt_dev_write(fd_spi, mbuf, ARRAY_SIZE(mbuf));
+ status = write(fd_spi, mbuf, ARRAY_SIZE(mbuf)); printf("Failed to change mode. ERR : %d\n", status);
@@ -206,7 +206,7 @@
void RETAIN_task_proc(void *arg)
while (!rt_event_wait(&RETAIN_Event, 1, &msk, EV_ANY, TM_INFINITE)) {
if(rt_mutex_acquire(&RETAIN_Mutex, TM_INFINITE)) return;
--- a/Pous/pousGOT.xml Wed Apr 11 13:06:58 2018 +0200
+++ b/Pous/pousGOT.xml Tue Dec 18 14:43:49 2018 +0100
@@ -17,7 +17,7 @@
- <pou name="Backlight_dimmer" pouType="functionBlock">
+ <pou name="Set_Brightness" pouType="functionBlock"> @@ -25,67 +25,97 @@
- <variable name="TYPE_VALUE">
+ <variable name="PERCENT">
- <variable name="DIMM_VALUE">
- <variable name="pooll0">
- <derived name="python_poll"/>
- <variable name="RESULT">
- <variable name="INPUT_ARGS">
- <variable name="INPUT_TYPE">
- <variable name="INPUT_VALUE">
- <variable name="INPUT_VALUE_CODE">
+ <derived name="python_eval"/> - <xhtml:p><![CDATA[INPUT_TYPE:=INT_TO_STRING(TYPE_VALUE); INPUT_VALUE:=INT_TO_STRING(DIMM_VALUE); INPUT_ARGS:=CONCAT(INPUT_TYPE, ',', INPUT_VALUE); INPUT_VALUE_CODE:=CONCAT('PLCObject.MWProvider.SetDimmerValue(', INPUT_ARGS, ')'); pooll0(TRIG := TRIG, CODE := INPUT_VALUE_CODE, ACK => ACK, RESULT => RESULT);]]></xhtml:p>
+ <xhtml:p><![CDATA[(* Set dimmer value *) + UINT_TO_STRING(PERCENT), - <xhtml:p><![CDATA[Backlight_dimmer function block allows the manipulation of brightness. TYPE_VALUE ranges from 0 to 3, where 0 is no fading, 1 slowly changes brightness when lowering it, 2 slowly changes brightness when rising it and 3 slowly changes it both ways. DIMM_VALUE ranges from 0 to 26 and changes the brightness value.]]></xhtml:p>
+ <xhtml:p><![CDATA[Set backlight brightness to PERCENT on raising edge of TRIG.]]></xhtml:p> + <pou name="Fade_Brightness" pouType="functionBlock"> + <variable name="PERCENT"> + <variable name="TIME_MS"> + <derived name="python_eval"/> + <xhtml:p><![CDATA[(* Fade dimmer value *) + UINT_TO_STRING(PERCENT), + UINT_TO_STRING(TIME_MS), + <xhtml:p><![CDATA[Start fading backlight brightness on raising edge of TRIG, from current value to PERCENT, in TIME_MS miliseconds.]]></xhtml:p> <pou name="Buzzer" pouType="functionBlock">
@@ -98,9 +128,9 @@
- <variable name="pooll0">
- <derived name="python_poll"/>
+ <derived name="python_eval"/> @@ -108,24 +138,19 @@
- <variable name="RESULT">
- <variable name="INPUT_VALUE_OLD">
- <variable name="INPUT_VALUE_CODE">
+ <variable name="APPLIED_VAL">
+ <variable name="ORDERED_VAL"> @@ -133,15 +158,47 @@
+ <variable name="rtrig"> + <derived name="R_TRIG"/> - <xhtml:p><![CDATA[TRIG :=TRUE; INPUT_VALUE_CODE:=CONCAT('PLCObject.MWProvider.SetBuzzerValue(', INT_TO_STRING(BOOL_TO_INT(INPUT_VALUE)), ')'); pooll0(TRIG := TRIG, CODE := INPUT_VALUE_CODE, ACK => ACK, RESULT => RESULT);]]></xhtml:p>
+ <xhtml:p><![CDATA[(* Turn buzzer on or off *) +(* test if not already waiting for ack, and there is change to apply *) +IF NOT(TRIG & NOT(ACK)) & (APPLIED_VAL <> INPUT_VALUE) THEN + ORDERED_VAL := INPUT_VALUE; + INT_TO_STRING(BOOL_TO_INT(INPUT_VALUE)), +rtrig(CLK := ACK, Q => RACK); + APPLIED_VAL := ORDERED_VAL; - <xhtml:p><![CDATA[Buzzer function block provides a buzz sound]]></xhtml:p>
+ <xhtml:p><![CDATA[Turns buzzer on or off, according to input value]]></xhtml:p> --- a/Pous/pousRTC.xml Wed Apr 11 13:06:58 2018 +0200
+++ b/Pous/pousRTC.xml Tue Dec 18 14:43:49 2018 +0100
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.plcopen.org/xml/tc6_0201" xmlns:xhtml="http://www.w3.org/1999/xhtml" xsi:schemaLocation="http://www.plcopen.org/xml/tc6_0201">
<fileHeader companyName="Beremiz" productName="Beremiz" productVersion="0.0" creationDateTime="2008-12-14T16:53:26"/>
- <contentHeader name="Beremiz non-standard POUs library" modificationDateTime="2014-03-17T08:07:24">
+ <contentHeader name="Beremiz non-standard POUs library" modificationDateTime="2018-09-06T13:45:38"> @@ -17,19 +17,74 @@
- <pou name="getRTC" pouType="functionBlock">
+ <pou name="getRTCString" pouType="functionBlock"> + <derived name="python_eval"/> + <xhtml:p><![CDATA[(* Get time from RTC *) +eval(TRIG:=TRIG, CODE:='GetRTC()', ACK => ACK, RESULT => DT_STR);]]></xhtml:p> + <xhtml:p><![CDATA[Sample time from RTC on raising edge of TRIG. Outputs a formated string in DT_STR and sets ACK to TRUE when output is ready. + YYYY-mm-dd HH:MM:SS w v + 2018-07-28 11:24:07 6 1]]></xhtml:p> + <pou name="getRTC" pouType="functionBlock">
@@ -49,7 +104,7 @@
@@ -67,22 +122,22 @@
- <variable name="pooll0">
- <derived name="python_poll"/>
+ <derived name="python_eval"/>
+ <variable name="rtrig"> + <derived name="R_TRIG"/> + <variable name="COMPUTE"> - <variable name="INPUT_VALUE_CODE">
+ <variable name="DT_STR"> @@ -91,9 +146,30 @@
- <xhtml:p><![CDATA[INPUT_VALUE_CODE:=CONCAT('PLCObject.MWProvider.GetRTC()'); pooll0(TRIG:=TRUE, CODE:=INPUT_VALUE_CODE, ACK => ACK, RESULT => DT_STR); VALID:=STRING_TO_BOOL(IN:=MID(IN:=DT_STR,L:=1,P:=23)); YEAR:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=4,P:=1)); MONTH:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=6)); DAY:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=9)); WDAY:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=1,P:=21)); HOUR:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=12)); MINUTE:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=15)); SECOND:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=18));]]></xhtml:p>
+ <xhtml:p><![CDATA[(* Get time from RTC *) +eval(TRIG:=TRIG, CODE:='GetRTC()', ACK => ACK, RESULT => DT_STR); +rtrig(CLK := ACK, Q => COMPUTE); +IF COMPUTE OR (TRIG & ACK ) THEN + VALID:=STRING_TO_BOOL(IN:=MID(IN:=DT_STR,L:=1,P:=23)); + YEAR:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=4,P:=1)); + MONTH:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=6)); + DAY:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=9)); + WDAY:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=1,P:=21)); + HOUR:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=12)); + MINUTE:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=15)); + SECOND:=STRING_TO_UINT(IN:=MID(IN:=DT_STR,L:=2,P:=18)); + <xhtml:p><![CDATA[Sample time from RTC on raising edge of TRIG. Outputs time as separate values and sets ACK to TRUE when output is ready. VALID is FALSE if hardware clock had a power failure and time is incorrect, TRUE otherwise.]]></xhtml:p> <pou name="setRTC" pouType="functionBlock">
@@ -135,19 +211,29 @@
- <variable name="RESULT">
+ <variable name="VALID"> - <variable name="pooll0">
- <derived name="python_poll"/>
+ <derived name="python_eval"/>
+ <variable name="rtrig"> + <derived name="R_TRIG"/> + <variable name="COMPUTE"> @@ -162,7 +248,7 @@
+ <variable name="RESULT"> @@ -171,9 +257,28 @@
- <xhtml:p><![CDATA[INPUT_ARGS:=CONCAT(UINT_TO_STRING(YEAR), ',', UINT_TO_STRING(MONTH), ',', UINT_TO_STRING(DAY), ',', UINT_TO_STRING(HOUR), ',', UINT_TO_STRING(MINUTE), ',', UINT_TO_STRING(SECOND)); INPUT_VALUE_CODE:=CONCAT('PLCObject.MWProvider.SetRTC(', INPUT_ARGS, ')'); pooll0(TRIG := TRIG, CODE := INPUT_VALUE_CODE, ACK => ACK, RESULT => RESULT);]]></xhtml:p>
+ <xhtml:p><![CDATA[(* Set RTC time *) +rtrig(CLK := TRIG, Q => COMPUTE); + INPUT_VALUE_CODE:=CONCAT( + UINT_TO_STRING(YEAR), ',', + UINT_TO_STRING(MONTH), ',', + UINT_TO_STRING(DAY), ',', + UINT_TO_STRING(HOUR), ',', + UINT_TO_STRING(MINUTE), ',', + UINT_TO_STRING(SECOND), ')'); +eval(TRIG := TRIG, CODE := INPUT_VALUE_CODE, ACK => ACK, RESULT => RESULT); + VALID := RESULT = 'True'; + <xhtml:p><![CDATA[Set RTC time on raising edge of TRIG]]></xhtml:p> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/WampAuthentication.py Tue Dec 18 14:43:49 2018 +0100
@@ -0,0 +1,19 @@
+# XXX remove that crap, seriously +from connectors import WAMP +from autobahn.wamp import auth +class WampSession(WAMP.WampSession): + self.join(u"Automation", [u"wampcra"], u"smarteh") + print("CRA checking ...") + def onChallenge(self, challenge): + if challenge.method == "wampcra": + key = auth.derive_key("smarteh", "salt123", 100, 16) + return auth.compute_wcs(key, challenge.extra['challenge']) + raise Exception("don't know how to handle authmethod {}".format(challenge.method)) --- a/WampOptionsEditor.py Wed Apr 11 13:06:58 2018 +0200
+++ b/WampOptionsEditor.py Tue Dec 18 14:43:49 2018 +0100
@@ -1,255 +1,419 @@
-[ID_OPTIONSWIZARDDIALOG,ID_ONCHANGE,ID_OPTIONSTYPECHOICE,ID_SUBGROUPTEXT,ID_UNITTEXT,ID_VALUECHECKBOX,ID_MINSPIN,ID_MAXSPIN,ID_PRECISIONSPIN,ID_SCADACHECKBOX,ID_OTHERTEXT,ID_DESCRIPTION,ID_STATIC] = [wx.NewId() for _init_ctrls in range(13)]
-VARIABLETYPE = ["", "Static", "Session", "Alarm"]
-class WampOptionsEditor(wx.Dialog):
- def _init_sizers(self):
- #self.MainSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
- self.MainSizer = wx.BoxSizer(wx.VERTICAL)
- #self.OptionsSizer = wx.FlexGridSizer(cols=2, hgap=10, rows=12, vgap=10)
- self.TypeSizer = wx.BoxSizer(wx.HORIZONTAL)
- self.TypeSizer.Add(wx.StaticText(self,wx.ID_ANY,"Type:"), flag=wx.LEFT, border=10, proportion=1)
- self.TypeSizer.Add(self.OptionsTypeChoice, proportion=2)
- self.MainSizer.Add(self.TypeSizer, flag=wx.EXPAND|wx.RIGHT|wx.TOP, border=10)
- self.OnChangeSizer = wx.BoxSizer(wx.HORIZONTAL)
- self.OnChangeSizer.Add(self.OnChangeCheckbox, flag=wx.LEFT, border=10)
- self.OnChangeSizer.Add(wx.StaticText(self, wx.ID_ANY, "On Change"), flag=wx.LEFT | wx.ALIGN_RIGHT, border=10)
- self.MainSizer.Add(self.OnChangeSizer, flag=wx.EXPAND | wx.RIGHT | wx.TOP, border=10)
- self.ScadaSizer = wx.BoxSizer(wx.HORIZONTAL)
- self.ScadaSizer.Add(self.ScadaCheckbox, flag=wx.LEFT, border=10)
- self.ScadaSizer.Add(wx.StaticText(self, wx.ID_ANY, "Scada"), flag=wx.LEFT, proportion=1, border=10)
- self.MainSizer.Add(self.ScadaSizer, flag=wx.EXPAND | wx.RIGHT | wx.TOP, border=10)
- self.StaticSizer = wx.BoxSizer(wx.HORIZONTAL)
- self.StaticSizer.Add(self.StaticCheckbox, flag=wx.LEFT, border=10)
- self.StaticSizer.Add(wx.StaticText(self, wx.ID_ANY, "Static"), flag=wx.LEFT, proportion=1, border=10)
- self.MainSizer.Add(self.StaticSizer, flag=wx.EXPAND | wx.RIGHT | wx.TOP, border=10)
- self.SubgroupSizer = wx.BoxSizer(wx.HORIZONTAL)
- self.SubgroupSizer.Add(wx.StaticText(self,wx.ID_ANY,"Subgroup:"), flag=wx.LEFT, proportion=1, border=10)
- self.SubgroupSizer.Add(self.SubgroupText, flag=wx.LEFT, border=10, proportion=2)
- self.MainSizer.Add(self.SubgroupSizer, flag=wx.EXPAND | wx.RIGHT | wx.TOP, border=10)
- self.UnitSizer = wx.BoxSizer(wx.HORIZONTAL)
- self.UnitSizer.Add(wx.StaticText(self,wx.ID_ANY,"Unit:"), flag=wx.LEFT, proportion=1, border=10)
- self.UnitSizer.Add(self.UnitText, flag=wx.LEFT, proportion=2, border=10)
- self.MainSizer.Add(self.UnitSizer, flag=wx.EXPAND | wx.RIGHT | wx.TOP, border=10)
- self.ValueSizer = wx.BoxSizer(wx.HORIZONTAL)
- self.ValueSizer.Add(self.ValueCheckbox, flag=wx.LEFT, border=10)
- self.ValueSizer.Add(wx.StaticText(self,wx.ID_ANY,"Enable min/max value"), flag=wx.LEFT, proportion=1, border=10)
- self.MainSizer.Add(self.ValueSizer, flag=wx.EXPAND | wx.RIGHT | wx.TOP, proportion=2, border=10)
- self.minValue=wx.StaticText(self, wx.ID_ANY, "Min value:")
- self.maxValue=wx.StaticText(self, wx.ID_ANY, "Max value:")
- self.PrecisionValue = wx.StaticText(self, wx.ID_ANY, "Precision:")
- self.MinSizer = wx.BoxSizer(wx.HORIZONTAL)
- self.MinSizer.Add(self.minValue, flag=wx.LEFT, border=10, proportion=1)
- self.MinSizer.Add(self.MinSpin, flag=wx.LEFT, proportion=2, border=10)
- self.MainSizer.Add(self.MinSizer, flag=wx.EXPAND | wx.RIGHT | wx.TOP, border=10)
- self.MaxSizer = wx.BoxSizer(wx.HORIZONTAL)
- self.MaxSizer.Add(self.maxValue, flag=wx.LEFT, border=10, proportion=1)
- self.MaxSizer.Add(self.MaxSpin, flag=wx.LEFT, proportion=2, border=10)
- self.MainSizer.Add(self.MaxSizer, flag=wx.EXPAND | wx.RIGHT | wx.TOP, border=10)
- self.PrecisionSizer = wx.BoxSizer(wx.HORIZONTAL)
- self.PrecisionSizer.Add(self.PrecisionValue, flag=wx.LEFT, border=10, proportion=1)
- self.PrecisionSizer.Add(self.PrecisionSpin, flag=wx.LEFT, proportion=2, border=10)
- self.MainSizer.Add(self.PrecisionSizer, flag=wx.EXPAND | wx.RIGHT | wx.TOP, border=10)
- self.OtherSizer = wx.BoxSizer(wx.HORIZONTAL)
- self.OtherSizer.Add(wx.StaticText(self, wx.ID_ANY, "Other:"), flag=wx.LEFT, border=10, proportion=1)
- self.OtherSizer.Add(self.OtherText, flag=wx.LEFT, proportion=2, border=10)
- self.MainSizer.Add(self.OtherSizer, flag=wx.EXPAND | wx.RIGHT | wx.TOP, border=10)
- self.DescriptionSizer = wx.BoxSizer(wx.VERTICAL)
- self.DescriptionSizer.Add(wx.StaticText(self, wx.ID_ANY, "Description:"), border=10)
- self.DescriptionSizer.Add(self.DescriptionText, flag=wx.EXPAND | wx.UP | wx.DOWN, proportion=1, border=10)
- self.MainSizer.Add(self.DescriptionSizer, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=10)
- self.ButtonSizer.AddWindow(self.ClearButton, flag=wx.ALIGN_CENTER_HORIZONTAL)
- #self.MainSizer.AddSizer(self.OptionsSizer, 0, border=20, flag=wx.ALL)
- self.MainSizer.AddSizer(self.ButtonSizer, 0, border=10, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM)
- self.SetSizer(self.MainSizer)
- def _init_ctrls(self, prnt):
- wx.Dialog.__init__(self, id=ID_OPTIONSWIZARDDIALOG,
- name='OptionsWizard', parent=prnt,
- size=wx.Size(258, 520), style=wx.DEFAULT_DIALOG_STYLE,
- self.OptionsTypeChoice = wx.Choice(parent=self, id=ID_OPTIONSWIZARDDIALOG,
- self.Bind(wx.EVT_CHOICE, self.OnTypeChoice, self.OptionsTypeChoice)
- self.OnChangeCheckbox = wx.CheckBox(parent=self, id=ID_ONCHANGE)
- self.SubgroupText = wx.TextCtrl(parent=self, id=ID_SUBGROUPTEXT)
- self.UnitText = wx.TextCtrl(parent=self, id=ID_UNITTEXT)
- self.ValueCheckbox = wx.CheckBox(parent=self, id=ID_VALUECHECKBOX)
- self.MinSpin = wx.SpinCtrl(parent=self, id=ID_MINSPIN, style=wx.SP_VERTICAL)
- self.MaxSpin = wx.SpinCtrl(parent=self, id=ID_MAXSPIN, style=wx.SP_VERTICAL)
- self.PrecisionSpin = wx.SpinCtrl(parent=self, id=ID_PRECISIONSPIN, style=wx.SP_VERTICAL)
- #self.MinSpin.SetRange(-sys.maxsize, sys.maxsize)
- self.MinSpin.SetRange(-9999, 9999)
- #self.MaxSpin.SetRange(-sys.maxsize, sys.maxsize)
- self.MaxSpin.SetRange(-9999, 9999)
- self.ScadaCheckbox = wx.CheckBox(parent=self, id=ID_SCADACHECKBOX)
- self.StaticCheckbox = wx.CheckBox(parent=self, id=ID_SCADACHECKBOX)
- self.OtherText = wx.TextCtrl(parent=self, id=ID_OTHERTEXT)
- self.DescriptionText = wx.TextCtrl(parent=self, id=ID_DESCRIPTION, size=(-1, 100), style=wx.TE_MULTILINE | wx.SUNKEN_BORDER)
- self.ClearButton = wx.Button(self, wx.ID_CLEAR, "Clear")
- self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL)
- self.ValueCheckbox.Bind(wx.EVT_CHECKBOX, self.EnableValue)
- self.MinSpin.Enable(False)
- self.MaxSpin.Enable(False)
- self.OnChangeCheckbox.Enable(False)
- self.StaticCheckbox.Enable(False)
- self.Bind(wx.EVT_CHOICE, self.Enabler, self.OptionsTypeChoice)
- self.Bind(wx.EVT_BUTTON, self.clearOptions, self.ClearButton)
- self.Bind(wx.EVT_CHECKBOX, self.Enabler, self.ScadaCheckbox)
- def __init__(self, parent, opt, desc):
- self._init_ctrls(parent)
- self.SetOptions(opt, desc)
- def Enabler(self, event):
- if self.OptionsTypeChoice.GetSelection() in [1,3]:
- self.OnChangeCheckbox.Enable(True)
- self.OnChangeCheckbox.Enable(False)
- if self.OptionsTypeChoice.GetSelection() == 3 and self.ScadaCheckbox.GetValue():
- self.StaticCheckbox.Enable(True)
- self.StaticCheckbox.Enable(False)
- def clearOptions(self, event):
- self.OptionsTypeChoice.SetSelection(0)
- self.SubgroupText.SetLabel("")
- self.UnitText.SetLabel("")
- self.MinSpin.SetValue(0)
- self.MaxSpin.SetValue(0)
- self.ValueCheckbox.SetValue(False)
- self.ScadaCheckbox.SetValue(False)
- self.StaticCheckbox.SetValue(False)
- self.OtherText.SetLabel("")
- self.MinSpin.Enable(False)
- self.MaxSpin.Enable(False)
- self.StaticCheckbox.Enable(False)
- self.PrecisionSpin.SetValue(0)
- self.OnChangeCheckbox.SetValue(False)
- self.DescriptionText.SetLabel("")
- def OnTypeChoice(self, event):
- self.selected = event.GetSelection()
- def EnableValue(self, event):
- self.MinSpin.Enable(self.ValueCheckbox.GetValue())
- self.MaxSpin.Enable(self.ValueCheckbox.GetValue())
- # def MinChange(self,event):
- # self.minValue.SetLabel("Min value: " + str(self.MinSpin.GetValue()))
- # def MaxChange(self,event):
- # self.maxValue.SetLabel("Max value: " + str(self.MaxSpin.GetValue()))
- def SetOptions(self, opt, desc):
- optionsTemp = opt1.split(" ")
- options.append(el.split("="))
- self.clearOptions(None)
- # self.ScadaCheckbox.SetValue(False)
- # self.StaticCheckbox.Enable(False)
- # self.StaticCheckbox.SetValue(False)
- self.OptionsTypeChoice.SetSelection(0)
- elif el[0] == "Static":
- self.OptionsTypeChoice.SetSelection(1)
- elif el[0] == "Session":
- self.OptionsTypeChoice.SetSelection(2)
- self.OptionsTypeChoice.SetSelection(3)
- self.ScadaCheckbox.SetValue(True)
- self.StaticCheckbox.Enable(True)
- self.StaticCheckbox.SetValue(True)
- if el[0] == "subgroup":
- self.SubgroupText.SetLabel(el[1])
- self.UnitText.SetLabel(el[1])
- self.ValueCheckbox.SetValue(True)
- self.MinSpin.SetValue(int(el[1]))
- self.MinSpin.Enable(True)
- self.ValueCheckbox.SetValue(True)
- self.MaxSpin.SetValue(int(el[1]))
- self.MaxSpin.Enable(True)
- self.OtherText.SetLabel(el[1])
- elif el[0] == "precision":
- self.PrecisionSpin.SetValue(int(el[1]))
- self.OnChangeCheckbox.Enable(True)
- self.OnChangeCheckbox.SetValue(True)
- if self.OptionsTypeChoice.GetSelection() == 3 and self.ScadaCheckbox.GetValue():
- self.StaticCheckbox.Enable(True)
- self.DescriptionText.SetLabel(desc)
- self.TypeSelected = self.OptionsTypeChoice.GetSelection()
- if self.TypeSelected<0:
- options = VARIABLETYPE[self.TypeSelected]
- if self.ScadaCheckbox.GetValue():
- if self.StaticCheckbox.GetValue():
- if self.SubgroupText.GetLineText(0) != "":
- options += " subgroup=" + self.SubgroupText.GetLineText(0)
- if self.UnitText.GetLineText(0) != "":
- options += " unit=" + self.UnitText.GetLineText(0)
- if self.MinSpin.IsEnabled():
- options += " min=" + str(self.MinSpin.GetValue())
- options += " max=" + str(self.MaxSpin.GetValue())
- if self.PrecisionSpin.GetValue() != 0:
- options += " precision=" + str(self.PrecisionSpin.GetValue())
- if self.OtherText.GetLineText(0) != "":
- options += " other=" + self.OtherText.GetLineText(0)
- if self.OnChangeCheckbox.GetValue():
- if VARIABLETYPE[self.TypeSelected] == "Alarm":
- elif VARIABLETYPE[self.TypeSelected] == "Static":
- self.value = "StoredValue"
- self.Description = self.DescriptionText.GetValue()
- return options, self.OnChange,self.value, self.Description
\ No newline at end of file
+from __future__ import absolute_import +[ID_OPTIONSWIZARDDIALOG,ID_ONCHANGE,ID_OPTIONSTYPECHOICE,ID_SUBGROUPTEXT,ID_UNITTEXT,ID_VALUECHECKBOX,ID_MINSPIN,ID_MAXSPIN,ID_PRECISIONSPIN, ID_INITIALSPIN,ID_SCADACHECKBOX,ID_OTHERTEXT,ID_DESCRIPTION,ID_STATIC] = [wx.NewId() for _init_ctrls in range(14)] +VARIABLETYPE = ["None", "Static", "Session", "Alarm"] +class WampOptionsEditor(wx.Dialog): + def _init_sizers(self): + self.MainSizer = wx.BoxSizer(wx.VERTICAL) + self.PropertySizer = wx.FlexGridSizer(cols=2, hgap=10, rows=13, vgap=10) + self.PropertySizer.AddWindow(wx.StaticText(self,wx.ID_ANY,_("Type:")), flag=wx.ALIGN_CENTER_VERTICAL | wx.GROW | wx.LEFT, border=15) + self.PropertySizer.AddWindow(self.OptionsTypeChoice, 1, flag= wx.EXPAND) + self.PropertySizer.AddWindow(self.OnChangeCheckbox, flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=15) + self.PropertySizer.AddWindow(wx.StaticText(self, wx.ID_ANY, _("On Change")), 1, flag=wx.GROW | wx.EXPAND) + self.PropertySizer.AddWindow(self.ScadaCheckbox, flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=15) + self.PropertySizer.AddWindow(wx.StaticText(self, wx.ID_ANY, _("Scada")), 1, flag=wx.GROW | wx.EXPAND) + self.PropertySizer.AddWindow(self.StaticCheckbox, flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=15) + self.PropertySizer.AddWindow(wx.StaticText(self, wx.ID_ANY, _("Static")), 1, flag=wx.GROW | wx.EXPAND) + self.PropertySizer.AddWindow(wx.StaticText(self,wx.ID_ANY, _("Subgroup:")), flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=15) + self.PropertySizer.AddWindow(self.SubgroupText, 1, flag=wx.GROW | wx.EXPAND) + self.PropertySizer.AddWindow(wx.StaticText(self,wx.ID_ANY, _("Unit:")), flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=15) + self.PropertySizer.AddWindow(self.UnitText, 1, flag=wx.GROW | wx.EXPAND) + self.PropertySizer.AddWindow(self.ValueCheckbox, flag=wx.GROW | wx.LEFT, border=15) + self.PropertySizer.AddWindow(wx.StaticText(self,wx.ID_ANY, _("Enable min/max value")), flag=wx.ALIGN_CENTER_VERTICAL) + self.minValue=wx.StaticText(self, wx.ID_ANY, _("Min value:")) + self.maxValue=wx.StaticText(self, wx.ID_ANY, _("Max value:")) + self.PrecisionValue = wx.StaticText(self, wx.ID_ANY, _("Precision:")) + self.InitialValue = wx.StaticText(self, wx.ID_ANY, _("Initial:")) + self.PropertySizer.AddWindow(self.minValue, flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=15) + self.PropertySizer.AddWindow(self.MinSpin, flag=wx.GROW) + self.PropertySizer.AddWindow(self.maxValue, flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=15) + self.PropertySizer.AddWindow(self.MaxSpin, flag=wx.GROW) + self.PropertySizer.AddWindow(self.PrecisionValue, flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=15) + self.PropertySizer.AddWindow(self.PrecisionSpin, flag=wx.GROW) + self.PropertySizer.AddWindow(wx.StaticText(self, wx.ID_ANY, _("Other:")), flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=15) + self.PropertySizer.AddWindow(self.OtherText, flag=wx.GROW) + self.PropertySizer.AddWindow(self.InitialValue, flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=15) + self.PropertySizer.AddWindow(self.InitialText, flag=wx.GROW) + self.PropertySizer.AddWindow(wx.StaticText(self, wx.ID_ANY, _("Description:")), flag=wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border=15) + self.PropertySizer.AddWindow(self.DescriptionText, flag=wx.GROW) + self.PropertySizer.AddGrowableCol(1, 1) + self.MainSizer.AddSizer(self.PropertySizer, flag=wx.GROW | wx.UP | wx.RIGHT, border=15) + self.ButtonSizer.AddWindow(self.ClearButton) + self.MainSizer.AddSizer(self.ButtonSizer, + flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = 10) + self.SetSizer(self.MainSizer) + def _init_ctrls(self, prnt, opt): + wx.Dialog.__init__(self, id=ID_OPTIONSWIZARDDIALOG, + name='OptionsWizard', parent=prnt, + size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE, + self.OptionsTypeChoice = wx.Choice(parent=self, id=ID_OPTIONSWIZARDDIALOG, + self.Bind(wx.EVT_CHOICE, self.OnTypeChoice, self.OptionsTypeChoice) + self.OnChangeCheckbox = wx.CheckBox(parent=self, id=ID_ONCHANGE) + self.SubgroupText = wx.TextCtrl(parent=self, id=ID_SUBGROUPTEXT) + self.UnitText = wx.TextCtrl(parent=self, id=ID_UNITTEXT) + self.ValueCheckbox = wx.CheckBox(parent=self, id=ID_VALUECHECKBOX) + self.MinSpin = wx.SpinCtrl(parent=self, id=ID_MINSPIN, style=wx.SP_VERTICAL) + self.MaxSpin = wx.SpinCtrl(parent=self, id=ID_MAXSPIN, style=wx.SP_VERTICAL) + self.PrecisionSpin = wx.SpinCtrl(parent=self, id=ID_PRECISIONSPIN, style=wx.SP_VERTICAL) + self.InitialText = wx.TextCtrl(parent=self, id=ID_INITIALSPIN) + self.MinSpin.SetRange(-1000000, 1000000) + self.MaxSpin.SetRange(-1000000, 1000000) + self.ScadaCheckbox = wx.CheckBox(parent=self, id=ID_SCADACHECKBOX) + self.StaticCheckbox = wx.CheckBox(parent=self, id=ID_STATIC) + self.OtherText = wx.TextCtrl(parent=self, id=ID_OTHERTEXT) + self.DescriptionText = wx.TextCtrl(parent=self, id=ID_DESCRIPTION, size=(-1, 100), style=wx.TE_MULTILINE | wx.SUNKEN_BORDER) + self.ClearButton = wx.Button(self, wx.ID_CLEAR, _("Clear")) + self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL) + self.ValueCheckbox.Bind(wx.EVT_CHECKBOX, self.EnableValue) + self.OnChangeCheckbox.Enable(False) + self.OtherText.Enable(False) + self.UnitText.Enable(False) + self.ScadaCheckbox.Enable(False) + self.SubgroupText.Enable(False) + self.ValueCheckbox.Enable(False) + self.MinSpin.Enable(False) + self.MaxSpin.Enable(False) + self.PrecisionSpin.Enable(False) + self.InitialText.Enable(False) + self.DescriptionText.Enable(False) + self.StaticCheckbox.Enable(False) + self.Bind(wx.EVT_CHOICE, self.Enabler, self.OptionsTypeChoice) + self.Bind(wx.EVT_BUTTON, self.clearOptions, self.ClearButton) + self.Bind(wx.EVT_CHECKBOX, self.Enabler, self.ScadaCheckbox) + def __init__(self, parent, opt, desc): + self._init_ctrls(parent, opt) + self.SetOptions(opt, desc) + def Enabler(self, event): + if self.OptionsTypeChoice.GetSelection() == 0: + self.clearOptions(event) + elif self.OptionsTypeChoice.GetSelection() in [1,3]: + self.ScadaCheckbox.Enable(True) + self.OtherText.Enable(True) + self.SubgroupText.Enable(True) + self.UnitText.Enable(True) + self.OnChangeCheckbox.Enable(True) + self.ValueCheckbox.Enable(True) + self.PrecisionSpin.Enable(True) + self.InitialText.Enable(True) + self.DescriptionText.Enable(True) + self.ScadaCheckbox.Enable(True) + self.OtherText.Enable(True) + self.SubgroupText.Enable(True) + self.UnitText.Enable(True) + self.OnChangeCheckbox.SetValue(False) + self.OnChangeCheckbox.Enable(False) + self.ValueCheckbox.Enable(True) + self.PrecisionSpin.Enable(True) + self.InitialText.Enable(True) + self.DescriptionText.Enable(True) + if self.OptionsTypeChoice.GetSelection() == 3 and self.ScadaCheckbox.GetValue(): + self.StaticCheckbox.Enable(True) + self.OnChangeCheckbox.SetValue(True) + self.StaticCheckbox.SetValue(False) + self.StaticCheckbox.Enable(False) + def clearOptions(self, event): + self.OptionsTypeChoice.SetSelection(0) + self.SubgroupText.SetValue("") + self.UnitText.SetValue("") + self.MinSpin.SetValue(0) + self.MaxSpin.SetValue(0) + self.ValueCheckbox.SetValue(False) + self.ScadaCheckbox.SetValue(False) + self.StaticCheckbox.SetValue(False) + self.OtherText.SetValue("") + self.MinSpin.Enable(False) + self.MaxSpin.Enable(False) + self.StaticCheckbox.Enable(False) + self.PrecisionSpin.SetValue(0) + self.InitialText.SetValue("") + self.OnChangeCheckbox.SetValue(False) + self.DescriptionText.SetValue("") + self.OnChangeCheckbox.Enable(False) + self.OtherText.Enable(False) + self.SubgroupText.Enable(False) + self.UnitText.Enable(False) + self.ScadaCheckbox.Enable(False) + self.ValueCheckbox.Enable(False) + self.MinSpin.Enable(False) + self.MaxSpin.Enable(False) + self.PrecisionSpin.Enable(False) + self.InitialText.Enable(False) + self.DescriptionText.Enable(False) + self.StaticCheckbox.Enable(False) + def OnTypeChoice(self, event): + self.selected = event.GetSelection() + def EnableValue(self, event): + self.MinSpin.Enable(self.ValueCheckbox.GetValue()) + self.MaxSpin.Enable(self.ValueCheckbox.GetValue()) + def SetOptions(self, opt, desc): + optionsTemp = opt1.split(" ") + options.append(el.split("=")) + self.OptionsTypeChoice.SetSelection(0) + elif el[0] == "Static": + self.OptionsTypeChoice.SetSelection(1) + elif el[0] == "Session": + self.OptionsTypeChoice.SetSelection(2) + self.OptionsTypeChoice.SetSelection(3) + self.ScadaCheckbox.SetValue(True) + self.StaticCheckbox.Enable(True) + self.StaticCheckbox.SetValue(True) + if el[0] == "subgroup": + self.SubgroupText.SetValue(el[1]) + self.UnitText.SetValue(el[1]) + self.ValueCheckbox.SetValue(True) + self.MinSpin.SetValue(int(el[1])) + self.MinSpin.Enable(True) + self.ValueCheckbox.SetValue(True) + self.MaxSpin.SetValue(int(el[1])) + self.MaxSpin.Enable(True) + self.OtherText.SetValue(el[1]) + elif el[0] == "precision": + self.PrecisionSpin.SetValue(int(el[1])) + self.OnChangeCheckbox.Enable(True) + self.OnChangeCheckbox.SetValue(True) + if self.OptionsTypeChoice.GetSelection() == 3 and self.ScadaCheckbox.GetValue(): + self.StaticCheckbox.Enable(True) + self.InitialText.SetValue(opt3) + self.DescriptionText.SetValue(desc) + self.TypeSelected = self.OptionsTypeChoice.GetSelection() + if self.TypeSelected<0: + options = VARIABLETYPE[self.TypeSelected] + if self.ScadaCheckbox.GetValue(): + if self.StaticCheckbox.GetValue(): + if self.SubgroupText.GetLineText(0) != "": + options += " subgroup=" + self.SubgroupText.GetLineText(0) + if self.UnitText.GetLineText(0) != "": + options += " unit=" + self.UnitText.GetLineText(0) + if self.MinSpin.IsEnabled(): + options += " min=" + str(self.MinSpin.GetValue()) + options += " max=" + str(self.MaxSpin.GetValue()) + if self.PrecisionSpin.GetValue() != 0: + options += " precision=" + str(self.PrecisionSpin.GetValue()) + if self.OtherText.GetLineText(0) != "": + options += " other=" + self.OtherText.GetLineText(0) + if self.OnChangeCheckbox.GetValue(): + if VARIABLETYPE[self.TypeSelected] == "Alarm": + elif VARIABLETYPE[self.TypeSelected] == "Static": + self.value = "StoredValue" + self.Description = self.DescriptionText.GetValue() + self.Initial = self.InitialText.GetValue() + return options, self.OnChange,self.value, self.Description, self.Initial +class WampOptionsCellControl(wx.PyControl): + Custom cell editor control with a text box and a button that launches + def __init__(self, parent, table, row): + wx.Control.__init__(self, parent, row) + main_sizer = wx.FlexGridSizer(cols=2, hgap=0, rows=1, vgap=0) + main_sizer.AddGrowableCol(0) + main_sizer.AddGrowableRow(0) + # create location text control + self.Options = wx.TextCtrl(self, size=wx.Size(0, -1), + style=wx.TE_PROCESS_ENTER) + self.Options.Bind(wx.EVT_KEY_DOWN, self.OnDurationChar) + main_sizer.AddWindow(self.Options, flag=wx.GROW) + self.EditButton = wx.Button(self, label='...', size=wx.Size(30, -1)) + self.Bind(wx.EVT_BUTTON, self.OnEditButtonClick, self.EditButton) + main_sizer.AddWindow(self.EditButton, flag=wx.GROW) + self.Bind(wx.EVT_SIZE, self.OnSize) + self.SetSizer(main_sizer) + def OnDurationChar(self, event): + keycode = event.GetKeyCode() + if keycode in [wx.WXK_RETURN, wx.WXK_TAB]: + self.Parent.Parent.ProcessEvent(event) + elif keycode == wx.WXK_ESCAPE: + self.Duration.SetValue(self.Default) + self.Parent.Parent.CloseEditControl() + def SetValue(self, value): + self.Options.SetValue(value) + return self.Options.GetValue() + def OnSize(self, event): + def OnEditButtonClick(self, event): + # pop up the Duration Editor dialog + options = [self.GetValue(), self.table.GetValueByName(self.row, _("OnChange")), self.table.GetValueByName(self.row, "Initial")] + desc = self.table.GetValueByName(self.row, _("Description")) + dialog = WampOptionsEditor(self.parent, options, desc) + answer = dialog.ShowModal() + opt, OnChange, value, description, initial = dialog.GetOptions() + self.table.SetValueByName(self.row, _("OnChange"), value) + self.table.SetValueByName(self.row, _("OnChange"), "") + self.table.SetValueByName(self.row, _("Description"), description) + self.table.SetValueByName(self.row, _("Initial"), str(initial)) + self.Options.SetFocus() + def OnChar(self, event): + keycode = event.GetKeyCode() + if keycode in [wx.WXK_RETURN]: + self.Parent.Parent.ProcessEvent(event) + elif keycode == wx.WXK_ESCAPE: + self.Options.SetValue(self.Default) + self.Parent.Parent.CloseEditControl() + self.Options.SetFocus() +class WampOptionsCellEditor(wx.grid.PyGridCellEditor): + Grid cell editor that uses DurationCellControl to display an edit button. + def __init__(self, table, row, col): + wx.grid.PyGridCellEditor.__init__(self) + self.colname = self.table.GetColLabelValue(col, False) + self.CellControl = None + def Create(self, parent, id, evt_handler): + self.CellControl = WampOptionsCellControl(parent, self.table, self.row) + self.SetControl(self.CellControl) + self.CellControl.PushEventHandler(evt_handler) + def BeginEdit(self, row, col, grid): + self.CellControl.Enable() + self.CellControl.SetValue(self.table.GetValueByName(self.row, self.colname)) + self.CellControl.SetFocus() + def EndEditInternal(self, row, col, grid, old_duration): + duration = self.CellControl.GetValue() + changed = duration != old_duration + self.table.SetValueByName(row, self.colname, duration) + self.CellControl.Disable() + if wx.VERSION >= (3, 0, 0): + def EndEdit(self, row, col, grid, oldval): + return self.EndEditInternal(row, col, grid, oldval) + def EndEdit(self, row, col, grid): + oldval = self.table.GetValueByName(row, self.colname) + return self.EndEditInternal(row, col, grid, oldval) + def SetSize(self, rect): + self.CellControl.SetDimensions(rect.x + 1, rect.y, + rect.width, rect.height, + wx.SIZE_ALLOW_MINUS_ONE) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/WxGladeEditor.py Tue Dec 18 14:43:49 2018 +0100
@@ -0,0 +1,10 @@
+from __future__ import absolute_import +from editors.CodeFileEditor import CodeFileEditor +from py_ext.PythonEditor import PythonCodeEditor +class WxGladeEditor(CodeFileEditor): + CONFNODEEDITOR_TABS = [ + (_("Python code"), "_create_CodePanel")] + CODE_EDITOR = PythonCodeEditor \ No newline at end of file