func (this ModbusRTUConnection) SetTimeout(timeout time.Duration) error {
	var sec C.uint32_t = C.uint32_t(timeout / time.Second)
	var usec C.uint32_t = C.uint32_t((timeout - time.Duration(sec)) / time.Microsecond)
	if C.modbus_set_response_timeout(this.ctx, sec, usec) == -1 {
		return errors.New("Invalid timeout value")
	}
	return nil
}
示例#2
0
// The modbus_set_response_timeout() function shall set the timeout interval used to wait for a response. When a byte timeout is set, if elapsed time for the first byte of response is longer than the given timeout, an ETIMEDOUT error will be raised by the function waiting for a response. When byte timeout is disabled, the full confirmation response must be received before expiration of the response timeout.
//The value of to_usec argument must be in the range 0 to 999999.
func (this *RtuConnection) Set_response_timeout(timeout time.Duration) error {
	sec := timeout / time.Second

	to_sec := C.uint32_t(sec)
	to_usec := C.uint32_t((timeout - sec) / time.Microsecond)

	res, errno := C.modbus_set_response_timeout(this.ctx, to_sec, to_usec)
	if int(res) != 0 {
		return errors.New(modbus_strerror(errno))
	}
	return nil
}