Comments (4)
Hi, thanks for the issue, i added a help wanted label in case someone can help.
from arduinomodbusslave.
Hello,
first thing, delete this:
//remove from final version
if (Serial1.available() > 100)
{
byte incomingByte1 = Serial1.read(); // read the incoming byte:
Serial.print(">>"); Serial.println(incomingByte1);
digitalWrite(RS485DEPin, HIGH); // (Pin RS485DEPin always LOW to receive value from Master)
delay(10);
Serial1.print(">>"); Serial1.println(incomingByte1);
digitalWrite(RS485DEPin, LOW); // (Pin RS485DEPin always LOW to receive value from Master)
delay(10);
}
You should not read the Serial1. the modbus library do this for you. If you read the Serial1, the bytes are removed from the Serial1 buffer.
2. Dont't use "delays" in your code.
Here you read only bytes. (uint8_t):
// Handle the function code Read Holding Registers (FC=03) and write back the values from the EEPROM (holding registers).
uint8_t readMemory(uint8_t fc, uint16_t address, uint16_t length)
{
// Read the requested ClientStatus registers.
for (int i = 0; i < length; i++)
{
// Below 50 is reserved for pinModes, above 50 is free to use.
if (address >= 0)
{
uint8_t value;
value = hr.MB_HoldReg[i+address];
slave.writeRegisterToBuffer(i, value);
}
}
// Serial.print("FC "); Serial.print(fc); Serial.print(" Address "); Serial.print(address);
// Serial.println(" OK");
return STATUS_OK;
}
check the things and try again.
br
from arduinomodbusslave.
here is the next one:
union { struct ClientStatusEx ClSt[N_Slots]; uint8_t MB_HoldReg[sizeof(ClientStatusEx) * N_Slots]; } hr;
declare it as uint16_t
- use Modbus wtith own array for registers.
- clean your code. It's verry hard to read.
from arduinomodbusslave.
thank you for reviewing my code
I have assembled it by copy/pasting example code from several libraries
I am used to having separate modules in separate files and have not quite figured out the stylistic aspects
of putting all the code into one file...
My reading and experience of the //remove from final version code is that serial1 will only be read directly
when the available character count reaches 100. A kind of debugging aid should the modbus processing stop.
So far I have not experienced such loss of data.
I did previously experiment with changing the union { uint8_t MB_HoldReg[... to uint16_t
however that conflicts with the RHReliableDatagram code
I will have to do as you suggest and create a separate array for the modbus data
from arduinomodbusslave.
Related Issues (20)
- Strange behiavor on slave using write single register HOT 9
- Stuck when calling flush() in begin() when using Serial1 in Arduino MKR(Zero) HOT 2
- Not working with I2C communication HOT 9
- Enable / disable communication HOT 2
- Arduino Mudbus RTU for MASTER to read/write for multi slave ?
- change Slave_ID in void setup() HOT 2
- Put data in a specific address HOT 1
- using a modbus master simulator software with this library HOT 10
- Exception Response , Illegal Data Address HOT 1
- linux modpoll HOT 1
- Change SLAVE ADDRESS during void setup HOT 1
- Hello how can i read data from 40001 HOT 1
- hi i am getting modbus poll pc application timeout error Could you please help me HOT 1
- Modbus Slave RP2 HOT 2
- 怎么设置 数据位 停止位
- Arduino Pro Micro
- Create new release HOT 4
- ESP32 Support HOT 8
- Character silent interval issue and Buffer overrun HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduinomodbusslave.