Package modbuspal.slave

Examples of modbuspal.slave.ModbusSlave


        {
            Node slaveNode = slavesList.item(i);
            //NamedNodeMap attributes = slaveNode.getAttributes();
            //ModbusSlave slave = new ModbusSlave( attributes );
            //slave.load( slaveNode );
            ModbusSlave slave = new ModbusSlave( this, slaveNode );
            addModbusSlave( slave );
        }
    }
View Full Code Here


        {
            return null;
        }
        else
        {
            ModbusSlave retval[] = new ModbusSlave[0];
            retval = found.toArray(retval);
            return retval;
        }
    }
View Full Code Here

     * Removes the specified MODBUS  slave from the project.
     * @param slaveID the slave number of the MODBUS slave to remove
     */
    public void removeModbusSlave(ModbusSlaveAddress slaveID)
    {
        ModbusSlave slave = getModbusSlave(slaveID);
        if( slave!=null )
        {
            slave.clear();
        }
        // disconnect slave from list
        setModbusSlave(slaveID, null);
    }
View Full Code Here

     * @param idDst the slave number of the copy
     * @param name the name to give to the copy
     */
    public void duplicateModbusSlave(ModbusSlaveAddress idSrc, ModbusSlaveAddress idDst, String name)
    {
        ModbusSlave newSlave = new ModbusSlave(idDst);
        newSlave.setName(name);

        try
        {
            // Create a temporary file in order to exportSlave the model
            File tempFile = File.createTempFile("modbuspal", null);
View Full Code Here

     * @param b if true, enables the MODBUS slave. if false, disables the
     * MODBUS slave.
     */
    public void setSlaveEnabled(ModbusSlaveAddress slaveID, boolean b)
    {
        ModbusSlave ms = getModbusSlave(slaveID, learnModeEnabled);
        if( ms!=null )
        {
            ms.setEnabled(b);
        }
    }
View Full Code Here

        /*if( (slaveID<0) || (slaveID>=ModbusConst.MAX_MODBUS_SLAVE) )
        {
            return false;
        }*/

        ModbusSlave ms = getModbusSlave(slaveID,learnModeEnabled);
        if( ms!=null )
        {
            return ms.isEnabled();
        }
        return false;
    }
View Full Code Here

     * @throws IOException
     */
    public void exportSlave(File exportFile, ModbusSlaveAddress modbusID, boolean withBindings, boolean withAutomations)
    throws FileNotFoundException, IOException
    {
        ModbusSlave exportedSlave = getModbusSlave(modbusID);
       
        OutputStream out = new FileOutputStream(exportFile);

        String xmlTag = "<?xml version=\"1.0\"?>\r\n";
        out.write( xmlTag.getBytes() );

        String docTag = "<!DOCTYPE modbuspal_slave SYSTEM \"modbuspal.dtd\">\r\n";
        out.write( docTag.getBytes() );

        String openTag = "<modbuspal_slave>\r\n";
        out.write( openTag.getBytes() );

        // if needed, first exportSlave automations (they need to be imported first!)
        if( withAutomations == true )
        {
            String names[] = exportedSlave.getRequiredAutomations();
            for(int i=0; i<names.length; i++)
            {
                Automation automation = getAutomation( names[i] );
                automation.save(out);
            }
        }
        exportedSlave.save(out,withBindings);

        String closeTag = "</modbuspal_slave>\r\n";
        out.write( closeTag.getBytes() );
        out.close();
    }
View Full Code Here

     * @throws IllegalAccessException
     */
    public void importSlave(Document doc, ModbusSlaveAddress idDst, boolean withBindings, boolean withAutomations)
    throws ParserConfigurationException, SAXException, IOException, InstantiationException, IllegalAccessException
    {
        ModbusSlave target = getModbusSlave(idDst,true);
        importSlave(doc, target, withBindings, withAutomations);
    }
View Full Code Here

     * @return the ModbusPduProcessor, or null if none is assigned for the
     * specified MODBUS slave and function code.
     */
    public ModbusPduProcessor getSlavePduProcessor(ModbusSlaveAddress slaveID, byte functionCode)
    {
        ModbusSlave ms = getModbusSlave(slaveID, learnModeEnabled);
        if( ms != null )
        {
            return ms.getPduProcessor(functionCode);
        }

        return null;
    }
View Full Code Here

            modbusPalProject.notifyPDUnotServiced();
            return 0;
        }

        // get the slave:
        ModbusSlave slave = modbusPalProject.getModbusSlave(slaveID);

        // process the "no reply" error rate of the slave:
        if( Math.random() < slave.getNoReplyErrorRate() )
        {
            System.err.println("Slave "+slaveID+" will no reply (check value error rate)" );
            modbusPalProject.notifyPDUnotServiced();
            return 0;
        }

        byte functionCode = buffer[offset+0];
        ModbusPduProcessor mspp = slave.getPduProcessor(functionCode);
        if( mspp == null )
        {
            System.err.println("Unsupported function code "+functionCode);
            int length = makeExceptionResponse(functionCode,XC_ILLEGAL_FUNCTION, buffer, offset);
            ModbusPalRecorder.recordOutgoing(slaveID,buffer,offset,length);
            modbusPalProject.notifyExceptionResponse();
            return length;
        }

        int length = mspp.processPDU(functionCode, slaveID, buffer, offset, modbusPalProject.isLeanModeEnabled());
        if(length<0)
        {
            System.err.println("Illegal function code "+functionCode);
            length = makeExceptionResponse(functionCode,XC_ILLEGAL_FUNCTION, buffer, offset);
        }

        if( isExceptionResponse(buffer,offset)==true )
        {
            modbusPalProject.notifyExceptionResponse();
        }
        else
        {
            modbusPalProject.notifyPDUprocessed();
        }

        // delay the reply
        try {
            Thread.sleep(slave.getReplyDelay());
        } catch (InterruptedException ex) {
            Logger.getLogger(ModbusSlaveProcessor.class.getName()).log(Level.SEVERE, null, ex);
        }

        ModbusPalRecorder.recordOutgoing(slaveID,buffer,offset,length);
View Full Code Here

TOP

Related Classes of modbuspal.slave.ModbusSlave

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.