Shop OBEX P1 Docs P2 Docs Learn Events
unsure about instances of uart — Parallax Forums

unsure about instances of uart

darnitdarnit Posts: 25
edited 2006-04-25 18:27 in General Discussion
I am trying to create a library file and in that file i want to have methodes that just send 'canned' messages to the lcd.· In order to get the library file to compile i had to create an instance of txUart.· The thing i am worried about is that i· have an instance of txUart opened in my primary program class.· will this cause a conflict or use unnecessary resources?

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-04-25 18:27
    Pass the uart instance you created to your library class via its constructor.

    //main class
    static Uart txUart = new Uart(...);

    static myLib lib = new myLib(txUart, ...);


    //your library class
    public class myLib {

    · private Uart tx;

    · public myLib(Uart tx, ...) {
    ··· this.tx = tx;
    ··· ...
    · }

    · //use tx.sendByte() in this library class
    }

    regards peter
Sign In or Register to comment.