Thread: How To Stream Data From A USB (Com Port) Win32

  1. #1
    Registered User
    Join Date
    Jan 2014
    Posts
    139

    How To Stream Data From A USB (Com Port) Win32

    Can someone please show me an example of how to stream data from a usb device (through com port)? I saw some managed examples that wont help much in a win32 and a few examples that did not work. Thanks in advance

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    what are you trying to do exactly? capture usb traffic? I think they make data loggers for that. I think trying to do it in real time with a serial port is a waste of time, because even the slowest usb port is ~100 times faster than the fastest typical serial port.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Registered User
    Join Date
    Jan 2014
    Posts
    139
    I bought a usb GPS and there is serial data coming from it (com3). How do I extract the information from it?

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Exactly the same as a regular COM port. Post some code and error messages if that doesn't work.

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Here is my awesome serial I/O class for all to enjoy:

    Code:
    #include "Win32Serial.h"
    
    #include <iostream>
    #include <iomanip>
    #include <cctype>
    using namespace std;
    
    using namespace Win32Serial;
     
    int main()
    {
        CWin32Serial com3;
    
        if (!com3.Open(3, CBR_115200, 'N', 8, 1, FC_Disabled))
        {
            cerr << "Failed to open COM3, ec = " << GetLastError() << endl;
            return 1;
        }//if
    
        BYTE b;
        while (com3.ReadByte(b))
        {
            int c = (unsigned)b;
    
            if (c == '\r' || c == '\n')
                cout << endl;
            else if (!isprint(c))
                cout << "." << flush;
            else
                cout << (char)c << flush;
        }//while
    
        return 0;
    }//main
    gg
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Codeplug View Post
    Code:
    if (!com3.Open(3, CBR_115200, 'N', 8, 1, FC_Disabled))
    may I suggest that, instead of passing a literal 'N' character for the parity bit, why not define an enum with PARITY_NONE, PARITY_EVEN, and PARITY_ODD values? I think it would make the code more clear.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Terminate a data stream
    By kim15 in forum C Programming
    Replies: 6
    Last Post: 01-28-2013, 04:07 PM
  2. sending streams over serial port in win32
    By deian in forum C Programming
    Replies: 2
    Last Post: 07-13-2009, 12:01 PM
  3. Data structure for storing serial port data in firmware
    By james457 in forum C Programming
    Replies: 4
    Last Post: 06-15-2009, 09:28 AM
  4. com port, graphing, win32
    By The Exodus in forum Windows Programming
    Replies: 7
    Last Post: 07-28-2003, 09:55 PM
  5. pipe stream data I/O
    By vector7 in forum Linux Programming
    Replies: 1
    Last Post: 03-11-2003, 06:46 PM