• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Error exporting new datasource

    Development general discussion
    2
    17
    7.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      apl
      last edited by

      
      package com.serotonin.mango.vo.dataSource.openv4j;
      
      import com.serotonin.json.JsonException;
      import com.serotonin.json.JsonObject;
      import com.serotonin.json.JsonReader;
      import com.serotonin.json.JsonRemoteProperty;
      import com.serotonin.mango.Common;
      import com.serotonin.mango.rt.dataSource.DataSourceRT;
      import com.serotonin.mango.rt.dataSource.openv4j.OpenVDataSourceRT;
      import com.serotonin.mango.rt.event.type.AuditEventType;
      import com.serotonin.mango.util.ExportCodes;
      import com.serotonin.mango.vo.dataSource.DataSourceVO;
      import com.serotonin.mango.vo.dataSource.PointLocatorVO;
      import com.serotonin.mango.vo.event.EventTypeVO;
      import com.serotonin.util.SerializationHelper;
      import com.serotonin.util.StringUtils;
      import com.serotonin.web.dwr.DwrResponseI18n;
      import com.serotonin.web.i18n.LocalizableMessage;
      import java.io.IOException;
      import java.io.ObjectInputStream;
      import java.io.ObjectOutputStream;
      import java.util.List;
      import java.util.Map;
      import net.sf.openv4j.Devices;
      import net.sf.openv4j.Protocols;
      import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;
      
      public class OpenVDataSourceVO extends DataSourceVO<OpenVDataSourceVO> {
          private final static Log LOG = LogFactory.getLog(OpenVDataSourceVO.class);
      
          private static final ExportCodes EVENT_CODES = new ExportCodes();
      
          static {
              EVENT_CODES.addElement(OpenVDataSourceRT.DATA_SOURCE_EXCEPTION_EVENT, "DATA_SOURCE_EXCEPTION");
              EVENT_CODES.addElement(OpenVDataSourceRT.POINT_READ_EXCEPTION_EVENT, "POINT_READ_EXCEPTION");
              EVENT_CODES.addElement(OpenVDataSourceRT.POINT_WRITE_EXCEPTION_EVENT, "POINT_WRITE_EXCEPTION");
          }
          @JsonRemoteProperty
          private String commPortId;
          private int updatePeriodType = Common.TimePeriods.MINUTES;
          @JsonRemoteProperty
          private int updatePeriods = 1;
          @JsonRemoteProperty
          private Devices device;
          @JsonRemoteProperty
          private Protocols protocol;
      
          @Override
          public Type getType() {
              return Type.OPEN_V_4_J;
          }
      
          @Override
          protected void addEventTypes(List<EventTypeVO> eventTypes) {
              eventTypes.add(createEventType(OpenVDataSourceRT.DATA_SOURCE_EXCEPTION_EVENT, new LocalizableMessage("event.ds.dataSource")));
              eventTypes.add(createEventType(OpenVDataSourceRT.POINT_READ_EXCEPTION_EVENT, new LocalizableMessage("event.ds.pointRead")));
              eventTypes.add(createEventType(OpenVDataSourceRT.POINT_WRITE_EXCEPTION_EVENT, new LocalizableMessage("event.ds.pointWrite")));
          }
      
          @Override
          public LocalizableMessage getConnectionDescription() {
              return new LocalizableMessage("common.default", commPortId);
          }
      
          @Override
          public PointLocatorVO createPointLocator() {
              return new OpenVPointLocatorVO();
          }
      
          @Override
          public DataSourceRT createDataSourceRT() {
              return new OpenVDataSourceRT(this);
          }
      
          @Override
          public ExportCodes getEventCodes() {
              return EVENT_CODES;
          }
      
          @Override
          protected void addPropertiesImpl(List<LocalizableMessage> list) {
              AuditEventType.addPropertyMessage(list, "dsEdit.openv4j.port", commPortId);
              AuditEventType.addPeriodMessage(list, "dsEdit.updatePeriod", updatePeriodType, updatePeriods);
          }
      
          @Override
          protected void addPropertyChangesImpl(List<LocalizableMessage> list, OpenVDataSourceVO from) {
              AuditEventType.maybeAddPropertyChangeMessage(list, "dsEdit.openv4j.port", from.commPortId, commPortId);
              AuditEventType.maybeAddPeriodChangeMessage(list, "dsEdit.updatePeriod", from.updatePeriodType,
                      from.updatePeriods, updatePeriodType, updatePeriods);
          }
      
          public String getCommPortId() {
              return commPortId;
          }
      
          public void setCommPortId(String commPortId) {
              this.commPortId = commPortId;
          }
      
          public int getUpdatePeriodType() {
              return updatePeriodType;
          }
      
          public void setUpdatePeriodType(int updatePeriodType) {
              this.updatePeriodType = updatePeriodType;
          }
      
          public int getUpdatePeriods() {
              return updatePeriods;
          }
      
          public void setUpdatePeriods(int updatePeriods) {
              this.updatePeriods = updatePeriods;
          }
      
          @Override
          public void validate(DwrResponseI18n response) {
              super.validate(response);
      
              if (StringUtils.isEmpty(commPortId)) {
                  response.addContextualMessage("commPortId", "validate.required");
              }
              if (!Common.TIME_PERIOD_CODES.isValidId(updatePeriodType)) {
                  response.addContextualMessage("updatePeriodType", "validate.invalidValue");
              }
              if (updatePeriods <= 0) {
                  response.addContextualMessage("updatePeriods", "validate.greaterThanZero");
              }
          }
      
      
      
      
          //
          ///
          /// Serialization
          ///
          //
          private static final long serialVersionUID = -1;
          private static final int version = 2;
      
          // Serialization for saveDataSource
          private void writeObject(ObjectOutputStream out) throws IOException {
              out.writeInt(version);
              out.writeInt(updatePeriodType);
              out.writeInt(updatePeriods);
                      SerializationHelper.writeSafeUTF(out, commPortId);
                      SerializationHelper.writeSafeUTF(out, device.name());
                      SerializationHelper.writeSafeUTF(out, protocol.name());
          }
      
          private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
              int ver = in.readInt();
      
              // Switch on the version of the class so that version changes can be elegantly handled.
              switch (ver) {
                  case 2:
                      updatePeriodType = in.readInt();
                      updatePeriods = in.readInt();
                                              commPortId = SerializationHelper.readSafeUTF(in);
                              device = Devices.valueOf(SerializationHelper.readSafeUTF(in));
                              protocol = Protocols.valueOf(SerializationHelper.readSafeUTF(in));
      
                      break;
              }
          }
      
          @Override
          public void jsonDeserialize(JsonReader reader, JsonObject json) throws JsonException {
              LOG.info("WRITE TO JSON");
              super.jsonDeserialize(reader, json);
              LOG.info("SUPER TO JSON");
              Integer value = deserializeUpdatePeriodType(json);
              if (value != null)
                  updatePeriodType = value;
              LOG.info("JSON OK");
          }
      
          @Override
          public void jsonSerialize(Map<String, Object> map) {
              super.jsonSerialize(map);
               serializeUpdatePeriodType(map, updatePeriodType);
         }
      
          /**
           * @return the device
           */
          public Devices getDevice() {
              return device;
          }
      
          /**
           * @param device the device to set
           */
          public void setDevice(Devices device) {
              this.device = device;
          }
      
          /**
           * @return the device
           */
          public Devices[] getDevices() {
              return Devices.values();
          }
      
          /**
           * @return the protocol
           */
          public Protocols getProtocol() {
              return protocol;
          }
      
          /**
           * @param protocol the protocol to set
           */
          public void setProtocol(Protocols protocol) {
              this.protocol = protocol;
          }
      
           /**
           * @return the protocols
           */
          public Protocols[] getProtocols() {
              return Protocols.values();
          }
      
      }
      
      
      1 Reply Last reply Reply Quote 0
      • M
        mlohbihler
        last edited by

        Annotate your class with "@JsonRemoteEntity". The JSON serializer is picking up the s/getAlarmLevel from the super class.

        Best regards,
        Matthew

        1 Reply Last reply Reply Quote 0
        • A
          apl
          last edited by

          Thanks,

          it works. (I will have to look better doing past and copy next time:-))

          Arne

          1 Reply Last reply Reply Quote 0
          • M
            mlohbihler
            last edited by

            Are your data sources completed/tested? You did mbus and openv?

            Best regards,
            Matthew

            1 Reply Last reply Reply Quote 0
            • A
              apl
              last edited by

              No consider both as highly experimental...

              Currently I work on openv read maybe write access.

              If this is done I have to update the m-bus sources at mbus4j.sf.net to the latest specification (IEC).

              Once this is done I plan to support primary adressing with no change of the data frame.
              Later support for

              • secondary addressing.
              • rewrite JSP to make it more compact
              • ability of changing frames.
              • atmodem support (atmodem4j.sf.net).

              My problem is currently that I have no direct access to m-bus hardware so this is mostly tested against dummys or mbus data from different readouts.

              If anyone has access to hardware it will speedup development.

              Arne

              1 Reply Last reply Reply Quote 0
              • M
                mlohbihler
                last edited by

                If anyone has access to hardware it will speedup development.

                Isn't that always the problem! I might as well make a shout out now for OPC XML-DA hardware. If anyone has any that they can make internet accessible for the purposes of data source testing, please let me know. I know there are some sample servers on the internet, but those i've found so far contain a single unchanging point. Not very useful...

                Best regards,
                Matthew

                1 Reply Last reply Reply Quote 0
                • A
                  apl
                  last edited by

                  Maybe try using WinCC from SIEMENS that has XML-OPC capabilities - I never tested it...

                  I think you can grap a demo version vom your local dealer.

                  Or could you send me the code for initial testing?

                  Arne

                  1 Reply Last reply Reply Quote 0
                  • M
                    mlohbihler
                    last edited by

                    I haven't written any code yet. There was no point in starting without decent equipment to work against. You have some OPC XML-DA stuff? Any chance i could hit it up for a bit? Could you open just to a particular IP address?

                    Best regards,
                    Matthew

                    1 Reply Last reply Reply Quote 0
                    • A
                      apl
                      last edited by

                      What about OPC UA (xml and binary protocol) I dont know the licence restrictions for any?

                      And for software see www.opcfoundation.org, there seem many servers and clients for demo available???

                      Arne

                      1 Reply Last reply Reply Quote 0
                      • M
                        mlohbihler
                        last edited by

                        And for software see www.opcfoundation.org, there seem many servers and clients for demo available???

                        That would be what i was referring to:

                        I know there are some sample servers on the internet, but those i've found so far contain a single unchanging point. Not very useful...

                        Best regards,
                        Matthew

                        1 Reply Last reply Reply Quote 0
                        • A
                          apl
                          last edited by

                          What exact is your plan OPS server, client or both.

                          I looked at the Java6 implementation of the Web service or axis2 or....

                          if mango should act as a server we need a client first - I can test it against WinCC.
                          after that the server should be easily implemented.

                          Arne

                          1 Reply Last reply Reply Quote 0
                          • M
                            mlohbihler
                            last edited by

                            Mango is primarily intended to act as a server.

                            Best regards,
                            Matthew

                            1 Reply Last reply Reply Quote 0
                            • A
                              apl
                              last edited by

                              So maybe implement at first the client into mango ;-) (one can use the get function to retrieve data from other (OPC-servers - which in turn could be simple devices...)
                              to have a testet client - and then do the server stuff.

                              what do you plan to use JAX-WS or Axis2?

                              Arne

                              1 Reply Last reply Reply Quote 0
                              • M
                                mlohbihler
                                last edited by

                                I use axis because i know it better, and it has ANT support (which i couldn't find in less than 5 minutes for JAX). But if someone else is doing the work it doesn't matter to me.

                                Best regards,
                                Matthew

                                1 Reply Last reply Reply Quote 0
                                • First post
                                  Last post