Closed Thread
Results 1 to 2 of 2

Thread: Serial controller algorithm

  1. #1
    kenneth_888 is offline Newbie
    Join Date
    Sep 2007
    Posts
    6
    Rep Power
    0

    Serial controller algorithm

    hi all,
    i would like to implement a serial controller controlling 7 segment display to c++.
    Can anyone just give me an algorithm so i can apply it to c++ coding??i dont need the code just plain simple pseudo code will do.

    The controller decodes incoming hexadecimal encoded in ASCII text stream.Assume input stream is stored in an input buffer from where the command handler reads each character. Valid commands are stored in the command buffer and a command handler reads them and executes them thereby updating the current display. the command is: [$] [UP/DOWN?STOP]. the $ is the start character for each command, UP increments the output value, DOWN decrements the output value while STOP sets the output value to 0 if the output is below 5. the output range is from 0 to 9.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    kkelly's Avatar
    kkelly is offline Learning Programmer
    Join Date
    Sep 2007
    Posts
    50
    Rep Power
    0
    What you're describing is a grammar analyzer. A grammar analyzer consists of a parser and lexical analyzer.
    The Parser operates at a syntax level. The Lexical Analyzer operates at the buffer level. If you were reading a book, your brain would be the Parser and your eyes would be the Lexical Analyzer.
    So you are sitting there and decide to read a book. You get up and walk to your bookshelf and select a book called SerialDevice. You sit back down, open the book (the stream), turn to the first page, and prepare to read (instantiate your SerialContoller class, and pass it the stream).
    Now the logic gets a little more intricate. To make it simpler, lets pretend the book is just a sentence long. So we want to read the sentence. More specifically, we want read each word in the sentence. So our brain says, "Eyes, get the first word", and our eyes move through the sentence until they reach a space (or $), and returns, "This array of characters is the word you requested." Then our brain interprets the word by comparing it to all the cases (like in a switch statement) of words it knows. So if the word is UP, it calls the appropriate function. If it is PU, it might reply, "That doesn't make sense, scan it again eyes", or it might say, "Whatever. Get me the next word"
    So, thats the gist of it. Just remember only the Parser calls Lexical Analzer and only the Lexical Analyzer handles the buffer.
    The next step I may or may not be able to help with. So, with the grammar analyzer we can get valid commands. The question is, "Does this need to happen on a separate thread?" I'm not quite up to multithreading yet, but if it does need to be on another thread you would need to have the Parser call a public function of the command buffer object that will put the command in the buffer. Also, unless the command buffer processor is polling the command buffer, an event would have to notify the processor a command has been put in the queue. An event system is easy enough to create. But I'll wait for a response before I elaborate.
    If not, then you would still have the Parser call a public function of the command buffer, but you wouldn't raise an event. Practically, there is no need for a command buffer if the flow of execution is synchronous. However, if this is just "proof of concept", then the Parser could read in several commands, and execution could then be handed to the command buffer processor.
    Last edited by kkelly; 09-13-2007 at 10:31 AM.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Making code into Model View Controller format
    By rubbadrools in forum C# Programming
    Replies: 2
    Last Post: 02-11-2011, 04:56 AM
  2. General Serial Port
    By mebob in forum Assembly
    Replies: 11
    Last Post: 12-16-2010, 03:08 PM
  3. ps3 controller to mouse
    By imagiro in forum General Programming
    Replies: 3
    Last Post: 11-20-2010, 01:36 AM
  4. Game controller question
    By netfirecat in forum General Programming
    Replies: 4
    Last Post: 06-24-2010, 07:13 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts