PDA

View Full Version : Serial protocol - How to detect frame start/end - Modbus



pacman
12-22-2009, 11:06 AM
I've been dabbling with Modbus recently, but have hit a bit of a problem with detecting the 3.5 character silence at the start/end of a modbus RTU packet.

I was thinking that as I know the baud rate, I could use something like the Extended_FDSerial object and the rxDecTime function within it to get fairly accurate timing..

I'm not convinced that this is the best (or even if this is a good/mediocre) way of detecting the silence.

Can anyone suggest an alternative? {sample code would be appreciated...}

Thanks in advance..

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
=================
The future is in our hands.
Which way to the future?
=================

Bill Henning
12-22-2009, 11:21 AM
Keep a "last start bit cnt value" register, initialized to cnt when you start your serial object

then check to see if last cnt > 3.5 character intervals, if so, new packet... regardless, save cnt to last cnt/



pacman said...
I've been dabbling with Modbus recently, but have hit a bit of a problem with detecting the 3.5 character silence at the start/end of a modbus RTU packet.

I was thinking that as I know the baud rate, I could use something like the Extended_FDSerial object and the rxDecTime function within it to get fairly accurate timing..

I'm not convinced that this is the best (or even if this is a good/mediocre) way of detecting the silence.

Can anyone suggest an alternative? {sample code would be appreciated...}

Thanks in advance..

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.mikronauts.com (http://www.mikronauts.com) Please use mikronauts _at_ gmail _dot_ com to contact me off-forum, my PM is almost totally full
Morpheus (http://mikronauts.com/products/morpheus/)dual Prop SBC w/ 512KB kit $119.95, Mem+2MB memory IO board kit $89.95, both kits $189.95
Propteus (http://mikronauts.com/products/propteus/) and Proteus (http://mikronauts.com/products/propteus/) for Propeller prototyping 6.250MHz custom Crystals run Propellers at 100MHz (http://mikronauts.com/products/mikronauts-625mhz-crystal/)
Las (http://mikronauts.com/software-products/largos/) - Large model assembler for the Propeller Largos (http://mikronauts.com/software-products/largos/) - a feature full nano operating system for the Propeller

Reset_Vector
12-22-2009, 11:18 PM
Hi Pacman,
As previous said, here is my MODBUS protocol handler.
If you have any questions, you can ask me.

Best regards from France

Dave Matthews
11-01-2010, 10:13 PM
I very much appreciate the code Olivier, any recent updates? I am just beginning to work on a version of the protocol relying heavily upon your work so generously posted. This week is the big push for me, so I hope you are still out there and perhaps available for questions.

Thanks again for publishing your creation,
Dave KI4PSR