當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。