Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Communicating with an USB Device

Communicating with an USB Device

Scheduled Pinned Locked Moved C#
tutorialquestion
21 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Dave Kreskowiak

    haolan wrote:

    So translated into code you are saying that I should do something like this when i read:

    Kind of, though there are async read methods that do all of this work for you and call you when there is some data to read.

    haolan wrote:

    The 10 bytes to read is because I know that the valid data always will be 10 characters long.

    That's not how you do it. Even though your return data may be 10 bytes, you can still get it in several small chunks in multiple reads. Your code has to be able to reassemble the data as it comes in so it can provide a completed message back to the code that's expecting a 10 byte message.

    A guide to posting questions on CodeProject[^]
    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
         2006, 2007

    H Offline
    H Offline
    haolan
    wrote on last edited by
    #21

    Ok.. I found this example at MSDN: public static void Read() { while (_continue) { try { string message = _serialPort.ReadLine(); Console.WriteLine(message); } catch (TimeoutException) { } } } And then you say I have to create a method that tries to parse the code, to check if it is a valid message, and if not, then it should run the read() again until the code can be parsed right?

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups