Thread: Need some suggestion to handle serial inputs.

  1. #1
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476

    Need some suggestion to handle serial inputs.

    Hi guys, I need some suggestion to handle the serial input. First I'll explain that the serial is attached to a device that consists of multiple buttons and will send a string representing each button upon pressing and will always send it with some intervals if it is still pressed. But if it was released, it doesn't send anything except only stop sending the string. Now because I needed it to behave similar like a keyboard event (with its key down / up), I need to find a way to handle this. I can only detect the key down event of the button but not the key up obviously. I've an idea actually. I was thinking of using a timeout state for each inputs. So if a button is pressed, I would have to get the time of the action and check whether or not the device is still sending a signal a few secs / milisecs later. But after much thinking, IMHO, that will make the input not as responsive because we need to wait for a few moments before we actually identify it as a key up. And what if the input is delayed because of something and I happen to call the onKeyUp before the input is received. So I'm asking if whether or net there's another way to do it or is it the only way? Thanks a lot in advance.
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    A timeout would be my solution too.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    Quote Originally Posted by matsp View Post
    A timeout would be my solution too.

    --
    Mats
    OIC. Thanks for the reply. I guess there's no helping it except with a timeout, right. BTW, I happen to find 2 kinds of methods to do the timeout. One is using the standard time.h call. The second one is by using QueryPerformanceCounter & QueryPErformanceFrequency. Which one should I use? What are the pros and cons between those 2? Thanks.
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by g4j31a5 View Post
    OIC. Thanks for the reply. I guess there's no helping it except with a timeout, right. BTW, I happen to find 2 kinds of methods to do the timeout. One is using the standard time.h call. The second one is by using QueryPerformanceCounter & QueryPErformanceFrequency. Which one should I use? What are the pros and cons between those 2? Thanks.
    I would have thought that you could actually use the read function itself with a timeout, if you set it up correctly for the serial port...

    Or you can use asynchronous (aka overlapped) I/O and use a timeout in the "wait for completion" on the async read.

    One of those would be my choice. Making your own timeout is definitely not the right thing.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    Quote Originally Posted by matsp View Post
    I would have thought that you could actually use the read function itself with a timeout, if you set it up correctly for the serial port...

    Or you can use asynchronous (aka overlapped) I/O and use a timeout in the "wait for completion" on the async read.

    One of those would be my choice. Making your own timeout is definitely not the right thing.

    --
    Mats
    Well, the device inputted different things. There are a few buttons on it. Each will send a different sequence of chars (i.e. button one will send "<1>", button 2 "<2>", etc). Also because I need it to be like a keyboard, there should be a case when there are multiple button go active at once. So with the read function timeout, I can't detect which one of the button is in a timeout and which one isn't.
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 04:02 PM
  3. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  4. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  5. Please help with serial communication problem - Long
    By spdylude in forum Windows Programming
    Replies: 3
    Last Post: 04-06-2005, 09:41 AM