Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Arduino code for KC868-A32 Pro]-03 read / write by RS485
#1
Code:
#include <arduino.h>
#include "HardwareSerial.h"
String comdata1,comdata2;
HardwareSerial my485Serial(1);
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  my485Serial.begin(9600,SERIAL_8N1,8,9);///rx:32  tx:33
  Serial.println("UsbSerial say hello");
  my485Serial.println("R485 say hello");
}

void loop() {
  // put your main code here, to run repeatedly:
 
    while (my485Serial.available() > 0) {
      delay(100);
      comdata1 = my485Serial.readString();
      my485Serial.print("R485.readString:");
      my485Serial.println(comdata1);
    }
    while (Serial.available() > 0) {
        delay(100);
      comdata1 = Serial.readString();
      Serial.print("UsbSerial.readString:");
      Serial.println(comdata1);
    }
}
source code download:

.zip   RS485.zip (Size: 475 bytes / Downloads: 80)
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)