Package com.infiniteautomation.serial.vo

Examples of com.infiniteautomation.serial.vo.SerialDataSourceVO


     @DwrPermission(user = true)
      public ProcessResult saveSerialDataSource(BasicDataSourceVO basic, String commPortId, int baudRate, int flowControlIn,
              int flowControlOut, int dataBits, int stopBits, int parity, int readTimeout, boolean useTerminator,
              String messageTerminator, String messageRegex, int pointIdentifierIndex) {
          SerialDataSourceVO ds = (SerialDataSourceVO) Common.getUser().getEditDataSource();

          setBasicProps(ds, basic);
          ds.setCommPortId(commPortId);
          ds.setBaudRate(baudRate);
          ds.setFlowControlIn(flowControlIn);
          ds.setFlowControlOut(flowControlOut);
          ds.setDataBits(dataBits);
          ds.setStopBits(stopBits);
          ds.setParity(parity);
          ds.setReadTimeout(readTimeout);
          ds.setUseTerminator(useTerminator);
          ds.setMessageTerminator(StringEscapeUtils.unescapeJava(messageTerminator));
          ds.setMessageRegex(messageRegex);
          ds.setPointIdentifierIndex(pointIdentifierIndex);
         
          return tryDataSourceSave(ds);
     
View Full Code Here


          return validatePoint(id, xid, name, locator, null);
      }
     
      @DwrPermission(user = true)
      public String getSafeTerminator() {
        SerialDataSourceVO ds = (SerialDataSourceVO) Common.getUser().getEditDataSource();
        return StringEscapeUtils.escapeJava(ds.getMessageTerminator());
      }
View Full Code Here

     
      @DwrPermission(user = true)
      public ProcessResult testString(String raw) {
        ProcessResult pr = new ProcessResult();
        String msg = StringEscapeUtils.unescapeJava(raw);
        SerialDataSourceVO ds = (SerialDataSourceVO) Common.getUser().getEditDataSource();
        if(ds.getId() == -1) {
          pr.addContextualMessage("testString", "serial.test.needsSave");
          return pr;
        }
        DataPointDao dpd = new DataPointDao();
        List<DataPointVO> points = dpd.getDataPoints(ds.getId(), null);
        if(ds.getUseTerminator()) {
          if(msg.indexOf(ds.getMessageTerminator()) != -1) {
            msg = msg.substring(0, msg.indexOf(ds.getMessageTerminator())+1);
            Pattern p = Pattern.compile(ds.getMessageRegex());
            Matcher m = p.matcher(msg);
            if(!m.matches()) {
              pr.addContextualMessage("testString", "serial.test.noMessageMatch");
              return pr;
            }
            String identifier = m.group(ds.getPointIdentifierIndex());
            for(DataPointVO pnt : points) {
              SerialPointLocatorVO plVo = (SerialPointLocatorVO) pnt.getPointLocator();
              if(identifier.equals(plVo.getPointIdentifier())) {
                Pattern v = Pattern.compile(plVo.getValueRegex());
                Matcher vm = v.matcher(msg);
View Full Code Here

    return "dsEdit.serial.desc";
  }

  @Override
  protected DataSourceVO<?> createDataSourceVO() {
    return new SerialDataSourceVO();
  }
View Full Code Here

 
 
  public SerialDataSourceRT(SerialDataSourceVO vo) {
    super(vo);
    buffer = new ByteQueue(1024);
    SerialDataSourceVO properties = (SerialDataSourceVO)this.getVo();
    terminator = properties.getMessageTerminator().getBytes();
  }
View Full Code Here

   * Connect to a serial port
   * @param portName
   * @throws Exception
   */
  public boolean connect () throws Exception{
    SerialDataSourceVO vo = (SerialDataSourceVO) this.getVo();
   
    SerialParameters params = new SerialParameters();
    params.setCommPortId(vo.getCommPortId());
        params.setPortOwnerName("Mango Serial Data Source");
        params.setBaudRate(vo.getBaudRate());
        params.setFlowControlIn(vo.getFlowControlIn());
        params.setFlowControlOut(vo.getFlowControlOut());
        params.setDataBits(vo.getDataBits());
        params.setStopBits(vo.getStopBits());
        params.setParity(vo.getParity());
        params.setRecieveTimeout(vo.getReadTimeout());
   
        if ( SerialUtils.portOwned(vo.getCommPortId()) ){
      raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.serial.portInUse",vo.getCommPortId()));
      return false;
        }else{
          try{
                this.port = SerialUtils.openSerialPort(params);
                this.port.addEventListener(this);
                return true;
             
            }catch(Exception e){
          raiseEvent(DATA_SOURCE_EXCEPTION_EVENT, System.currentTimeMillis(), true, new TranslatableMessage("event.serial.portError",vo.getCommPortId(),e.getLocalizedMessage()));
          return false;
            }
        }

    }
View Full Code Here

        return;
      }
      //We recieved some data, now parse it.
      try{
        InputStream in = this.port.getInputStream();
        SerialDataSourceVO vo = ((SerialDataSourceVO)this.getVo());
              int data;
              while (( data = in.read()) > -1 ){
                index += 1;
                  buffer.push(data);
                  if (vo.getUseTerminator()) {
                    if(isTerminatorFound())
                      break;
                  }
              }
              if(!vo.getUseTerminator()) {
                  String msg = new String(buffer.peekAll());
                  searchRegex(msg, 0);
              }
              if(!isTerminatorFound())
                return;
             
              String msg = buffer.popString(index, Charset.forName("ASCII"));
              index = 0;
             
              if(!this.dataPoints.isEmpty()){
                 
                  //DS Information
                  String messageRegex = vo.getMessageRegex(); //"!([A-Z0-9]{3,3})([a-zA-Z])(.*);";
                  int pointIdentifierIndex = vo.getPointIdentifierIndex();
                 
                Pattern messagePattern = Pattern.compile(messageRegex);
                Matcher messageMatcher = messagePattern.matcher(msg);
                  if(messageMatcher.matches()){
                   
                      //Parse out the Identifier
                    String pointIdentifier = messageMatcher.group(pointIdentifierIndex);
                   
                    //Update all points that have this Identifier
                    for(DataPointRT dp: this.dataPoints){
                      SerialPointLocatorRT pl = dp.getPointLocator();
                      SerialPointLocatorVO plVo = pl.getVo();
                      if(plVo.getPointIdentifier().equals(pointIdentifier)){
                        Pattern pointValuePattern = Pattern.compile(plVo.getValueRegex());
                        Matcher pointValueMatcher = pointValuePattern.matcher(msg); //Use the index from the above message
                            if(pointValueMatcher.matches()){
                              String value = pointValueMatcher.group(plVo.getValueIndex());                 
                              PointValueTime newValue = new PointValueTime(DataValue.stringToValue(value, plVo.getDataTypeId()),
                                  Common.timer.currentTimeMillis());
                            dp.updatePointValue(newValue);
                            }//end if value matches
                      }//end for this point id
                    }
                   
                   
                  }else{
                    raiseEvent(POINT_READ_PATTERN_MISMATCH_EVENT,System.currentTimeMillis(),true,new TranslatableMessage("event.serial.patternMismatch",vo.getMessageRegex(),msg));
                  }
                 
              }
              returnToNormal(POINT_READ_EXCEPTION_EVENT, System.currentTimeMillis());
          }catch ( IOException e ){
View Full Code Here

TOP

Related Classes of com.infiniteautomation.serial.vo.SerialDataSourceVO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.