Fix tcp deadlines.
This commit is contained in:
@@ -41,6 +41,7 @@ func (m *Mbclient) ReadRegisters(first uint16, numRegs uint16) ([]uint16, error)
|
||||
req[7] = 3 //FunctionCode
|
||||
binary.BigEndian.PutUint16(req[8:10], first-1)
|
||||
binary.BigEndian.PutUint16(req[10:12], numRegs)
|
||||
m.conn.SetDeadline(time.Now().Add(10 * time.Second))
|
||||
byteswritten, err := m.conn.Write(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
func TestReadOneRegister(t *testing.T) {
|
||||
c, err := New("192.168.0.154:502", 1)
|
||||
assert.NoError(t, err)
|
||||
for n := 0; n < 5; n++ {
|
||||
res, err := c.ReadRegisters(12401, 2)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, res, 2)
|
||||
@@ -28,5 +29,6 @@ func TestReadOneRegister(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, res, 1)
|
||||
t.Log(res)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user