当前位置: 首页>>代码示例>>Java>>正文


Java IoBuffer.putUnsignedShort方法代码示例

本文整理汇总了Java中org.apache.mina.core.buffer.IoBuffer.putUnsignedShort方法的典型用法代码示例。如果您正苦于以下问题:Java IoBuffer.putUnsignedShort方法的具体用法?Java IoBuffer.putUnsignedShort怎么用?Java IoBuffer.putUnsignedShort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mina.core.buffer.IoBuffer的用法示例。


在下文中一共展示了IoBuffer.putUnsignedShort方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertData

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
/**
 * Encode the data from Java byte order to requested modbus byte order
 *
 * @param data
 *            the data to encode
 * @param dataOrder
 *            the target modbus byte order
 * @return the converted data, or the input data if no conversion was
 *         necessary
 */
public static IoBuffer convertData ( final IoBuffer data, final ByteOrder dataOrder )
{
    if ( dataOrder == ByteOrder.BIG_ENDIAN )
    {
        return data;
    }

    final IoBuffer result = IoBuffer.allocate ( data.capacity () );
    result.order ( dataOrder );

    for ( int i = 0; i < data.remaining () / 2; i++ )
    {
        // convert to LITTLE_ENDIAN
        result.putUnsignedShort ( data.getUnsignedShort ( i * 2 ) );
    }

    // the byte order we use is BIG_ENDIAN
    result.order ( ByteOrder.BIG_ENDIAN );

    return result;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:32,代码来源:ModbusProtocol.java

示例2: encodeBrowseUpdate

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private void encodeBrowseUpdate ( final IoSession session, final Object message, final IoBuffer data ) throws ProtocolCodecException
{
    // length
    data.putUnsignedShort ( ( (BrowseAdded)message ).getEntries ().size () );

    final CharsetEncoder encoder = Sessions.getCharsetEncoder ( session );

    // data
    for ( final BrowseAdded.Entry entry : ( (BrowseAdded)message ).getEntries () )
    {
        data.putUnsignedShort ( entry.getRegister () );
        data.put ( entry.getDataType ().getDataType () );
        data.putEnumSet ( entry.getFlags () );

        try
        {
            data.putPrefixedString ( entry.getName (), encoder );
            data.putPrefixedString ( entry.getDescription (), encoder );
            data.putPrefixedString ( entry.getUnit (), encoder );
        }
        catch ( final CharacterCodingException e )
        {
            throw new ProtocolCodecException ( e );
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:27,代码来源:ProtocolEncoderImpl.java

示例3: encodeProperties

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private void encodeProperties ( final IoBuffer data, final Map<String, String> properties ) throws ProtocolCodecException
{
    final CharsetEncoder encoder = this.defaultCharset.newEncoder ();

    data.putUnsignedShort ( properties.size () );
    for ( final Map.Entry<String, String> entry : properties.entrySet () )
    {
        try
        {
            data.putPrefixedString ( entry.getKey (), encoder );
            data.putPrefixedString ( entry.getValue (), encoder );
        }
        catch ( final CharacterCodingException e )
        {
            throw new ProtocolCodecException ( e );
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:ProtocolEncoderImpl.java

示例4: makeReadReply

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
protected Object makeReadReply ( final BaseMessage baseMessage, final int[] data, final ByteOrder order )
{
    final IoBuffer reply = IoBuffer.allocate ( data.length * 2 );

    reply.order ( order );

    for ( int i = 0; i < data.length; i++ )
    {
        reply.putUnsignedShort ( data[i] );
    }
    reply.flip ();
    return new ReadResponse ( baseMessage.getTransactionId (), baseMessage.getUnitIdentifier (), baseMessage.getFunctionCode (), reply );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:14,代码来源:SlaveHost.java

示例5: encode

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void encode ( final IoSession session, final Object message, final ProtocolEncoderOutput out ) throws Exception
{
    logger.debug ( "Encoding: {}", message );
    final Pdu request = (Pdu)message;

    final IoBuffer buffer = IoBuffer.allocate ( request.getData ().remaining () + 7 );
    buffer.setAutoExpand ( true );

    final IoBuffer pdu = request.getData ();

    // put transaction identifier
    buffer.putUnsignedShort ( request.getTransactionId () );
    // put modbus protocol identifier (always 0)
    buffer.putUnsignedShort ( 0 );
    // put length, including slave id
    buffer.putUnsignedShort ( request.getData ().remaining () + 1 );
    // put slave id
    buffer.put ( request.getUnitIdentifier () );
    // put data
    buffer.put ( pdu );

    buffer.flip ();

    logger.trace ( "Encoded to: {}", buffer );

    out.write ( buffer );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:29,代码来源:ModbusTcpEncoder.java

示例6: encodeEntry

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
private void encodeEntry ( final IoSession session, final IoBuffer data, final Entry entry ) throws ProtocolCodecException
{
    data.putUnsignedShort ( entry.getRegister () );
    data.put ( entry.getMissedUpdates () );
    data.putLong ( entry.getTimestamp () );
    data.putEnumSetShort ( entry.getStates () );

    // put payload
    encodeVariant ( session, data, entry.getValue () );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:11,代码来源:ProtocolEncoderImpl.java

示例7: putValue

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void putValue ( final IoBuffer slice, final Variant value )
{
    slice.putUnsignedShort ( makeValue ( value ) );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:6,代码来源:UnsignedShortIntegerType.java

示例8: put

import org.apache.mina.core.buffer.IoBuffer; //导入方法依赖的package包/类
@Override
public void put ( final IoBuffer data, final Integer value )
{
    data.putUnsignedShort ( value );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:6,代码来源:UInt16Accessor.java


注:本文中的org.apache.mina.core.buffer.IoBuffer.putUnsignedShort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。