extending the Uart class
BobVal
Posts: 48
Hello:
I want to extend the Uart class so that my extension program can check the Uart for something coming in and have the data parsed for the main app.
lets us what follows as examples:
class ParseData extends Uart· {
······ private· boolean· ParseIncoming()· {
···························· if·· (byteAvailable())·· {
·································· //
·································· //· Here we would parse the data into arrays and
·································· //·········have the data ready for the main app
···································//
·································· return true;
··························· ·}
············· ·············· return false;
······ }
······ public boolean· AnyData()· {
··························· //
··························· //· If we have ANY data parsed the return true
··························· //
········
······ }
······ public ParseData(int UsePin)· {
························· super(Uart.dirReceive, UsePin, Uart.dontInvert, Uart.speed9600, Uart.stop1);
······ }
}
public· class· Main· {
·········ParseData· mIncomingData = new ParseData(7);· //· Pin Number for RX
········ public void main()· {
················· while(true)· {
························· if· (mIncomingData.AnyData())· {
······························ //· If any parsed data then find out what type and do something about it.
·························}
········ }
}
============================
NOW HERE ARE MY PROBLEMS
============================
The reason I want to extend the Uart class is because I will need this class in other programs.
I do not completely understand how the Virtual Peripherals class works.
How would I get my ParseIncoming of ParseData to RUN NON-STOP checking the Uart for input and parsing it?
What makes a routine in a Virtual Peripherals class get called?
=============================
I KNOW, I KNOW, I KNOW
=============================
I know I can probably do this in one of another 5 different ways.·
But I want to LEARN how the Virtual Peripherals class works for things I might want to do later on down the road.
So can any explain to me how a routine in a Virtual Peripherals class runs / gets called on it's own?
Is there any extended help / doc on the Virtual Peripherals class.
Has anyone done anything like I am talking about?
Thanks in advance.
BobVal
I want to extend the Uart class so that my extension program can check the Uart for something coming in and have the data parsed for the main app.
lets us what follows as examples:
class ParseData extends Uart· {
······ private· boolean· ParseIncoming()· {
···························· if·· (byteAvailable())·· {
·································· //
·································· //· Here we would parse the data into arrays and
·································· //·········have the data ready for the main app
···································//
·································· return true;
··························· ·}
············· ·············· return false;
······ }
······ public boolean· AnyData()· {
··························· //
··························· //· If we have ANY data parsed the return true
··························· //
········
······ }
······ public ParseData(int UsePin)· {
························· super(Uart.dirReceive, UsePin, Uart.dontInvert, Uart.speed9600, Uart.stop1);
······ }
}
public· class· Main· {
·········ParseData· mIncomingData = new ParseData(7);· //· Pin Number for RX
········ public void main()· {
················· while(true)· {
························· if· (mIncomingData.AnyData())· {
······························ //· If any parsed data then find out what type and do something about it.
·························}
········ }
}
============================
NOW HERE ARE MY PROBLEMS
============================
The reason I want to extend the Uart class is because I will need this class in other programs.
I do not completely understand how the Virtual Peripherals class works.
How would I get my ParseIncoming of ParseData to RUN NON-STOP checking the Uart for input and parsing it?
What makes a routine in a Virtual Peripherals class get called?
=============================
I KNOW, I KNOW, I KNOW
=============================
I know I can probably do this in one of another 5 different ways.·
But I want to LEARN how the Virtual Peripherals class works for things I might want to do later on down the road.
So can any explain to me how a routine in a Virtual Peripherals class runs / gets called on it's own?
Is there any extended help / doc on the Virtual Peripherals class.
Has anyone done anything like I am talking about?
Thanks in advance.
BobVal
Comments
on the number of methods in a class (64 or so).
Better to create your own class, passing a Uart object via the constructor.
package stamp.myclasses.parse;
import stamp.core.*;
public class ParseData·{
· private Uart rx;·
· //constructor
· public ParseData(Uart rx) {
··· this.rx = rx;
· }
· private· boolean· ParseIncoming()· {
····if·· (rx.byteAvailable())·· {
······//
······//· Here we would parse the data into arrays and
······//·········have the data ready for the main app
······//
······return true;
····}
··· return false;
··}
··public boolean· AnyData()· {
····boolean parse =·ParseIncoming(); //check for incoming data
··· //
····//· If we have ANY data parsed the return true
····//
········
··}
}
import stamp.core.*;
import stamp.myclasses.parse.*;
public·class·myMainClass·{
· static final int UsePin = CPU.pin0;
· static Uart parseUart = new Uart(Uart.dirReceive, UsePin, Uart.dontInvert, Uart.speed9600, Uart.stop1);
··static·ParseData· mIncomingData = new ParseData(parseUart);
··static·void main()· {
····while (true)· { //mainloop
······if· (mIncomingData.AnyData())· { //keep checking for incoming data and parse if available
········//· If any parsed data then find out what type and do something about it.
······}
····}
· }
}
The advantage of this setup is that you define your VP's in your main class so you can easily
manage those. It is the responsibility of the programmer to ensure certain parts are continuesly
running. This is best done from the mainloop as in your example above.
regards peter
I guess you missed the point.· I surely could do what you suggested, and actually have.
But this does not help me learn anything about writing a VirtualPeripheral.
How do routines get called in a VirtualPeripheral
where is the vpBank routine and what does it do?
The coolest of this chip is the VirtualPeripheral class and I want to understand why and how it works so I can try writting my own.
Bob
All you can do is write classes that make use of the available VP's like Uart and PWM.
regards peter