Serial port mouse

back to my expirement:
i try to take signal from serial mouse by the following class but i have a NullPointerException :
   import javax.comm.*;
import java.io.*;
import java.util.*;
public class ComControl implements Runnable, SerialPortEventListener  {
    static CommPortIdentifier portId1;
    static CommPortIdentifier portId2;
    InputStream inputStream;
    OutputStream outputStream;
    SerialPort serialPort1, serialPort2;
    Thread readThread;
    protected String divertCode = "10";
    static String TimeStamp;
public static void main(String[] args) throws UnsupportedCommOperationException {
        try {
          portId1 = CommPortIdentifier.getPortIdentifier("COM1");
          //portId2 = CommPortIdentifier.getPortIdentifier("COM1");
          ComControl reader = new ComControl();
    catch
      (Exception e) {
      TimeStamp = new java.util.Date().toString();
      System.out.println(TimeStamp + ": aaa " + portId1);
     // System.out.println(TimeStamp + ": COM5 " + portId2);
      System.out.println(TimeStamp + ": msg1 - " + e);
public ComControl() {
        try {
            TimeStamp = new java.util.Date().toString();
            serialPort1 = (SerialPort) portId1.open("ComControl", 2000);
            System.out.println(TimeStamp + ": " + portId1.getName() + " opened for scanner input");
           // serialPort2 = (SerialPort) portId2.open("ComControl", 2000);
            //System.out.println(TimeStamp + ": " + portId2.getName() + " opened for diverter output");
        } catch (PortInUseException e) {}
        try {
            inputStream = serialPort1.getInputStream();
        } catch (IOException e) {}
        try {
            serialPort1.addEventListener(this);
        } catch (TooManyListenersException e) {}
        serialPort1.notifyOnDataAvailable(true);
        try {
            serialPort1.setSerialPortParams(9600,
                SerialPort.DATABITS_8,
                SerialPort.STOPBITS_1,
                SerialPort.PARITY_NONE);
            serialPort1.setDTR(false);
            serialPort1.setRTS(false);
          /*  serialPort2.setSerialPortParams(9600,
                SerialPort.DATABITS_7,
                SerialPort.STOPBITS_1,
                SerialPort.PARITY_EVEN);*/
        } catch (UnsupportedCommOperationException e) {}
        readThread = new Thread(this);
        readThread.start();
public void run() {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {}
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:
            StringBuffer readBuffer = new StringBuffer();
            int c;
            try {
                  System.out.println("aaaaa"+inputStream.read());
                while ((c=inputStream.read()) != 10){
                   if(c!=13)  readBuffer.append((char) c);
                 String scannedInput = readBuffer.toString();
                 TimeStamp = new java.util.Date().toString();
                 System.out.println(TimeStamp + ": scanned input received:" + scannedInput);
                 inputStream.close();
                 if(scannedInput.substring(0,1).equals("F")){
                   outputStream = serialPort1.getOutputStream();
                   outputStream.write(divertCode.getBytes());
                   System.out.println(TimeStamp + ": diverter fired");
                   outputStream.close();
                   } else {
                   System.out.println(TimeStamp + ": diverter not diverted");}
            } catch (IOException e) {}
            break;
}   

Could you post a stacktrace or atleast on which line you are getting this nullpointerexception?

Similar Messages

  • Using a PS/2 keyboard on a Sparc workstation through the serial port

    We have recently migrated an application that used to run on a PC, to now run on a Sparc Workstation. This is a SunBlade 1500, running Solaris 8. The application is running in a dedicated console which has a fitted keyboard and trackerball that have PS/2 connectors and cannot be changed.
    We need a way of connecting the PS/2 keyboards to the serial ports of the Sparc workstation. We already have a piece of software that will read ascii values from the serial port so we definately want to go through the serial ports.
    Can someone please suggest what converters will be required to get the output of the keyboard and trackerball as ascii input to the serial port.

    Actually, that's not a bit perverse, at all.
    Jonathan's suggestion is a standard method of connecting to a server.
    (null cable between the computer serial ports)
    ... see the Solaris man pages.
    man tip
    TeraTerm and Hyperterminal are customarily used on a PC running some dialect of Windows.
    The 'tip' command is all that's necessary between Solaris systems.
    PS/2 is not a serial connection, but is a keyboard/mouse interface 'invented' by IBM when they offered their XT-class PS/2 line of desktop systems, back in the 1980's.
    I found this next link by using Google:
    http://members.chello.at/theodor.lauppert/computer/ps2/
    The smaller DIN ports were more compact than the AT-class keyboard ports and the mouse moved from a serial port to a dedicated mouse port.
    Serial communication devices are not keyboards, per se,
    and keyboards are not serial communication devices.
    You need other hardware in between to translate what the human being sends, and another computer is a common method to accomplish that translation.
    Having said all that ...
    Since you cannot change the dedicated console hardware,
    I suggest you go to the manufacturer of that console equipment
    and have them suggest some sort of serial-to-serial interface lash-up.

  • Msi 5124 serial port com1 com2

    i have a mainboard msi 5124 and want to use the serial port (COM1) for connecting a standard serial mouse. however i cannot get the mouse to work nor even be detected. not under dos nor under win98.
    before i used a ps/2 mouse, and never a serial mouse.
    most likely the pin-connections are not correct.
    can someone please give me a layout of the pins of the COM1 and COM2 port on the mainboard? on the msi homepage the manual is just 6 pages - which do not cover this information
    thank you,
    PS: the keyboard i am using is still ps/2 and is working fine.

    YOU CAN USE ACTIVEX COM CONTROLS IN YOUR FORM.

  • Computer freezes while reading from serial port

    My computer freezes when i tried to read from a serial port for a longer period of time such as 10 hours. I always close the serial port after reading. please, help me solve this problem

    I too experienced a similar problem twice on my machine and I have no idea how to stop it because it is so intermittent and I cannot replicate it.
    Perhaps I can offer some clues.
    The Labview screen cannot be stopped and some parts of Windows appears frozen. Oddly enough I can switch to the block diagram but thats about all I can do. The LV stop button will indicate a mouse click on it but the VI does not stop. iT also cannot be closed.
    Even the reset button and power button on the PC does not work. I am forced to power down the PC (pull the plug) to get back control.
    I believe it is related to a visa call to my serial Balance.
    ANyway no solution but hopefully some clues.
    Dell Optiplex GX260 w/ 500MB RAM
    Win2K 500.2195 w service pak 4,
    NI
    serial Hardware and NI serial ver1.45 (16 com ports)
    Labview 6.1 and 7

  • ADB or Serial ports

    my bro has a PowerBook G3 233 running on Jaguar. I'm trying to use a mouse and a printer that plugs into the ADB/Serial ports but the machine doesn't seem to detect it. Does OS X support these ancient ports??

    Josh,
    Sorry for the delayed reply...
    Apple introduced USB 2.0 drivers in OSX 10.2.8 but they have problems with USB 2.0 PC cards that do not have the NEC-based USB2 chipset. Usually the symptoms are printers not working, USB HDs not transferring data or freezing up, etc; low-demand devices like a USB mouse seem to work OK, though.
    Your options might be these:
    1. Find an inexpensive used USB 1.1 PC card; these still work fine but of course only run at the slowere 1.1 speeds.
    2. Buy a USB 2.0 PC card that uses the NEC-based chipset; unfortunately I know of only two because most manufacturers do not advertise this data. Here are two such cards:
    http://www.ratocsystems.com/english/products/subpages/cbu2.html
    http://www.macally.com/spec/usb/connecting_device/uh2226.html
    3. Download the Mac OS X 10.2.5 or 10.2.6 Update > extract the 'IOUSBFamily.kext' extension using Pacifist (VersionTracker) and replacing the 10.2.8 version with the one from 10.2.5 or 10.2.6. You can then buy any USB 2.0 PC card and have it work without issue, but of course it will only run at the slower 1.1 speeds.

  • Unable to capture data from Serial port using LVRT2010 in single core pentium 4 machine

    I am using application written in Labview using windows Labview
    Runtime environment 2010. Application creates a tunnel to intercept data from
    Serial port.
    My problem is, Currently, I am using single core Pentium
    processor. When I am trying to intercept the data between COM1 and COM7 (COM 7
    is a virtual port) it is not able to capture data.
    When I am running Labview RT environment using dual core
    processor machine it is running normally. I wonder whether it could be the compatibility issues with
    single core Pentium processor.

    Hi Magnetica
    Are both of the machines running the same runtime engine,
    drivers ect?
    Have you had RT applications running on this
    machine before?
    Is the development computer a 64bit machine?
    The processor is a supported model (See link below).
    http://zone.ni.com/devzone/cda/tut/p/id/8239
    Regards
    Robert
    National Instruments UK & Ireland

  • Problem on WinXP / Labview 6.1 with VISA (serial port)

    There is a problem on WinXP / Labview 6.1 with VISA which i use to poll the state lines of the serial port. The only functions that i use are "VISA Open", "Find Resource", line state properties and "VISA close".
    On my own machine (WinME) it works fine as a standalone application (with runtime engine in the same direction), even if i rename the Labview directory so that Labview is not found.
    From my VXIpnp directory i deleted all but these files:
    directory "Win95",
    subdirectory "Bin" containing "NiViAsrl.dll",
    subdirectory "NIvisa" containing "visaconf.dll".
    When shipping this to WinXP (and copying "VXIpnp" to the root directory), the serial port was not found, so i renamed the direction "Win95" to "
    WinNT", but this did not work also.
    I installed the VISA server, although it seems not to be required -- no result.
    Final question:
    What must i do for distributing the program as a standalone application for all windows platforms?

    Hey Joachim,
    In order to create an installer that includes the VISA Run-time engine for serial IO you will have to purchase LabVIEW 7.x. See screen shot. This packages a small compact version of the run-time that can only be used for serial, but it takes up much less space. The installer that I created has my application, the LV Run-time, and the VISA run-time and it is about 26 MB.
    That is much smaller than if I had to include the 32 MB LV 7.1 run-time and the 14 MB VISA run-time separately. It would have been even smaller if I would have uncheck some of the items that I wasn't using.
    -Josh
    Attachments:
    advanced.JPG ‏31 KB

  • Using a serial port under j9.. How?

    I am trying out j9 on an ipaq. I am trying to get javax.comm to work.
    When I call CommPortIdentifier.getIdentifiers ();
    I get java.lang.string.NoSuchMethodError: java/lang/String.<init>([BIII)V
    It would appear that the javax.comm package was implemented using a now deprecated String method, and that IBM has chosen not to implement deprecated methods in it's j9 vm (I get the same issue trying to run swing.)
    One would think that what is needed is an updated javax.comm package. However, there doesn't appear to be a javax.comm package on Sun's site, let alone an updated one. Whats going on here? Can someone give me an idea of how Sun and/or the JCP thinks about developers who want to use serial ports?
    Is there a workaround? A different way of talking to a serial port? Or should I abandon j9? I should add that I got my software running just fine on nsi.com's creme vm (javax.comm and swing too) and it worked without any hassles. It even understands jar files (is there a reason why IBM insists on having a link file?). However, the reason I persevered was that a) j9 is cheaper and more importantly b) nsi.com don't seem terribly keen on actually selling their product. I have lots of references to them selling their vm in bundles of 40 ($1000) which is a bit ouchy but hey I'm not paying for it. But, you'd think the nsi.com people would actually confirm this on their site?
    So.. can it be done? And why, in the world of embedded systems (my field) and now lots of phones and pdas, is so little attention given to the humble serial port? It doesn't matter how fancy the protocol is, underneath it all is a UART. grumble
    -Russel

    Hi Russel,
    I will probably soon be in the position you are in trying to get this to work. I found the following page which offers some promise.
    http://www.intrinsyc.com/support/I-Linux/405-cube/misc/smf_serial_port_access_example.htm
    Mike

  • I have problem with delay in serial port

    I have problem with serial port. I have connected two computers by serial port and I need to create program in Labview for transfer strings using start bits and stop bits. My problem is that my program is working quite well ...when I press start bit it starts to concatenate strings and if i press stop bits it stops...this is the purpose of this program...but problem is that it working only with delay...and need that this program dont need delay, because it can only concatenating data depends on delay from start bit....I wana solved problem with delay...I dont want using delay process in my program, but allways when I try to delete this delay it stop works correct
    here is my program

    Ok this should be simple - if I understand you correctly.
    You have the VISA session initialized with read termination character enabled.  So reading the number of bytes at port is NOT the correct way to read from the port.  Set the read number of bytes to something large (say 4096) and the read will return as soon as a termination character is received (or timeout).
    You'll need to make sure the sending device is configured to send termination character on writes (you can set that with a VISA property node)  and that you are sending the correct termination character.  The default is 0x0A (newline).
    Jeff

  • Open and configure serial port

    Hi,
    when i use the function configured serial port, i can work with it.
    for which case i need the function open port. do i need both an in which order?
    thanks florian 

    Hi florian
    check the help examples
    Attached png file shows  the example.
    chow
    xseadog
    Attachments:
    serial.PNG ‏39 KB

  • How do I process serial port strings as bits

    In response to my commands, my instrument is sending bytes to my serial
    port. In one instance, 2 bytes are received. I want to treat these 2 bytes
    as a group of 16 bits.
    The VISA and Compatibility Serial functions return these bytes from the
    serial port to Labview clearly labelled a "string".
    Everything I can find in the way of Labview functions and .vis don't want to
    do bit twiddling, bit swapping, and bit dropping, with "string" data.
    I thought "hex string to number" could be used here, but I can't find a way.
    The 2 Bytes in question can be represented as hex, but the data are not the
    ASCII codes for the hex representation of a binary number, they are the
    binary number. This "hex string to number" seems to want ASCII c
    odes.
    You can feed a hex number typed into a "control" box wired into "hex string
    to number" and you get a meaningful number. You can feed the 2 bytes from
    the serial port into an "indicator" set to read in hex and you get a hex
    number that is a correct representation. But that is Labview handing them
    around to itself. I need to get my "hands" on them.
    I can't feed those same bytes that show up as a correct hex representation
    in an indicator into the "hex string to number" or anything else, so far,
    and get a number that is useful for further processing.
    I thought "variant to data", but I can't find enough reference material to
    understand how to use it. A boolean array seems like a bit of a weird
    approach, so I thought I'd ask before I looked into that.
    I'm used to dealing directly with binary numbers on the processor stack, I
    call them whatever I want, and turn them into anything I feel like.
    I'm sure I'm staring the solution in the face, but I can't find any way to
    persuade
    Labview to treat this "string" data as 16 bits.
    I've got the 16 bits, which is better than not having them, but I don't have
    much hair left.

    duh, well I finally discovered the "Unflatten from String" function. A guy
    just feeds in the bytes he's collected from his serial port that Labview
    thinks are a "string", and out come lovely little unsigned 16 bit numbers,
    or whatever other type of number he wants to turn the bytes into. And there
    are great little bit twiddlers available after that, like "swap bytes", and
    you can mask out bits with the logic operators, why this is fun. There's
    nothing like being a moron...... fly me to the moon...................
    "David Lewis" wrote in message
    news:[email protected]..
    > The two bytes would come from a serial port read.vi in Labview, classed as
    a
    > string. For instance, D3 and 02. The output wou
    ld swap the two bytes,
    i.e.
    > to 02 and D3, consider the two swapped bytes as 16 bits, drop the six most
    > significant bits, and output the ten bits that are left as an integer
    > classed by Labview as some kind of number, not a string.
    >
    > Your example StringToBits_Converter.vi I found on the ni.com site
    > unfortunately gives an error message and refuses to open on my system
    saying
    > it comes from a newer version of Labview 6 than I am running. Mine says
    > 6.0.1b3. Thank you very much anyway.
    >
    > "FightOnSCTrojan" wrote in message
    > news:[email protected]..
    > > In another words, you want to create a VI in which the input is 2
    > > strings (i.e. AB) and the output is the converted array bits (e.g.
    > > 1010101010101010)?
    >
    >

  • KM2M serial port not working in Linux

    I noticed a few Linux postings so I thought I'd give this a shot. I'm running Fedora Core and for some strange reason I can't seem to send any communications out to the ttyS0 (COM 1) or ttyS1 (COM 2) ports.
    Does anyone have any suggestions on making it work?
    Thank you.

    No, your code had no termination characters at all - automatic or not. The enable termination character for the VISA Configure Serial Port is only for reads. Just like the help explains.
    And while you should check the download page for updates, LabVIEW comes with the 34401 driver.
    Message Edited by Dennis Knutson on 12-19-2009 05:49 PM

  • Problem in using serial port.

    I am using serial port to get data from a fusion splicer. The number of bytes at the port is 4096 but the read buffer of VISA read is empty. I am reading the same number of bytes. Can any one tell me what is the maximum size of VISA Read buffer? I am trying to put the contents of the buffer in a file. I am using labVIEW 6.1 on linux.I am also attaching the VI.
    I also noticed this problem...If I read the number of bytes in the serial buffer many times, sometimes it reads it as 0 and I have to keep trying until it reads this 4096 bytes.
    Thanx for any help.
    S.Vijayalakshmi
    Attachments:
    serail_comm.vi ‏52 KB

    Hey Viji,
    In your application it looks like you are just checking to see how many bytes are at the serial port. Is it possible that your application is check for the serial data at the port before the data actually gets there. If you are looping this code as a subVI or just running it over and over it is possible that one of the iterations could occur faster than your device can write the information to the bus. In this instance you are checking the number of bytes at the port and there might not be any there yet. In this case the port reads 0 as you have designed it.
    If you want the read function to wait and always read 4096 then don't wire the bytes at port to the read function. Just wire a constant/control equal to 4096 to the read function instead o
    f the bytes at port. In this case, if there are not any bytes at the port the read function will wait for the bytes to show up or until the timeout period is reached.
    I would also, suggest lowering your time to something more reasonable, because if your instrument quits transmitting your application is going to wait for 33 minutes. That is a long time for a program to hang.
    I hope this helps out.
    JoshuaP
    National Instruments

  • "Example on reading combined signals from a serial port and separating them for display purposes". I am a beginner in Labview and would appreciate if anyone help with that

    I am working on a wireless vital sign monitor. I have 3 signals; heart rate and temperature. I filter and amplify the signals before converting them into digital form. I then pass them via MAX232 before passing them to RS232 serial cable.
    I am therefore working on a program to receive the combined signal and separate them.
    I have come across serial read and write examples on ni.com but am looking for one where I can actually separate combined signals and display them separately.

    Reading the serial port will give you a string. How you divide the channels depends on how the data was formatted before it was sent over the serial channel.
    If you are designing the instrument, as it seems from your query, then you can set up any form you wish. If your data is always floating point numeric, you could use space or tab characters to separate data words. You could use and XML format. If the instrument is provided by a vendor, contact them for the protocol.
    If tabs are used between words and returns between sets of readings, the resutlant string can be interpretted by the Spreadsheet String to Array function in LV.
    Things to avoid are characters often used by serial communications systems as control characters. Carraige returns are
    often used as command terminators by serial protocols, but may also be used by the port.
    Lynn

  • Help with reading information coming from a software into LabVIEW through Serial port

    Hi,
    I am new to LabVIEW and also an amateur in using RS232 for communication. I have this software that has these icons like speed increase/decrease, elevation up/down, start/stop. Now, when I click these buttons on the software, they perform the appropriate functions. For example, if I press start button, the signal must go through a serial COM port into LabVIEW to start the machine. How do I do that? How do I find what format the code word is when I press a button on the software? And how to decode the information to read whether the button pushed is start etc...? Any help would be appreciated.

    I may not be perfect, but I'm all I got!

    That information would be in the programming manual for the device you're controlling. Unless you have a device that has no documentation or you cannot get the documentation that's the first place you should look. If you cannot get the documentation at all then you've got some reverse-engineering to do. To do this you will either need a serial port sniffer (a hardware device), or you can try to use a software-based port capturing program. On Windows PortMon is the most prevalent. This will show you how the port was configured (baud rate, stop bits, etc). Warning: the information is technical.
    As far as how to get it running in LabVIEW, you should take a look at the serial port communication examples that ship with LabVIEW. The most problems occur in figuring out how to (a) terminate a write command, and (b) determining when to stop reading. For (a) this is typically done by appending a carriage return or linefeed to the command. This is device dependent. For (b) this is usually done by the byte stream ending with a character like a linefeed. Again, this is device-dependent. 
    You may also want to peruse this KB article: Serial Instrument Control Tutorial. There are also lots of tutorial on the internet for basic tutorials on serial port communication.

Maybe you are looking for