Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ fn print_write_result<T>(result: Result<T, RequestError>) {
}
}

async fn run_channel(mut channel: Channel) -> Result<(), Box<dyn std::error::Error>> {
async fn run_channel(channel: Channel) -> Result<(), Box<dyn std::error::Error>> {
channel.enable().await?;

// ANCHOR: request_param
Expand Down
2 changes: 1 addition & 1 deletion examples/perf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let start = std::time::Instant::now();

// spawn tasks that make requests for the specified duration
for (mut channel, params) in channels {
for (channel, params) in channels {
let handle: tokio::task::JoinHandle<Result<usize, RequestError>> =
tokio::spawn(async move {
let mut iterations = 0;
Expand Down
2 changes: 1 addition & 1 deletion integration/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async fn test_requests_and_responses() {
let (tx, mut rx) = tokio::sync::mpsc::channel(8);
let listener = ClientStateListener { tx };

let mut channel = spawn_tcp_client_task(
let channel = spawn_tcp_client_task(
HostAddr::ip(addr.ip(), addr.port()),
10,
default_retry_strategy(),
Expand Down
8 changes: 4 additions & 4 deletions rodbus-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,16 @@ async fn main() -> Result<(), Error> {
async fn run() -> Result<(), Error> {
let cli = Cli::parse();

let (mut channel, command) = setup_channel(cli.mode).await?;
let (channel, command) = setup_channel(cli.mode).await?;

let params = RequestParam::new(UnitId::new(cli.id), REQUEST_TIMEOUT);

match cli.period {
None => run_command(&command, &mut channel, params).await,
None => run_command(&command, &channel, params).await,
Some(period_ms) => {
let period = Duration::from_millis(period_ms);
loop {
run_command(&command, &mut channel, params).await?;
run_command(&command, &channel, params).await?;
tokio::time::sleep(period).await
}
}
Expand Down Expand Up @@ -367,7 +367,7 @@ async fn setup_serial(path: String, settings: ModeSerialSettings) -> Result<Chan

async fn run_command(
command: &Command,
channel: &mut Channel,
channel: &Channel,
params: RequestParam,
) -> Result<(), Error> {
match command {
Expand Down
18 changes: 9 additions & 9 deletions rodbus/src/client/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Channel {

/// Read coils from the server
pub async fn read_coils(
&mut self,
&self,
param: RequestParam,
range: AddressRange,
) -> Result<Vec<Indexed<bool>>, RequestError> {
Expand All @@ -161,7 +161,7 @@ impl Channel {

/// Read discrete inputs from the server
pub async fn read_discrete_inputs(
&mut self,
&self,
param: RequestParam,
range: AddressRange,
) -> Result<Vec<Indexed<bool>>, RequestError> {
Expand All @@ -176,7 +176,7 @@ impl Channel {

/// Read holding registers from the server
pub async fn read_holding_registers(
&mut self,
&self,
param: RequestParam,
range: AddressRange,
) -> Result<Vec<Indexed<u16>>, RequestError> {
Expand All @@ -194,7 +194,7 @@ impl Channel {

/// Read input registers from the server
pub async fn read_input_registers(
&mut self,
&self,
param: RequestParam,
range: AddressRange,
) -> Result<Vec<Indexed<u16>>, RequestError> {
Expand All @@ -212,7 +212,7 @@ impl Channel {

/// Write a single coil on the server
pub async fn write_single_coil(
&mut self,
&self,
param: RequestParam,
request: Indexed<bool>,
) -> Result<Indexed<bool>, RequestError> {
Expand All @@ -227,7 +227,7 @@ impl Channel {

/// Write a single register on the server
pub async fn write_single_register(
&mut self,
&self,
param: RequestParam,
request: Indexed<u16>,
) -> Result<Indexed<u16>, RequestError> {
Expand All @@ -242,7 +242,7 @@ impl Channel {

/// Write multiple contiguous coils on the server
pub async fn write_multiple_coils(
&mut self,
&self,
param: RequestParam,
request: WriteMultiple<bool>,
) -> Result<AddressRange, RequestError> {
Expand All @@ -260,7 +260,7 @@ impl Channel {

/// Write multiple contiguous registers on the server
pub async fn write_multiple_registers(
&mut self,
&self,
param: RequestParam,
request: WriteMultiple<u16>,
) -> Result<AddressRange, RequestError> {
Expand All @@ -277,7 +277,7 @@ impl Channel {
}

/// Dynamically change the protocol decoding level of the channel
pub async fn set_decode_level(&mut self, level: DecodeLevel) -> Result<(), Shutdown> {
pub async fn set_decode_level(&self, level: DecodeLevel) -> Result<(), Shutdown> {
self.tx
.send(Command::Setting(Setting::DecodeLevel(level)))
.await?;
Expand Down
18 changes: 9 additions & 9 deletions rodbus/src/client/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ mod tests {

#[tokio::test]
async fn returns_io_error_when_write_fails() {
let (mut channel, _task, mut io) = spawn_client_loop();
let (channel, _task, mut io) = spawn_client_loop();

let error_kind = ErrorKind::ConnectionReset;

Expand All @@ -452,7 +452,7 @@ mod tests {

#[tokio::test]
async fn returns_timeout_when_no_response() {
let (mut channel, _task, mut io) = spawn_client_loop();
let (channel, _task, mut io) = spawn_client_loop();

// the expected request
let range = AddressRange::try_from(7, 2).unwrap();
Expand All @@ -479,7 +479,7 @@ mod tests {

#[tokio::test]
async fn returns_shutdown_when_task_dropped() {
let (mut channel, task, mut io) = spawn_client_loop();
let (channel, task, mut io) = spawn_client_loop();

// the expected request
let range = AddressRange::try_from(7, 2).unwrap();
Expand Down Expand Up @@ -517,7 +517,7 @@ mod tests {

#[tokio::test]
async fn transmit_read_coils_when_requested() {
let (mut channel, _task, mut io) = spawn_client_loop();
let (channel, _task, mut io) = spawn_client_loop();

let range = AddressRange::try_from(7, 2).unwrap();
let request = get_framed_adu(FunctionCode::ReadCoils, &range);
Expand Down Expand Up @@ -558,7 +558,7 @@ mod tests {

// spawn 3 requests that will all timeout
for _ in 0..3 {
let mut ch = channel.clone();
let ch = channel.clone();
tokio::spawn(async move {
ch.read_coils(
RequestParam::new(UnitId::new(1), Duration::from_secs(1)),
Expand Down Expand Up @@ -588,7 +588,7 @@ mod tests {

// send 10 requests that all timeout
for _ in 0..10 {
let mut ch = channel.clone();
let ch = channel.clone();
tokio::spawn(async move {
ch.read_coils(
RequestParam::new(UnitId::new(1), Duration::from_secs(1)),
Expand Down Expand Up @@ -620,7 +620,7 @@ mod tests {

// First two timeouts
for _ in 0..2 {
let mut ch = channel.clone();
let ch = channel.clone();
tokio::spawn(async move {
ch.read_coils(
RequestParam::new(UnitId::new(1), Duration::from_secs(1)),
Expand All @@ -636,7 +636,7 @@ mod tests {

// Successful request
let success_task = tokio::spawn({
let mut ch = channel.clone();
let ch = channel.clone();
async move {
ch.read_coils(
RequestParam::new(UnitId::new(1), Duration::from_secs(1)),
Expand Down Expand Up @@ -675,7 +675,7 @@ mod tests {

// Two more timeouts - should NOT terminate since counter was reset
for _ in 0..2 {
let mut ch = channel.clone();
let ch = channel.clone();
tokio::spawn(async move {
ch.read_coils(
RequestParam::new(UnitId::new(1), Duration::from_secs(1)),
Expand Down
2 changes: 1 addition & 1 deletion rodbus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//!#[tokio::main(flavor = "multi_thread")]
//!async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!
//! let mut channel = spawn_tcp_client_task(
//! let channel = spawn_tcp_client_task(
//! HostAddr::ip("127.0.0.1".parse()?, 502),
//! 10,
//! default_retry_strategy(),
Expand Down