Coder Social home page Coder Social logo

Comments (4)

yaacov avatar yaacov commented on July 22, 2024

Hi, thanks for the issue, i added a help wanted label in case someone can help.

from arduinomodbusslave.

device111 avatar device111 commented on July 22, 2024

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.

device111 avatar device111 commented on July 22, 2024

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

  1. use Modbus wtith own array for registers.
  2. clean your code. It's verry hard to read.

from arduinomodbusslave.

kurt-klingbeil avatar kurt-klingbeil commented on July 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.