Reading serial data from a usb port

Discussion in 'Mac Programming' started by newConvert, Dec 6, 2006.

  1. newConvert macrumors regular

    Joined:
    Aug 25, 2006
    #1
    Hello,

    I want to write a widget that gets a stream of data from a usb port, which has originall come from a serial cable (via a serial to usb converter)... Does anyone know where i can get some java that'd do this? I've looked around and can't really find anything. Any help would be awsome!! Thanks.
     
  2. almightyshoe macrumors regular

    Joined:
    Jun 4, 2006
    Location:
    B-Town, India
    #2
    Maybe this doesn't apply to you, but I've been trying to use serial and parallel adapters with USB with NO luck. Supposedly there's some issue with the grounding that only makes it work with certain archaic systems. What data are you trying to stream? Maybe I can suggest an alternative.
     
  3. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #3
  4. newConvert thread starter macrumors regular

    Joined:
    Aug 25, 2006
    #4
    well, i have a temperature monitoring device, that can stream (current temp) data via a serial cable to a pc (or mac), so i need to get a usb adapter, than read it from there..... can you use C with widgets? i haven't looke dinto them much.
     
  5. Analog Kid macrumors 68040

    Analog Kid

    Joined:
    Mar 4, 2003
    #5
    They Keyspans are what we use at work. The drivers can be a little bit buggy, but they're stable enough if you don't do anything too unusual.

    If Java can read files in /dev, you should be able to access it. Trouble might come in when you want to change the baud rates and such, or send line breaks.
     
  6. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #6
    I believe you need to make a widget plugin to access anything but the 'net http://developer.apple.com/document...shboard_ProgTopics/Articles/WidgetPlugin.html in which case, C should work.

    Line breaks should be easy. It's just another character...

    ioctl calls might be more difficult from Java, but I don't know if there's other higher level routines... Seems like he'll need a plug in anyhow.

    B
     
  7. Analog Kid macrumors 68040

    Analog Kid

    Joined:
    Mar 4, 2003
    #7
    Really? Is there an ascii code that can't be sent because it's intercepted to generate a break, or is it some how outside the ascii set?

    I've always used tcsendbreak...
     
  8. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #8
    Ah, sorry isn't tcsendbreak a bit more related to flow control? It's still just sending data, just all zeroes with no start bits onr stop bits. :p

    B
     
  9. savar macrumors 68000

    savar

    Joined:
    Jun 6, 2003
    Location:
    District of Columbia
    #9
    There are a couple of issues.

    First, what converter are you using? Different converters have different levels of quality and feature sets, especially when it comes to the driver.

    At root, however, the drivers should create a virtual COM port (on Windows, that is) which can be treated just like a regular serial port -- assuming the drivers provide all the features for a regular serial port. Different brands vary significantly in quality.

    The second issue is that java (last time I checked) doesn't have serial port I/O built in. You'll need to download Sun's serial port I/O library: http://java.sun.com/products/javacomm/

    Once you get these two things figured out, the rest should be pretty easy.
     
  10. newConvert thread starter macrumors regular

    Joined:
    Aug 25, 2006
    #10
    no converter as of yet.... just trying to flesh out my idea a bit.... would it make a big difference dependingo n which serial->usb converter you used? IE would i have to write it for a specific converter?
     
  11. Analog Kid macrumors 68040

    Analog Kid

    Joined:
    Mar 4, 2003
    #11
    Line breaks aren't so much flow control as an interrupt. When a receiver notices the transmitter holding high for longer than a character period it responds according to some prearranged plan.
     
  12. Analog Kid macrumors 68040

    Analog Kid

    Joined:
    Mar 4, 2003
    #12
    As long as the converter is supported on OS X and installs itself as a serial device in /dev, then the interface should be consistent from device to device. Should be... In practice there are differences in how well different features are supported-- which is mostly a failure of the drivers.

    The beauty of the Unix model is that all serial devices should conform to the same interface-- I've easily used the same code to connect to USB/RS232 adapters and Bluetooth serial interfaces.
     

Share This Page