Goodmorning everyone,
So far I used the attached code that uses the modbus rtu protocol but now for various reasons I have to move on modbus tcp.
The structure of the code I used would like to keep it as it is.
Can you tell me a modbus tcp library for arduino and point me a method to apply it to the code?
\#include<Controllino.h>Â /* Usage of CONTROLLINO library allows you to use CONTROLLINO_xx aliases in your sketch. */
\#include<ModbusRtu.h>
\#defineID3Modbusslave(ID, 0, 0); // this is slave ID and RS-232 or USB-FTDIint8_tstate=0;//dataarrayformodbusnetworksharinguint16_tau16data[9];voidsetup() {
 io_setup(); // I/O settings
 slave.begin(38400);
}
voidloop() {
 //pollmessages
 state=slave.poll(au16data, 9);
 io_poll();
}
voidio_setup() {
 //Setdigitalout
 pinMode(CONTROLLINO_R0, OUTPUT); // next to the digital output screw terminal
 pinMode(CONTROLLINO_R1, OUTPUT); // next to the digital output screw terminal
 pinMode(CONTROLLINO_R2, OUTPUT); // next to the digital output screw terminal
 pinMode(CONTROLLINO_R3, OUTPUT); // next to the digital output screw terminal
 pinMode(CONTROLLINO_R4, OUTPUT); // next to the digital output screw terminal
 pinMode(CONTROLLINO_R5, OUTPUT); // next to the digital output screw terminal
 pinMode(CONTROLLINO_R6, OUTPUT); // next to the digital output screw terminal
 pinMode(CONTROLLINO_R7, OUTPUT); // next to the digital output screw terminal
 pinMode(CONTROLLINO_R8, OUTPUT); // next to the digital output screw terminal
 pinMode(CONTROLLINO_R9, OUTPUT); // next to the digital output screw terminal
 //Setanalogin(usedasdigital)
 pinMode(CONTROLLINO_A0, INPUT); // next to the analog input screw terminal
 pinMode(CONTROLLINO_A1, INPUT); // next to the analog input screw terminal
 pinMode(CONTROLLINO_A2, INPUT); // next to the analog input screw terminal
 pinMode(CONTROLLINO_A3, INPUT); // next to the analog input screw terminal
 pinMode(CONTROLLINO_A4, INPUT); // next to the analog input screw terminal
 pinMode(CONTROLLINO_A5, INPUT); // next to the analog input screw terminal
 pinMode(CONTROLLINO_A6, INPUT); // next to the analog input screw terminal
 pinMode(CONTROLLINO_A7, INPUT); // next to the analog input screw terminal
 pinMode(CONTROLLINO_A8, INPUT); // next to the analog input screw terminal
 pinMode(CONTROLLINO_A9, INPUT); // next to the analog input screw terminal
}
voidio_poll() {
 //getanaloginputs->au16data[0]
 bitWrite(au16data[0], 0, digitalRead(CONTROLLINO_A0));
 bitWrite(au16data[0], 1, digitalRead(CONTROLLINO_A1));
 bitWrite(au16data[0], 2, digitalRead(CONTROLLINO_A2));
 bitWrite(au16data[0], 3, digitalRead(CONTROLLINO_A3));
 bitWrite(au16data[0], 4, digitalRead(CONTROLLINO_A4));
 bitWrite(au16data[0], 5, digitalRead(CONTROLLINO_A5));
 bitWrite(au16data[0], 6, digitalRead(CONTROLLINO_A6));
 bitWrite(au16data[0], 7, digitalRead(CONTROLLINO_A7));
 bitWrite(au16data[0], 8, digitalRead(CONTROLLINO_A8));
 bitWrite(au16data[0], 9, digitalRead(CONTROLLINO_A9));
 //bitWrite(au16data[0], 10, digitalRead(CONTROLLINO_IN0));
 //bitWrite(au16data[0], 11, digitalRead(CONTROLLINO_IN1));
 //setdigitaloutputs->au16data[1]
 digitalWrite(CONTROLLINO_R0, bitRead(au16data[1], 0));
 digitalWrite(CONTROLLINO_R1, bitRead(au16data[1], 1));
 digitalWrite(CONTROLLINO_R2, bitRead(au16data[1], 2));
 digitalWrite(CONTROLLINO_R3, bitRead(au16data[1], 3));
 digitalWrite(CONTROLLINO_R4, bitRead(au16data[1], 4));
 digitalWrite(CONTROLLINO_R5, bitRead(au16data[1], 5));
 digitalWrite(CONTROLLINO_R6, bitRead(au16data[1], 6));
 digitalWrite(CONTROLLINO_R7, bitRead(au16data[1], 7));
 digitalWrite(CONTROLLINO_R8, bitRead(au16data[1], 8));
 digitalWrite(CONTROLLINO_R9, bitRead(au16data[1], 9));
 //diagnosecommunication
 au16data[6] =slave.getInCnt();
 au16data[7] =slave.getOutCnt();
 au16data[8] =slave.getErrCnt();
}
Goodmorning everyone,
So far I used the attached code that uses the modbus rtu protocol but now for various reasons I have to move on modbus tcp.
The structure of the code I used would like to keep it as it is.
Can you tell me a modbus tcp library for arduino and point me a method to apply it to the code?
Related
Talk.ru: 1
Talk.ru: 7
Talk.ru: 8
look at this http://www.fleaplc.it/en/tutorials/29-arduino it should help you