Hello,
I want to incorporate the reading of a barcode scanner into a plugin. The barcode scanner is connected through a USB connection. In a standalone program, I can acquire the reading by public static void main(String[] args) throws Exception{ InputStream in = System.in; int b; while (true) { b = in.read(); if (b==-1) break; // do something... System.out.println((char)b); } } But when I code it in imageJ plugin, it doesn't work. Basically, imageJ gets completely stuck (Not responding). Any ideas how to solve it? Thanks in advance, Emilio |
Hi Emilio,
You're using System.in to read from a USB barcode scanner? Don't you need some kind of Java USB library like javax.usb (http://javax-usb.org/) or jUSB (http://jusb.sourceforge.net/)? There is no reason it shouldn't work pretty much the same from ImageJ as from your standalone program. I doubt System.in works out of the box in ImageJ, since ImageJ runs without a console and you would need to map some other means of input like a text area to standard input. But I would be surprised if you need to use standard input at all. -Curtis On Feb 6, 2008 5:58 PM, Emilio Miguelanez <[hidden email]> wrote: > Hello, > > I want to incorporate the reading of a barcode scanner into a plugin. The > barcode scanner is connected through a USB connection. > > In a standalone program, I can acquire the reading by > > public static void main(String[] args) throws Exception{ > InputStream in = System.in; > int b; > while (true) > { > b = in.read(); > if (b==-1) break; > // do something... > System.out.println((char)b); > } > > } > > But when I code it in imageJ plugin, it doesn't work. Basically, imageJ > gets > completely stuck (Not responding). > > Any ideas how to solve it? > > Thanks in advance, > > Emilio > |
Curtis,
Thanks for your input, and I'll try on it using jusb. However, I don't think I'll need an extra library. In the standalone application, the standard input (System.in) works perfectly. Within ImageJ, System.in does not work (as you pointed out), however if I open a Text box or even generic dialog with a user input, it reads perfectly from the barcode scanner, which it means that ImageJ gets the input from the usb port. But I still need to be able to read the data directly from the USB port (or maybe by scanning automatically the Text Box, and I do not know how) so I can manipulate the data without the user walking back to the computer to hit enter or click a button to tell the app its time to grab the data. Does it make sense to you? Cheers, Emilio On Thu, 2008-02-07 at 12:48 -0600, Curtis Rueden wrote: > Hi Emilio, > > You're using System.in to read from a USB barcode scanner? Don't you need > some kind of Java USB library like javax.usb (http://javax-usb.org/) or jUSB > (http://jusb.sourceforge.net/)? > > There is no reason it shouldn't work pretty much the same from ImageJ as > from your standalone program. I doubt System.in works out of the box in > ImageJ, since ImageJ runs without a console and you would need to map some > other means of input like a text area to standard input. But I would be > surprised if you need to use standard input at all. > > -Curtis > > On Feb 6, 2008 5:58 PM, Emilio Miguelanez <[hidden email]> wrote: > > > Hello, > > > > I want to incorporate the reading of a barcode scanner into a plugin. The > > barcode scanner is connected through a USB connection. > > > > In a standalone program, I can acquire the reading by > > > > public static void main(String[] args) throws Exception{ > > InputStream in = System.in; > > int b; > > while (true) > > { > > b = in.read(); > > if (b==-1) break; > > // do something... > > System.out.println((char)b); > > } > > > > } > > > > But when I code it in imageJ plugin, it doesn't work. Basically, imageJ > > gets > > completely stuck (Not responding). > > > > Any ideas how to solve it? > > > > Thanks in advance, > > > > Emilio > > Emilio Migueláñez Martín, PhD Research Associate Electrical, Electronic and Computing Engineering School of Engineering and Physical Sciences Heriot-Watt University Riccarton Edinburgh EH14 4AS t: +44 (0) 131 4513357 |
Hi,
On Fri, 8 Feb 2008, Emilio Miguelanez Martin wrote: > However, I don't think I'll need an extra library. In the standalone > application, the standard input (System.in) works perfectly. System.in is usually the channel that takes the keyboard input in the terminal. I fail to see how using System.in to read from a barcode scanner via USB could be correct, ever. So it appears to me as if your USB barcode scanner would generate keyboard events. But this has nothing to do with ImageJ: the events are transformed into keyboard events by the driver, long before any Java code could intercept it. Oh, and BTW A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? Hth, Dscho |
Johannes,
> System.in is usually the channel that takes the keyboard input in the > terminal. I fail to see how using System.in to read from a barcode > scanner via USB could be correct, ever. Well, I can tell that it works perfectly. The scanner connects to the computer using the USB, but my 'standalone' program can simply consider the input coming from Stdin. Once the program is running, the user doesn't have to hit enter or anything as long as the scanner flushes its buffer for each scan. > > So it appears to me as if your USB barcode scanner would generate keyboard > events. But this has nothing to do with ImageJ: the events are > transformed into keyboard events by the driver, long before any Java code > could intercept it. True, but ImageJ can intercept it. I am just looking for the complete automated solution without any intervention of the user. > > Oh, and BTW > > A: Because it messes up the order in which people normally read text. > Q: Why is top-posting such a bad thing? > A: Top-posting. > Q: What is the most annoying thing on usenet and in e-mail? Ups, sorry for the 'reverse' reading it may be cause to you Emilio -- Emilio Migueláñez Martín, PhD Research Associate Electrical, Electronic and Computing Engineering School of Engineering and Physical Sciences Heriot-Watt University Riccarton Edinburgh EH14 4AS t: +44 (0) 131 4513357 |
Hi,
On Sun, 10 Feb 2008, Emilio Miguelanez Martin wrote: > Johannes, > > > System.in is usually the channel that takes the keyboard input in the > > terminal. I fail to see how using System.in to read from a barcode > > scanner via USB could be correct, ever. > > Well, I can tell that it works perfectly. But you cannot tell why, evidently. ;-) The scanner driver translates the events into _keyboard_ events. So it makes _no difference_ for _any_ program if you _type in_ the numbers, or _scan in_ the barcode. The input will be _keyboard events_. So if you have a console program, you can read stdin. If you have a GUI program, you have to handle the keyboard events _differently_. The method addKeyListener() comes to mind. Hth, Dscho |
Hi Dscho, Emilio,
hmm, I do not agree that you should get keyboard events from the barcode scanner. See http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#in public static final InputStream System.in quote The "standard" input stream. This stream is already open and ready to supply input data. Typically this stream corresponds to keyboard input or another input source specified by the host environment or user. end_quote As far as I know, ImageJ itself does not change System.in, so I suspect that the ImageJ launcher (ImageJ.app on Mac, ImageJ.exe on the PC) somehow modifies it. On Windows, you might try to change "javaw" into "java" in the ImageJ.cfg file, maybe this helps. It will create a console (DOS-like) window in addition to ImageJ. Michael ________________________________________________________________ > Hi, > > On Sun, 10 Feb 2008, Emilio Miguelanez Martin wrote: > >> Johannes, >> >>> System.in is usually the channel that takes the keyboard input in >>> the >>> terminal. I fail to see how using System.in to read from a barcode >>> scanner via USB could be correct, ever. >> >> Well, I can tell that it works perfectly. > > But you cannot tell why, evidently. ;-) > > The scanner driver translates the events into _keyboard_ events. > So it > makes _no difference_ for _any_ program if you _type in_ the > numbers, or > _scan in_ the barcode. The input will be _keyboard events_. > > So if you have a console program, you can read stdin. If you have > a GUI > program, you have to handle the keyboard events _differently_. The > method > addKeyListener() comes to mind. > > Hth, > Dscho |
Hi,
On Mon, 11 Feb 2008, Michael Schmid wrote: > hmm, I do not agree that you should get keyboard events from the barcode > scanner. See > http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#in > > public static final InputStream System.in > quote > The "standard" input stream. This stream is already open and > ready to supply input data. Typically this stream corresponds > to keyboard input or another input source specified by the > host environment or user. > end_quote > > As far as I know, ImageJ itself does not change System.in, so I suspect > that the ImageJ launcher (ImageJ.app on Mac, ImageJ.exe on the PC) > somehow modifies it. On Windows, you might try to change "javaw" into > "java" in the ImageJ.cfg file, maybe this helps. It will create a > console (DOS-like) window in addition to ImageJ. ImageJ does not change System.in. The ImageJ launcher does not modify it. Changing javaw to java does not help it. The thing is: when one of ImageJ's windows is in the foreground, the original _console_ is not. Therefore, it does not receive keyboard input, but the foreground windows do. And since the console does not receive any keyboard input, System.in is silent, too. Hth, Dscho |
> ImageJ does not change System.in. The ImageJ launcher does not modify it.
> Changing javaw to java does not help it. > > The thing is: when one of ImageJ's windows is in the foreground, the > original _console_ is not. Therefore, it does not receive keyboard input, > but the foreground windows do. And since the console does not receive any > keyboard input, System.in is silent, too. And I agree with it, because with a text window (or dialog with user input box) open in the foreground, it receives the barcode scanned. My problem is how I can retrieve this barcode value without user intervention (i.e. not OKayed the dialog). One solution (hinted by Jeff Hanson) is to configure the scanner so it will send a return key after each reading, but I haven't managed to get the product manual yet. Cheers, Emilio -- Emilio Migueláñez Martín, PhD Research Associate Electrical, Electronic and Computing Engineering School of Engineering and Physical Sciences Heriot-Watt University Riccarton Edinburgh EH14 4AS t: +44 (0) 131 4513357 |
Hi,
I am testing another barcode scanner these days and I want to look for a fine barcode scanner whose way of processsing is simple and fast. It will be better if it offers free trials for users to check. Any suggestion will be appreciated. Thanks in advance. Best regards, Arron |
Free forum by Nabble | Edit this page |