Example usage for io.netty.buffer ByteBuf writeShort

List of usage examples for io.netty.buffer ByteBuf writeShort

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf writeShort.

Prototype

public abstract ByteBuf writeShort(int value);

Source Link

Document

Sets the specified 16-bit short integer at the current writerIndex and increases the writerIndex by 2 in this buffer.

Usage

From source file:com.digitalpetri.modbus.codec.ModbusRequestEncoder.java

License:Apache License

public ByteBuf encodeReadInputRegisters(ReadInputRegistersRequest request, ByteBuf buffer) {
    buffer.writeByte(request.getFunctionCode().getCode());
    buffer.writeShort(request.getAddress());
    buffer.writeShort(request.getQuantity());

    return buffer;
}

From source file:com.digitalpetri.modbus.codec.ModbusRequestEncoder.java

License:Apache License

public ByteBuf encodeWriteSingleCoil(WriteSingleCoilRequest request, ByteBuf buffer) {
    buffer.writeByte(request.getFunctionCode().getCode());
    buffer.writeShort(request.getAddress());
    buffer.writeShort(request.getValue());

    return buffer;
}

From source file:com.digitalpetri.modbus.codec.ModbusRequestEncoder.java

License:Apache License

public ByteBuf encodeWriteSingleRegister(WriteSingleRegisterRequest request, ByteBuf buffer) {
    buffer.writeByte(request.getFunctionCode().getCode());
    buffer.writeShort(request.getAddress());
    buffer.writeShort(request.getValue());

    return buffer;
}

From source file:com.digitalpetri.modbus.codec.ModbusRequestEncoder.java

License:Apache License

public ByteBuf encodeWriteMultipleCoils(WriteMultipleCoilsRequest request, ByteBuf buffer) {
    buffer.writeByte(request.getFunctionCode().getCode());
    buffer.writeShort(request.getAddress());
    buffer.writeShort(request.getQuantity());

    int byteCount = (request.getQuantity() + 7) / 8;
    buffer.writeByte(byteCount);/*from w ww . j  a v a2s.co  m*/

    buffer.writeBytes(request.getValues(), byteCount);

    return buffer;
}

From source file:com.digitalpetri.modbus.codec.ModbusRequestEncoder.java

License:Apache License

public ByteBuf encodeWriteMultipleRegisters(WriteMultipleRegistersRequest request, ByteBuf buffer) {
    buffer.writeByte(request.getFunctionCode().getCode());
    buffer.writeShort(request.getAddress());
    buffer.writeShort(request.getQuantity());

    int byteCount = request.getQuantity() * 2;
    buffer.writeByte(byteCount);/*from  w w w. ja  v a2 s  .c o  m*/

    buffer.writeBytes(request.getValues(), byteCount);

    return buffer;
}

From source file:com.digitalpetri.modbus.codec.ModbusRequestEncoder.java

License:Apache License

public ByteBuf encodeMaskWriteRegister(MaskWriteRegisterRequest request, ByteBuf buffer) {
    buffer.writeByte(request.getFunctionCode().getCode());
    buffer.writeShort(request.getAddress());
    buffer.writeShort(request.getAndMask());
    buffer.writeShort(request.getOrMask());

    return buffer;
}

From source file:com.digitalpetri.modbus.codec.ModbusResponseEncoder.java

License:Apache License

private ByteBuf encodeWriteSingleCoil(WriteSingleCoilResponse response, ByteBuf buffer) {
    buffer.writeByte(response.getFunctionCode().getCode());
    buffer.writeShort(response.getAddress());
    buffer.writeShort(response.getValue());

    return buffer;
}

From source file:com.digitalpetri.modbus.codec.ModbusResponseEncoder.java

License:Apache License

private ByteBuf encodeWriteSingleRegister(WriteSingleRegisterResponse response, ByteBuf buffer) {
    buffer.writeByte(response.getFunctionCode().getCode());
    buffer.writeShort(response.getAddress());
    buffer.writeShort(response.getValue());

    return buffer;
}

From source file:com.digitalpetri.modbus.codec.ModbusResponseEncoder.java

License:Apache License

private ByteBuf encodeWriteMultipleCoils(WriteMultipleCoilsResponse response, ByteBuf buffer) {
    buffer.writeByte(response.getFunctionCode().getCode());
    buffer.writeShort(response.getAddress());
    buffer.writeShort(response.getQuantity());

    return buffer;
}

From source file:com.digitalpetri.modbus.codec.ModbusResponseEncoder.java

License:Apache License

private ByteBuf encodeWriteMultipleRegisters(WriteMultipleRegistersResponse response, ByteBuf buffer) {
    buffer.writeByte(response.getFunctionCode().getCode());
    buffer.writeShort(response.getAddress());
    buffer.writeShort(response.getQuantity());

    return buffer;
}