/// <summary> /// Connects the client to the device. /// </summary> /// <returns>An awaitable task.</returns> public Task Connect() { logger?.LogTrace("ModbusClient.Connect"); if (isDisposed) { throw new ObjectDisposedException(GetType().FullName); } if (isStarted) { return(ConnectingTask); } isStarted = true; logger?.LogInformation("ModbusClient starting"); if (DriverEnableRS485 && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { try { var rs485 = GetDriverState(); serialDriverFlags = rs485.Flags; rs485.Flags |= RS485Flags.Enabled; rs485.Flags &= ~RS485Flags.RxDuringTx; SetDriverState(rs485); driverModified = true; } catch (Exception ex) { logger.LogError(ex, "ModbusClient.Connect faild to set RS485 serial driver state."); throw; } } wasConnected = false; mainCts = new CancellationTokenSource(); Task.Run(() => Reconnect(mainCts.Token)); ConnectingTask = GetWaitTask(mainCts.Token); return(ConnectingTask); }
/// <summary> /// Connects the client to the device. /// </summary> /// <returns>An awaitable task.</returns> public Task Connect() { logger?.LogTrace("ModbusClient.Connect"); if (isDisposed) { throw new ObjectDisposedException(GetType().FullName); } if (!isStarted) { logger?.LogInformation("ModbusClient starting"); isStarted = true; if (DriverEnableRS485 && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { try { var rs485 = GetDriverState(); serialDriverFlags = rs485.Flags; rs485.Flags |= RS485Flags.Enabled; rs485.Flags &= ~RS485Flags.RxDuringTx; SetDriverState(rs485); driverModified = true; } catch (Exception ex) { logger.LogError(ex, "ModbusClient.Connect faild to set RS485 serial driver state."); throw; } } ConnectingTask = Task.Run((Action)Reconnect); } return(ConnectingTask); }
static extern _LTRNative.LTRERROR LTR43_RS485_ExchangeEx(ref TLTR43 hnd, short[] PackToSend, short[] ReceivedPack, int OutPackSize, int InPackSize, RS485Flags flags, out int ReceivedSize);
public virtual _LTRNative.LTRERROR RS485_ExchangeEx(short[] PackToSend, short[] ReceivedPack, int OutPackSize, int InPackSize, RS485Flags flags, out int ReceivedSize) { return(LTR43_RS485_ExchangeEx(ref module, PackToSend, ReceivedPack, OutPackSize, InPackSize, flags, out ReceivedSize)); }