New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delay before read response in to Serial #95

Closed
wants to merge 2 commits into
base: development
from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+13 −0
Diff settings

Always

Just for now

@@ -42,6 +42,7 @@
private int transDelayMS = Modbus.DEFAULT_TRANSMIT_DELAY;
private final Object MUTEX = new Object();
private long lastTransactionTimestamp = 0;
private int delayReadResponse = 0;

/**
* Constructs a new <tt>ModbusSerialTransaction</tt>
@@ -73,6 +74,14 @@ public ModbusSerialTransaction(AbstractSerialConnection con) {
setSerialConnection(con);
}

public int getDelayReadResponse() {
return delayReadResponse;
}

public void setDelayReadResponse(int delayReadResponse) {
this.delayReadResponse = delayReadResponse;
}

/**
* Sets the port on which this <tt>ModbusTransaction</tt>
* should be executed.
@@ -138,6 +147,8 @@ public void execute() throws ModbusException {
synchronized (MUTEX) {
//write request message
transport.writeRequest(request);
//Delay before read response
Thread.sleep(delayReadResponse);
//read response message
response = transport.readResponse();
finished = true;
@@ -149,6 +160,8 @@ public void execute() throws ModbusException {
}
ModbusUtil.sleep(getRandomSleepTime(tries));
logger.debug("Execute try {} error: {}", tries, e.getMessage());
} catch (InterruptedException e) {
e.printStackTrace();
}
} while (!finished);

ProTip! Use n and p to navigate between commits in a pull request.