0

如果要將Modbus TCP 範例中的slave端改成PLC,並由電腦上的labview發起命令,需要更改範例程式的哪個部分,然後才可以加入以下的程式。

(以下是ameba開發板藉由RS232 轉 TTL來讀取PLC的程式,)

/*
Software serial test

Receives from serial RX, and then sends to serial TX

The circuit:
* RX is digital pin 0 (connect to TX of other device)
* TX is digital pin 1 (connect to RX of other device)

*/
#include <SoftwareSerial.h>

SoftwareSerial mySerial(0, 1); // RX, TX

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);

Serial.println(“PLC serial communications Linking… ”);

// set the data rate for the SoftwareSerial port
mySerial.begin(9600);

// Send command to PLC

mySerial.println(“command..”);
}

void loop(){

// read from PLC

if (mySerial.available()) {
mySerial.write(mySerial.read());
}
}

williamlai 回答了