USB and serial port access in java

Hi
I have a magstripe card reader connected to my computer with a USB interface (port).
I am using javax.comm API to get the card swipe data but could not succeeded.
Can i do that or have to do something else ???

ok. Below is my code:
this is a sample code come with the API.
package msr;
* @author Dell
import java.io.*;
import java.util.*;
import javax.comm.*;
* Class declaration
* @author
* @version 1.8, 08/03/00
public class SimpleRead implements Runnable, SerialPortEventListener {
    static CommPortIdentifier portId;
    static Enumeration           portList;
    InputStream                inputStream;
    SerialPort                serialPort;
    Thread                readThread;
     * Method declaration
     * @param args
     * @see
    public static void main(String[] args) {
    boolean                portFound = false;
    String                defaultPort = "COM3";
     if (args.length > 0) {
         defaultPort = args[0];
     portList = CommPortIdentifier.getPortIdentifiers();
     while (portList.hasMoreElements()) {
         portId = (CommPortIdentifier) portList.nextElement();
         if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
          if (portId.getName().equals(defaultPort)) {
              System.out.println("Found port: "+defaultPort);
              portFound = true;
              SimpleRead reader = new SimpleRead();
     if (!portFound) {
         System.out.println("port " + defaultPort + " not found.");
     * Constructor declaration
     * @see
    public SimpleRead() {
     try {
         serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
     } catch (PortInUseException e) {}
     try {
         inputStream = serialPort.getInputStream();
     } catch (IOException e) {}
     try {
         serialPort.addEventListener(this);
     } catch (TooManyListenersException e) {}
     serialPort.notifyOnDataAvailable(true);
     try {
         serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
                            SerialPort.STOPBITS_1,
                            SerialPort.PARITY_NONE);
     } catch (UnsupportedCommOperationException e) {}
     readThread = new Thread(this);
     readThread.start();
     * Method declaration
     * @see
    public void run() {
     try {
         Thread.sleep(20000);
     } catch (InterruptedException e) {}
     * Method declaration
     * @param event
     * @see
    public void serialEvent(SerialPortEvent event) {
     switch (event.getEventType()) {
     case SerialPortEvent.BI:
     case SerialPortEvent.OE:
     case SerialPortEvent.FE:
     case SerialPortEvent.PE:
     case SerialPortEvent.CD:
     case SerialPortEvent.CTS:
     case SerialPortEvent.DSR:
     case SerialPortEvent.RI:
     case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
         break;
     case SerialPortEvent.DATA_AVAILABLE:
         byte[] readBuffer = new byte[20];
         try {
          while (inputStream.available() > 0) {
              int numBytes = inputStream.read(readBuffer);
          System.out.print(new String(readBuffer));
         } catch (IOException e) {}
         break;
}

Similar Messages

  • Java applets in a browser, and Serial port input

    I know that there is a special package for serial port input in java. (java.Comm.SerialPort)
    What I am trying to figure out before a final decision on design is made, is if there is anyway of reading serial port input into a java applet that is running inside of a browser.
    I have found lots of reference to Serial port input, but nothing that really goes in the direction that I am lookind for.
    Any little tid bits of information pertaining to this would be greatly appreciated.
    Cuervo

    You should also consider that applets are not allowed to access their client system's hardware without being signed; in other words, the user must agree (by clicking a button) to disable the applet security features. Why would you use an applet to do this? Applets are meant to be an extension of a website. You should use an application in this situation.

  • Low Level Serial Port Access

    This question has gone unanswered several times on this forum in the past but I thought I would try it once more.
    Is there any Java API that is in, or will work with J2ME to allow direct read and write to the serial port similar to the functionality that javax.comm provides for j2se.
    This would be useful for a project where a palmos device is used to communicate with equipment used to monitor industrial processes.

    Some MIDP 1.0 devices support access to the Serial
    Port.
    I have done it with Motorola i85, i50 (iDen) and
    Motorola T720i.
    I think 95cl also supports it. I'm ALSO having problems with serial port access on
    my T-Mobile Moto T720i phone. I've had MUCH success
    with the Nextel i85, i50, i95cl, etc phones, but the
    same code isn't running on the T720i.
    What do I need to do differently???
    Thanks,
    -Tim

  • Usb to Serial port adapter

    I have a gilsson usb to serial port bi directional adapter cable which uses the Prolific pl-2303 chipset. I am attempting to use this cable to interface a Mac Mini with a Harsper PDP plasma television.
    I am attempting to control the functions of the television via the serial port on the television. i.e. Turn on, input, volume, etc.
    What I need is software, or source code that would allow me to send hexidecimal commands to the television and receive the task completed codes.

    ZTerm will allow serial communications. Get it to ensure that throughput is happening as expected.
    RealBasic will allow you to roll your own with a fair amount of ease.
    A long time ago I used the above to communicate with my cellphone to send and receive text messages via the serial port, so I know it can work. Understanding the protocols is the difficult part...

  • Serial port access time slows in version 6 to 7 upgrade

    Hi - I am in the process of upgrading an project from LV 6 to LV
    7,  the serial port access works well in LV6 but after the
    upgrade, the serial port access is slow in LV if the application is
    compiled into an exe.  We are running Windows 2K on all machines
    and have installed the LV7.0 runtime engine on the PC that is running
    the executable.  If I run the application on a machine that has
    the full LV7.0 development  software on it, the executable runs
    just like it used to under LV6.0
    What am I forgetting??  The application is built into one exe that
    has all of the sub vi's included.  I have checked the box on the
    application builder that says included serial port support.
    Help! - We have 3000 PCBs sitting in manufacturing waiting to go to test until I solve this problem
    Thank you

    Hi
    I just recently finished a project in which I had to upgrade code from LV 6 to LV 7.1. After I did that the serial port actually worked but all the Fieldpoint devices that were connected to the system didn't work. The problem ultimately was the NI Fieldpoint Drivers. After I installed the newest drivers from NI everything worked perfectly. I don't know why your problem is occurring, but I wanted to reasure you that there isn't a problem with the serial ports when upgrading to LV7.1 (I don't know about LV7).BTW, I had LV6.1 development system installed on the computer, but didn't have the LV7.1 (All I had was an EXE file).
    So, try installing the newest drivers. Maybe that can help.
    Ami 

  • Mac Pro USB and FW800 ports not working

    I've been reading tons of forum entries in the Apple Support Community and in other forums.  Nothing seems to answer quite what's going on with my Mac Pro Tower.
    Here are the details and steps taken up to now:
    - I'm running a Mac Pro Tower (MacPro 3,1, 2x 2,8GHz Quad Core, Early 2008 model), currently running OS 10.6.8
    - I moved before the holidays in December and left my computer unplugged for over  month while away. Didn't have any issues before the move.
    - up until the last couple of weeks, I had actually been running on Leopard (yes, I'm a luddite!, please, no teasing )
    - I was trying to update my ipod touch's iOS and kept getting errors preventing it from completing the process. At first I thought it was an ipod app causing the issue after having read a few threads on that topic...
    - Also, on startup, the Mac started searching for a Bluetooth keyboard, of which I don't have, and would not detect my usb keyboard.  I would disconnect and reconnect the keyboard and the majority of the time, the Mac would then recognize my USB keyboard.
    - I decided to upgrade to Snow Leopard, which didn't help with the iPod update. I did not do a clean install.
    - Then I noticed that my USB stick wasn't working and tried it in all the usb ports (except the ones on the keyboard)
    - Also, I had removed and then reinstalled printer and scanner drivers for my All-in-one printer. After this I kept getting constant communication errors between the mac and the printer via the usb port, although I was able to print a test page.
    - I've used Hardware Test once which didn't detect any issue.
    - I reset the SMC
    - I reset the PRAM, and for a few seconds I was able to read from my USB stick, then never again, even after another PRAM reset.
    - I've cleaned the whole inside of the computer and checked for loose cables.  Cables are in so tight it's so hard to loosen them!
    - I now tested all the ports:
         ∞ the 2 front and 3 back USB ports are unresponsive to my usb key and to my VoyagerQ dock
         ∞ the front and back FW800 ports are unresponsive to my VoyagerQ dock
         ∞ However, the keyboard works in any fo the back ports and my USB stick is recorgnized by the USB port of the keyboard.
         ∞ I also plugged in my Logitech webcam into the keyboard and it works there but not in any other port.
         ∞ When I plug in USB powered speakers into any of the ports, they work fine
         ∞ And the FW400 ports are also working fine with my VoyagerQ dock
    - a few times, including once today, my mac restarted by itself.  The times before today, I thought it was because I was sort of moving back the computer in place, but today I was nowhere near the computer.
    So what does this all mean? Should I do a clean install of the Mac OS? Or is it a problem with my Logic Board?
    Any insight please would be helpful.  I had Apple Care and missed the reminder to renew it so I really hoping not to spend more money than necessary.

    Thanks Grant,
    The battery is a start and something inexpensive to replace.
    I did do a PRAM reset (command + option + P + R) and was able to hear the chime 4 times. I tried resetting it a number of times over the past week, as well as yesterday with no success in reviving the USB ports.  But isn't it weird that my USB powered speakers work by plugging them in any USB port (with the mini jack pugged in the back or front earphone plug)?
    I did not use the USB ports on the keyboard until yesterday, so that is not the cause of the other USB and FW800 ports failing. But I'll follow your suggestion and not use them except for the mouse.
    Another weird thing that happened yesterday, I have 16GB of RAM and I spent all day trying to troubleshoot a RAM issue that is magically fixed after leaving the computer on overnight to do an extended Hardware Test. The issue was:
    - Only 8 RAMS were being recognized
    - a red LED light appeared on the top riser
    - first I thought I had isolated the faulty RAM bar, and then a second one
    - Then going pair by pair again, I no longer saw the LED light
    - Put back all 8 bars, only 8 GB of RAM recognized
    - Left computer overnight running Hardware test (said it took almost 3 hours, with no errors)
    - Now all 16 GB are recognized!
    Thanks again for the tips

  • Usb to serial port converter in lenova g560

    hi this is madhan. i m using lenova g560 ideapad. there is no serial port in my laptop. For my project i need a serial port. i heard tat in market USB to serial port converters are available. Does Lenova g560 support this change?? If so is there any driver to make support to serial port?????????

    If you buy a Serial-USB interface/cable you won't have any problem. Usually this accesory comes with drivers. If you have Windows 7, mayte it will detect all automaticaly.
    Regards.
    IPnaSh
    First Spanish Community Guru - Colaborador ad honorem

  • What is wrong with my 30" Cinema Display?  The USB and FireWire ports still work, but the screen is pitch black. When you plug it into the computer, it detects that it's a Cinema Display.

    When you plug it into the computer, it detects that it's a Cinema HD but the screen is pitch black.
    For some reason, the USB and FireWire ports still work.

    If you shine a really bright light directly into the screen can you then see a faint image on the screen? If so, that would indicate the backlight has died (hardware failure) and the unit needs repairing.

  • How can collect the data from laptop sound card and serial port at the same time?

    I'm working on a project, I need to collect the data from laptop sound card, and also from serial port at the same time.
    The attachments are my VIs for sound card and serial port communication, I'm wondering that can I combine these two VIs together? Or can I run these two VI at the same time?
    Thank you!
    Attachments:
    AC_Radar_Receive.vi ‏46 KB
    RadarAudioPlug.vi ‏774 KB

    A smarter way is just to put all your code in the same VI.
    Two parallel loops if rates are different.
    Attachments:
    RadarAudioPlug.vi ‏450 KB

  • GPIB and serial port communication errors via an executalbe file.

    I have a data acquisition program that communicates with instruments via the serial port and GPIB bus. When I create an executable file and run it on another PC I get GPIB and serial port errors when the program tries to initialize these ports. Are there additional vi's I need to include when I build the executable?

    When you installed the GPIB board on the other pc, did you install just NI-GPIB? Did you configure the GPIB board? You also need NI-VISA if your're using VISA calls in your program. You can either install the full NI-VISA or just the run-time version.

  • Java and serial ports

    i want to be able to use java to access my serial port to
    remote dial other systems....

    Download javax.comm from the Sun website and use that.
    http://java.sun.com/products/javacomm/index.html
    Follow the install instructions VERY carefully .

  • Java enabled phones supporting serial port access

    Does anybody know a Java enabled mobile phone beside the Motorola iden family that supports access to the serial port ? As far as I can see there are no such phones on the market.

    simens sl45 and m50

  • Java and serial port communication

    Hello,
    In my code i have parsed a file through which i have extracted the port name and baud rate .
    Now i want to open the port with this portname and baud rate.
    I have a device moxa card which has 16 port and want to open each and and read and write data into it.
    thanking you.

    RXTX seems to be a decent library for serial/parallel communication using Java.
    [http://www.rxtx.org/]

  • Infrared / Serial ports access in MIDP for Palm

    Hello,
    Do you guys know if MIDP for Palm allows to connect to the IR / Serial ports ? If yes, any examples ?
    Thanks,
    Vadim.

    I'm very interested by your discussion, i have searched a lot of information about midp and the access to the serial port.
    The specifications of midp says that the comm protocol is not available in midp.
    The IBM J9 Java VM is supposed to be full midp implementation but only only for x86 processors. The lcdui package is not available with the J9 VM for palm. The lasts contact i have with ibm about this subject, they said that they will implement lcdui but they can't say when .... perhaps in 2002.
    I don't know any other Java VM witch have a full midp implementation ... Kada VM will be but i don't know when ...
    If you have any other information, i'm very interested
    Thanks by advance

  • Need faster serial port access

    I am using javacomm for serial port communication and the performance is too
    slow for my needs. I am comming with an embedded app from an NT machine
    with my java app. For benchmark purposes I hava VB app that can also talk
    to this embedded app. The round trip communication time for the VB app is
    20-30 milliseconds but the java app takes ~200 milliseconds. I think I could
    improve performance by writing to the serial port directly instead of going
    through the javacomm api which I think is slowing me down. Is it possible to
    to a low-level file open and write directly to the serial port? And if so, how?
    Thanks,
    Michael

    I am using javacomm for serial port communication and
    the performance is too
    slow for my needs. I am comming with an embedded app
    from an NT machine
    with my java app. For benchmark purposes I hava VB app
    that can also talk
    to this embedded app. The round trip communication
    time for the VB app is
    20-30 milliseconds but the java app takes ~200
    milliseconds. I think I could
    improve performance by writing to the serial port
    directly instead of going
    through the javacomm api which I think is slowing me
    down. Is it possible to
    to a low-level file open and write directly to the
    serial port? And if so, how?
    Thanks,
    MichaelSlowing down of communication process depends upon code content as well. if u can put ur code here, may be u can get some feedback concerned with speed.
    you can not directly talk at a serial level but make a component in say C n can use native methods to access that component. But that component would be very much comparable to Win32com.dll.There would be speed difference but that difference would not be enough to warrant 'too much'
    Jatin

Maybe you are looking for

  • How do I add a signature/watermark to my pictures without using Digimark?

    I want to add my name on my pictures but I don't need to track them or follow them. If someone edits my name out oh well. I just want it for when I put it on the internet or give it to my friends and family.

  • IPod can not be synced

    Like many others i'm having a **** of a time syncing my 2 iPods. 5th gen video and 2nd gen shuffle. They are both coming up with the same errors when trying to manually sync. The ipod "xxx" cannot be synced. The disk could not be read from or written

  • ITunes library not available upon iMac sleep

    I have an Intel Core Duo v10.4.8. My iTunes music is on here and I share it on my local network through AirPort Express. When my iMac goes to sleep the sharing is not available on the other computers and I must wake it to continue. I have the compute

  • How can I prevent my Trash Mailbox from automatically deleting?

    I keep changing the settings for the Trash mailbox to ERASE DELETED MESSAGES: NEVER but it continuously defaults back to ONE WEEK OLD. Please tell me how I can prevent it from defaulting back so it maintains the NEVER setting. Thank you. ([email prot

  • Iphone shows up in windows but not in itunes

    I have an Iphone 4s and windows 7 64 bit. I knew there were troubles with win7 and itunes so I waited to try to sync. Today I was told that a new version of itunes was out and I could sync my phone now. Installed itunes 10.5.2.11 and my iphone shows