Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newConvert

macrumors regular
Original poster
Aug 25, 2006
214
3
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.
 

almightyshoe

macrumors regular
Jun 4, 2006
118
0
B-Town, India
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.
 

newConvert

macrumors regular
Original poster
Aug 25, 2006
214
3
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.
 

Analog Kid

macrumors G3
Mar 4, 2003
9,351
12,588
I use a Keyspan USA-19HS with my DirecTivos though I haven't programmed for them. Keyspan provides sample C code on their website http://www.keyspan.com/downloads-files/developer/macosx/KesypanTestSerial.c, but I don't know how portable it is to Java.

Generally though the serial port is just treated as a byte stream in unix, so standard file routines should work...

B
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.
 

balamw

Moderator emeritus
Aug 16, 2005
19,365
979
New England
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.

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.

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.
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
 

Analog Kid

macrumors G3
Mar 4, 2003
9,351
12,588
Line breaks should be easy. It's just another character...

B
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...
 

balamw

Moderator emeritus
Aug 16, 2005
19,365
979
New England
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...

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
 

savar

macrumors 68000
Jun 6, 2003
1,950
0
District of Columbia
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.

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.
 

newConvert

macrumors regular
Original poster
Aug 25, 2006
214
3
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.

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?
 

Analog Kid

macrumors G3
Mar 4, 2003
9,351
12,588
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
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.
 

Analog Kid

macrumors G3
Mar 4, 2003
9,351
12,588
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?
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.