Hi Guys
I'm quite afaid to enter this forum having no experience with programming at all so don't shoot yet 😎. All I want to do is read temperatures from a PT100 transmitter which say it used Modbus protocol (and it does, verified by someone else who has used it). The data sheet says:
Read Temp value, send command (example) 64 03 00 01 00 01 DC 3F (Device ID, function code, Register high bit, reg low bit, read number high bit, read number low bit, CRC_H, CRC_L).
Respnse will be: 64 03 02 01 0C 5F D9 (Device ID, function code, data byte numbers, Temp data high bit, Temp data low bit, CRC_H, CRC_L)
I wired the transmitter to A+ B-
After reading multitudes of examples from different libraries to try to understand a tiny bit, or byte, I used the code below.
There was no communication with the transmitter. It has a light that flashes and there was no light, and of course no data came through. I don't know what I don't know, so I'm looking for the error I have made if anyone can help I'd be most grateful.
#include ModbusRTUMaster
#if defined HAVE_RS485_HARD
#include
ModbusRTUMaster master(RS485);
#elif defined HAVE_RS232_HARD
#include
ModbusRTUMaster master(RS232);
#else
ModbusRTUMaster master(Serial1);
#endif
#define REGISTERS_TO_READ 2
const uint32_t baudrate = 9600;
uint32_t SlaveID = 0x64;
const uint16_t Address = 40002;
uint32_t lastSentTime = 0UL;
void setup() {
Serial.begin(9600); // Start the serial port
#if defined HAVE_RS485_HARD
RS485.begin(baudrate, HALFDUPLEX, SERIAL_8N1);
#elif defined HAVE_RS232_HARD
RS232.begin(baudrate, SERIAL_8N1);
#else
Serial1.begin(baudrate, SERIAL_8N1);
#endif
master.begin(baudrate);
Serial.println();
Serial.println("Checking start....");
}
void loop() {
Serial.println();
Serial.println("Checking Loop....");
// Send a request every 1000ms
if (millis() - lastSentTime > 925) {
// Read REGISTERS_TO_READ holding registers, starting at address 0.
// IMPORTANT: all read and write functions start a Modbus transmission, but they are not
// blocking, so you can continue the program while the Modbus functions work. To check for
// available responses, call master.available() function often.
if (!master.readHoldingRegisters(SlaveID, 0, REGISTERS_TO_READ)) {
// Failure treatment
}
Serial.print("Last time sent = ");
Serial.print(lastSentTime);
Serial.println();
lastSentTime = millis();
// Check available responses often
if (master.isWaitingResponse()) {
ModbusResponse response = master.available();
Serial.print("Holding Register values: ");
for (int i = 0; i
Serial.print(response.getRegister(i));
Serial.print(';');
if (response) {
if (response.hasError()) {
// Response failure treatment. You can use response.getErrorCode()
// to get the error code.
Serial.print("Error code is ");
Serial.println(response.getErrorCode());
} else {
// Get the discrete inputs values from the response
Serial.println();
}
}
}
}
}
delay(475);
}
Sent: Friday, July 21, 2023 7:46:57 PM
To: Hilton <[email protected]>
Subject: Reading a Modbus PT100 temperature probe
Una nueva pregunta Reading a Modbus PT100 temperature probe de Forum Controladores/PLC se ha publicado. Haga clic aquí para acceder a la pregunta:
Ver pregunta
Best Regards / Atentamente
Ricard Franch Technical Specialist
E: [email protected]T:
(+ 34) 938 76 01 91 WhatsApp: (+34) 644
92 79 00
Industrial Shields by Boot & Work Corp, S.L. | Camí del Grau, 25 | Sant Fruitós de Bages 08272 Barcelona
Boot & Work Corp. S.L.
+34 938 76 01 91 | [email protected] | https://www.industrialshields.com
Con tecnología de Odoo