Hi,I am a beginner in arduino and English is not my native language.Anyway i hope my description would not be confusing,here it goes.
I am working with an assignment which requires me to send message in ascii format from PC to UNO board,and convert the message into RTU format and finally return it to PC.So I can see the corresponding RTU message in serial monitor.This assignment aims to design a simple modbus protocol convertor that could transfer the ascii to rtu.I have no experience with modbus protocal before and the only required hardware in this assignment is an arduino UNO board.Is there anybody know how to deal with it?It would be helpful if some code could be demonstrated.
Hi mikb55,thanks for your reply.The software I use is Arduino IDE.In this assignment my PC is master and the UNO Board is slave.My idea is that I type the message in the textbox of serial monitor of Arduino IDE and send it to arduino board.The uno board would read it in ascii format and return the corresponding RTU message to serial monitor.I find a similar code sketch to reach this goal,but there are still some places need to be modified.Here is my code,
String comdata = "";
if (comdata.length() > 0)
{
Serial.print(comdata);
comdata = "";
}
}
The ideal case is that I input the message in ascii format(like "hello"),and the UNO board returns the corresponding RTU message(like"01101000 01100101 01101100 01101100 01101111",since RTU data is binary).Currently I could only return the message in the same format(like the input is"hello",and the output is also "hello").Is there any advice for further improvements?Thanks in advance!
The Arduino serial monitor doesn't understand binary data. You need RTU slave software running on the PC to decode the binary data stream.
Modbus is more than a data format. It is a bidirectional communications protocol.
Perhaps you should talk to your supervisor and ask them to suggest books or web pages for background reading.