Analizörün A ve B portlarını RS 485 dönüştürücünün A ve B portlarına bağlantısını sağladım. Kullandığım analizörün register listesine göre adresleri yazdım. Fakat serial ekranda sürekli garip simgeler gördüm. Yardımlarınızı bekliyorum.
#include <ModbusMaster.h><br /> #define MAX485_DE 3<br />#define MAX485_RE_NEG 2<br /> // instantiate ModbusMaster object<br />ModbusMaster node;<br /> void preTransmission()<br />{<br /> digitalWrite(MAX485_RE_NEG, 1);<br /> digitalWrite(MAX485_DE, 1);<br />}<br /> void postTransmission()<br />{<br /> digitalWrite(MAX485_RE_NEG, 0);<br /> digitalWrite(MAX485_DE, 0);<br />}<br /> void setup()<br />{<br /> pinMode(MAX485_RE_NEG, OUTPUT);<br /> pinMode(MAX485_DE, OUTPUT);<br /> // Init in receive mode<br /> digitalWrite(MAX485_RE_NEG, 0);<br /> digitalWrite(MAX485_DE, 0);<br /> // Modbus communication runs at 115200 baud<br /> Serial.begin(9600);<br /> // Modbus slave ID 1<br /> node.begin(1, Serial);<br /> // Callbacks allow us to configure the RS485 transceiver correctly<br /> node.preTransmission(preTransmission);<br /> node.postTransmission(postTransmission);<br />}<br /> void loop()<br />{<br /> uint8_t result;<br /> // Read 16 registers starting at 0x3100)<br /> result = node.readInputRegisters(0x4000, 4);<br /> if (result == node.ku8MBSuccess)<br /> {<br /> Serial.print("Vbir: ");<br /> Serial.println(node.getResponseBuffer(0x02)/100.0f);<br /> Serial.print("Viki: ");<br /> Serial.println(node.getResponseBuffer(0x03)/100.0f);<br /> }<br /> delay(1000);<br />}
Soru yeni cevaplara kapalıdır.
Mehmet En iyi cevap olarak seçildi Mayıs 10, 2021
#include “SoftwareSerial.h”
/*—–( Declare Constants and Pin Numbers )—–*/
#define SSerialRX 10 //Serial Receive pin
#define SSerialTX 11 //Serial Transmit pin
#define SSerialTxControl 3 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 13
/*—–( Declare objects )—–*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
/*—–( Declare Variables )—–*/
int byteReceived;
String ph_hexa, ph_hexa_hight_byte, ph_hexa_low_byte, ph_hexa_value;
byte request [] = {
0x01, // slave adres id 1 analizör
0x03, // sorgu yani okuma
0x0F, // 0fa3 registerin hex formatı
0xA3,
0x00, //data buyuklugu
0x01,
0x77, //crc değeri
0x3C
};
void setup() /****** SETUP: RUNS ONCE ******/
{
// Start the built-in serial port, probably to Serial Monitor
Serial.begin(9600);
Serial.println(“YourDuino.com SoftwareSerial remote loop example”);
Serial.println(“Use Serial Monitor, type in upper window, ENTER”);
pinMode(Pin13LED, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver
// Start the software serial port, to another device
RS485Serial.begin(9600); // set the data rate
}//–(end setup )—
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
//response————————————————————————————
Serial.println();
digitalWrite(SSerialTxControl, RS485Transmit); // Init Transceiver
for (int i = 0; i < 8; i++) {
Serial.print(request[i], HEX);
RS485Serial.write((byte)request[i]);
}
Serial.println();
digitalWrite(SSerialTxControl, RS485Receive); // Init Transmit
delay(1000);
Serial.print("0: ");
for (int i = 0; i 60.00f){
//sendSms(“”);
}
Serial.println();
}
Serial.print(” “);
}
/*
Serial.println(ph_hexa);
ph_hexa = “”;
*/
Serial.println();
}
unsigned int hexToDec(String hexString) {
unsigned int decValue = 0;
int nextInt;
for (int i = 0; i = 48 && nextInt = 65 && nextInt = 97 && nextInt <= 102) nextInt = map(nextInt, 97, 102, 10, 15);
nextInt = constrain(nextInt, 0, 15);
decValue = (decValue * 16) + nextInt;
}
return decValue;
}