package nmodbus_test import ( "encoding/binary" "git.noahlan.cn/noahlan/nnet/config" "git.noahlan.cn/noahlan/ntool-biz/nmodbus" "git.noahlan.cn/noahlan/ntool-biz/nmodbus/util" "testing" ) func TestA(t *testing.T) { ngin, handler := nmodbus.NewModbusTCPEngine(nmodbus.ModbusTCPConf{ EngineConf: config.EngineConf{ Mode: "dev", Name: "ModbusTCP", }, ByteOrder: binary.BigEndian, }) defer ngin.Stop() // read:0x03 write:0x06 handler.HoldingRegisters[0] = 0b00000011 // > 0000000000000011 = 0x03 = 3 // 1~2 浮点 [2]uint16 copy(handler.HoldingRegisters[1:2], util.Float32ToUint16(binary.BigEndian, 1.25)) handler.HoldingRegisters[3] = 21 // read:0x04 non-write handler.InputRegisters[0] = 0b00000011 _ = ngin.ListenTCP(config.TCPServerConf{ Protocol: "tcp", Addr: "0.0.0.0:5502", }) }