package net.vtstar.zhongtong.avi;

import io.netty.buffer.ByteBuf;
import lombok.extern.slf4j.Slf4j;
import net.vtstar.protocol.modbus.tcp.netty.packet.ReadCoilsRequest;
import net.vtstar.protocol.modbus.tcp.netty.packet.ReadCoilsResponse;
import net.vtstar.protocol.modbus.tcp.netty.service.ModbusTemplate;
import net.vtstar.protocol.modbus.tcp.netty.utils.PoolKey;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@ActiveProfiles("dev-yxh")
public class ModbusTest {

    @Autowired
    private ModbusTemplate modbusTemplate;

    @Test
    public void test() throws Exception {

        ReadCoilsRequest readCoilsRequest = new ReadCoilsRequest(1,0,5);
        PoolKey poolKey = new PoolKey("localhost",502);
        ReadCoilsResponse response= modbusTemplate.execute(poolKey, readCoilsRequest, ReadCoilsResponse.class);
        ByteBuf body = response.getBody();
        byte b = body.readByte();
        System.out.println("___" + b);
//        byte[] array = body.array();
    }
}
