Page 1 of 1

Block Serial Read / MODBUS-RTU

Posted: Tue Dec 08, 2015 2:28 pm
by stevek4444
I am new to the Netburner platform and am in need of some guidance on how to setup a timer to detect gaps in received characters in order to determine the end of a response to a MODBUS-RTU query. Basically, a response message is defined as a gap larger the 3.5 character times between successive bytes in a message stream. In my code I want to be able to detect the gaps. I have successfully used a decremented counter that is reset to a known timing value on each character received. When the count reaches zero the message frame receipt is completed.

I prefer ISR code for the serial RX processing but would need to add the code to update the countdown mechanism/ restart a one-shot timer.

My platform is the SBL2E with the 2.7.3 IDE.

Thanks in advance for any guidance.

Re: Block Serial Read / MODBUS-RTU

Posted: Tue Dec 08, 2015 5:52 pm
by pbreed
Add a function:

void MyRecievedData(BYTE data)
{//This function will be called in the ISR for eaqch recieved serial BYTE...
//Do what you will, check your timers etc....
}

//Point the serial port data handler at your function..
//port is 0,1,2
SerialPortCallBack[port]=MyRecievedData;


//Just open the serial port in the normal way.
InitIRQUart(port,baud,1,8,eParityNone);

//Now every received byte will go to your special function rather than to the system processing...
//It will happen as soon as the ISR is serviced... which unless you have a lot of something else going on will be
//within a usec of so of char receive...

Re: Block Serial Read / MODBUS-RTU

Posted: Fri Apr 29, 2016 5:48 pm
by joepasquariello
Does this apply only to SB2LE? I can't find any mention of SerialCallBack in any docs or source other than an SB2LE example.

Joe

Re: Block Serial Read / MODBUS-RTU

Posted: Sun May 01, 2016 12:06 pm
by pbreed
Yes that specific call is SBL2E specific...

For the non l2e you have two approaches...

1)
Under the web site support there is a docs and downloads link...
look under your platform
Then look under development kit...
There is a how to write your own serial driver set of examples...


2)There is a function pointer in the serial drivers that will
get called by the ISR for every received charator...
Its documented in serinternal.h

so

if you have a function..

void MyProcessRxChar(int num, BYTE c);

You can

#include <serinternal.h>


UartData[port_number].m_pPutCharFunc=MyProcessRxChar;

The num parameter is the serial port number the call back us being called for...

Re: Block Serial Read / MODBUS-RTU

Posted: Sun May 01, 2016 6:07 pm
by joepasquariello
Hi Paul,

Thanks. I see in Serial.cpp for 5234 that those pointers are assigned BasePutChar and BaseGetChar on initialization, so changing them to point to your own functions would bypass the standard FIFOs without fiddling with the ISRs. That seems a lot simpler than completely replacing the ISRs as in the bare driver example.

Joe

Re: Block Serial Read / MODBUS-RTU

Posted: Sun May 01, 2016 10:04 pm
by pbreed
If your going to modify the TX pointer then you will have to return -1 when you have no chars to send.
Anytime you have returned -1 you must call

void WakeTx( int x )

When you want the transmitter to wake up again....

See serwrite in serial.cpp


Paul

Re: Block Serial Read / MODBUS-RTU

Posted: Mon May 02, 2016 9:57 am
by joepasquariello
Thanks, I will give it a try and report back.

Does all of this apply to MOD5441X and its 10 UARTs? I have an application to build a simulation that runs on that board.

Joe

Re: Block Serial Read / MODBUS-RTU

Posted: Mon May 02, 2016 10:01 am
by pbreed
Yes it applies to all standard netburner devices (IE everything except SBL2's and MOD5213)