Block Serial Read / MODBUS-RTU

for everything else
Post Reply
stevek4444
Posts: 1
Joined: Tue Nov 24, 2015 2:54 pm

Block Serial Read / MODBUS-RTU

Post 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.
User avatar
pbreed
Posts: 1087
Joined: Thu Apr 24, 2008 3:58 pm

Re: Block Serial Read / MODBUS-RTU

Post 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...
joepasquariello
Posts: 85
Joined: Mon Apr 28, 2008 7:32 am

Re: Block Serial Read / MODBUS-RTU

Post 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
User avatar
pbreed
Posts: 1087
Joined: Thu Apr 24, 2008 3:58 pm

Re: Block Serial Read / MODBUS-RTU

Post 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...
joepasquariello
Posts: 85
Joined: Mon Apr 28, 2008 7:32 am

Re: Block Serial Read / MODBUS-RTU

Post 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
User avatar
pbreed
Posts: 1087
Joined: Thu Apr 24, 2008 3:58 pm

Re: Block Serial Read / MODBUS-RTU

Post 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
joepasquariello
Posts: 85
Joined: Mon Apr 28, 2008 7:32 am

Re: Block Serial Read / MODBUS-RTU

Post 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
User avatar
pbreed
Posts: 1087
Joined: Thu Apr 24, 2008 3:58 pm

Re: Block Serial Read / MODBUS-RTU

Post by pbreed »

Yes it applies to all standard netburner devices (IE everything except SBL2's and MOD5213)
Post Reply