How to detect if my external device is connected to the Serial port

Hi,
If I remove the cable from the serial port in my pc or either remove the serial cable from my external device, then when I send a request to open the serial port from my program, it basically does nothing, it just sits there.
I want to be able to show some sort of message or any other way of indicating to the user that they should check the cable.
below is the bit of code to open and set serial port params:
     public void openPort() {
          // Initialise the drivers
          System.setSecurityManager(null);
          String driverName = "com.sun.comm.Win32Driver";
          try {
               CommDriver commdriver = (CommDriver) Class.forName(driverName)
                         .newInstance();
               commdriver.initialize();
          } catch (Exception e2) {
               e2.printStackTrace();
          // port will be set in Store Operations.
          String wantedPortName = Configuration
                    .getParameter(ConfigSetting.EFT_COM_PORT);
          //System.out.println("wantedPortname : " + wantedPortName);
          Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();
          CommPortIdentifier portId = null; // will be set if port found
          while (portIdentifiers.hasMoreElements()) {
               System.out.println("counter");
               CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers
                         .nextElement();
               System.out.println(pid.getName());
               if (pid.getPortType() == CommPortIdentifier.PORT_SERIAL
                         && pid.getName().equals(wantedPortName)) {
                    portId = pid;
                    System.out.println("found a macth");
                    break;
          } // end of while
          if (portId == null) {
               System.err.println("Could not find serial port " + wantedPortName);
               //System.exit(1);
          try {
               port = (SerialPort) portId.open("EFTDriver", // Name of the
                                                                           // application
                                                                           // asking for the
                                                                           // port
                         10000 // Wait max. 10 sec. to acquire port
          } catch (PortInUseException e) {
               e.printStackTrace();
               System.err.println("Port already in use: " + e);
               //System.exit(1);
          // Now we are granted exclusive access to the particular serial
          // port. We can configure it and obtain input and output streams.
          try {
                    port.setSerialPortParams(9600, SerialPort.DATABITS_8,
                         SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
          } catch (UnsupportedCommOperationException usc) {
               System.err.println("Unsupported operation" + usc);
          }Please advise what method can I use for this purpose.
Thanks
Abhi

You mean it hangs in the open() method despite the timeout?

Similar Messages

  • How can I control a HP 33120A waveform generator with the serial port of my PC?

    Hello,
    I want to control a HP 33120A waveform generator with my PC using the serial port. I don't have any idea about how to do it. If you've done it or if you know how I can do it, please give me some indications.
    Thanks
    Jean-Baptiste Paillet
    PS: I don`t have G PIB port

    The answer to your cross-post in the LabVIEW General group seems to be right on the money:
    http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=50650000000800000032200000&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0
    Regards,
    John Lum
    National Instruments

  • Is it possible for an external device to burn out the USB port?

    I think the available current of the USB port is 500 mA. If a USB device can work with a current of 500mA ~ 600mA, is it possible for it to burn out the USB port with 600mA current (larger than the safe 500mA) when connected? Or the port can never provide a current larger than 500mA?
    Thank you.
    P.S. The USB device I worry about is a pair of USB warm slipper (to be worn on feet in cold winter). Its label reads "5V / 2.5W", which should be safe. But I once connected it and a mouse to a USB hub, then to a single MBP USB port, and the mouse stopped working in a few seconds, and came back normal only after I switched it to another port. Now the slipper is connected to a port by itself, but I am just afraid that the USB slipper can go malfunctioning all of a sudden and drain a lot of current to burn the USB port.

    ...But I once connected it and a mouse to a USB hub, then to a single MBP USB port, and the mouse stopped working in a few seconds, and came back normal only after I switched it to another port....
    Likely the hub is only barely able to handle the 500mA requirement.  Many powered USB hubs have "cheap" power adapters and can't handle any high surge situations.  Many devices like heating elements and motors have "surge currents" where the initial powering on of the device has a much larger current flow than during normal usage.  Think of it like riding a bicycle.  You have to push hard on the pedals to start off, but it's easier to pedal after the bike is moving.
    ...Now the slipper is connected to a port by itself...
    If you mean the device is plugged into the Mac's USB port, then you should know that all Macs for the past few years provide more than the 500mA minimum for USB.  Some other computers also provide higher power.  But most USB hubs I've seen were limited to 500mA.
    If you are plugged into the hub, not the Mac, then the power adapter for your hub may be barely adequate or possibly even defective.
    ...but I am just afraid that the USB slipper can go malfunctioning all of a sudden and drain a lot of current to burn the USB port.
    IMHO, I would stop using the heater with any computer USB port.  There is always the possibility that eventually something could short out in the heating element and cause a catestrophic surge through the USB port.  The electronics in computers are quite delicate and I'd be paranoid about the device damaging my computer.  (BTW, I have an electrical engineering background so I'm paranoid about power issues all the time anyway. )  Even if the heater is plugged into a hub, the surge current could damage the other devices plugged into the hub.  While not as catastrophic as a dead computer, I'd still be irked to have to replace my mouse, digital camera, printer, webcam, etc.
    Instead, I recommend plugging the heater into it's own "power adapter."  One of those that give a USB port to charge a cellphone or whatever.  Plug the power adapter into a power strip.  Place the power strip in the floor next to the slippers.  That way you can conviniently turn the strip on and off with your toes as you're putting on your slippers.

  • How do i fix i a loose phone connection on the phone port end of things?

    My iphone port connection is loose. I found this out by playing music in the car. If i hit a bump the system will not read the information.

    russ1162 wrote:
    where can i get cheap iphone or ipod on the net >? Plus do you mean all the iproducts on ebay are stolden?
    I would not know any.  I know that I do not bother with eBay or such places for electronics and other devices.  These very forums are full of posts from people who bought used online only to receive a hacked device that then failed to work, or recently the big problem is iOS Activation Lock keeping them from using their iOS device and resellers who either refuse to respond when contacted, or try to extort even more money to get Actvation Lock removed.
    If you want a reliable device, then buy from a trustworthy source.  I have not used eBay in years - just completely lost faith in it for anything a long time ago now.

  • How can I autoindexi​ng data from vi that read the serial port (CODE)

    Hello. I´m working in a proyect in the company, the proyect consist in read two incremental encoders for the inspection of automotors supension. I have a Digital Read Out System that read the 2 linear encoders, the DRO it has a serial RS-232 interface, i can read the data from the DRO to my computer, but now, I want to storage the information in Arrays (for autoindexing) for then make a graphic, If you want check the program, and if you tell me information, or a example code  thanks for yor help.
    P.D. Only if the data is diferent is sotraged. (I have LabVIEW 5.1.1)
    Atn. Ing. Jorge Cardozo. San Luis Rassini Corporation. Piedras Negras Coahuila Mexico.
    Thank you for your help.
    Attachments:
    KA-COUNTER (Comparacion).vi ‏77 KB

    hi there
    to collect scalar data in an array you can use a so called "Shift register". To display the history of scalar data you can use a Waveform Chart (not a "Graph", a "Chart"). See attachments. because i can't save the vi as 5.1 i appended some screenshots of the front panel and the block diagramm.
    Best regards
    chris
    CL(A)Dly bending G-Force with LabVIEW
    famous last words: "oh my god, it is full of stars!"
    Attachments:
    KA_Counter_BD.JPG ‏122 KB
    KA_Counter_FP.JPG ‏86 KB

  • How can detect the serial port is active

    I made a program. It can read datas via serial port. But the datas wont came all the time, so the other part of the program not need to run. I want to put before the "reading serial port" a detection about the serial port is get a data. So the reading is wont start before datas are not coming. Can anybody help me how can i solve this problem?

    Hi Zoyo, if you use the VISA- VIs, the functionyou need is "VISA Bytes at serial port". It shows, how many Bytes are available in the input buffer. You can find it here:
    greets, Dave
    Message Edited by daveTW on 11-22-2006 02:01 PM
    Greets, Dave
    Attachments:
    Bytes at serial port.png ‏20 KB

  • I converted from a PC to a Mac Mini.  I have my PC documents backed up on a DVD disk.  I have an external DVD drive connected to the Mac Mini.  I want to open them up and save them to the Mac, BUT....when I put the DVD disk in the Mac is NOT reading it!

    I converted from a PC to a Mac Mini.  I have my PC documents backed up on a DVD disk.  I have an external DVD drive connected to the Mac Mini.  I want to open these documents up from the DVD storage and save them to the Mac, BUT....when I put the DVD disk in the Mac is NOT reading it!

    Hi Joe,
    Thanks for your quick response.  I should add....it worked before.  When I previously inserted the two DVDs into this remote drive, and I went into finder, I could click on the "remote device" line and see all my saved documents (excel, word, etc) on the DVD and open them on the Mac.  Now I cannot see them, when I try to open them on the Mac, nothing happens, nothing is displayed.  I just re-tested the remote DVD drive with a CD and, no problem, it opened up the CD via iTunes and I cold play the CD.  SO......I know the remote DVD drive (it's an LG by the way) is fine, it's something to do with some settings on my mini mac,especially where I could open it previously.  I do not remember changing any settings since then. 
    When I go into system preferences and click on CD/DVD it gives me options of how to open up a music CD (default is iTunes), a DVD (default is iMovie), etc.  The problem is my DVD is all miscellaneious files/documents.  I just want to be able to see them in the finder.  I also tried to open them via microsoft word, from the remote disk and again, it could not open the drive, even though some of the documents were microsoft word documents.  Again, I was able to open them previously and the DVD is not corrupted in any way.  
    Any additional advice? 
    Thank you!

  • TS2776 I can synch items entered into MS calendars to my iPad... this is done automatically when I connect to the USB.  How do I synch items initially entered into my iPad to MS Calendars when the unit is connected to the USB port???

    Cannot tell is the initial question was sent so here goes again.  I can synch items entered into MS Calendars with my iPad... this is done automatically when I connect the iPad to the USB port.  Can I synch items entered into the iPad calendar to the MS Calendar when the iPad is connected to the USB port??? if so how???

    I have found an alternative and much quicker way to transfer photos to my ipad. Having exhausted the Apple route with its connection kit, I stumbled upon a YouTube video showing how you could use an external sd card reader / USB to transfer pictures. I did a quick search on eBay and found a device that would work with the ios7 update. Hey presto it works! (I purchased an sd card and a sd card adapter for my Canon 350d) plus the little sd card reader from eBay ( for quarter of the price ) of Apples connection kit ( which didn't work)
    Come on Apple why can suppliers in the Market place produce accessories that work better than your own kit? You are missing an opportunity and frustrating customers no doubt. Could do better !

  • HT1338 Does anyone have a fix for the error message "Because a USB device was drawing too much power from your computer one or more of your USB devices have been disabled" - this is a brand new machine with nothing connected to the USB ports - i've done u

    Hi
    does anyone know how to fix the message on my iMac:
    "Because a USB device was drawing too much power from your computer, one or more of your USB devices have been disabled."
    This is a brand new machine and did not have anything attached to the USB ports"
    Thanks for any help

    If you are getting that message on a brand new Mac with nothing connected to the USB ports, take it back. It is broken.

  • HT201250 Time machine back up using a external hard drive connected to the Airport extreme

    How can I setup a time machine back up using a external hard drive connected to the Airport extreme? Even better for time managment purposes I want to use the Eithernet Thunderbolt connection for the first back up and then through the wifi there after for daily routine Time Machine back ups.

    You can attach a hard drive, but Time Machine backups to a drive at the USB port at the AirPort Extreme are not supported by Apple, so it's not possible to say what your actual results might be.
    If you decide to try this, it would be wise to have a secondary backup plan in place as well.
    http://docs.info.apple.com/article.html?path=Mac/10.6/en/15139.html

  • I want to transfer data through the serial port in the same coding that hyperterminal uses. How can i do it?

    The serial port seems to be working, and labview seems to be sending the data, but the problem is in which format does it send the data, because in hyperterminal i just input the string "JDX" and it sends it to my device, with labview it sends something but my device does not recognize it.

    nobuto wrote:
    > I want to transfer data through the serial port in the same coding
    > that hyperterminal uses. How can i do it?
    >
    > The serial port seems to be working, and labview seems to be sending
    > the data, but the problem is in which format does it send the data,
    > because in hyperterminal i just input the string "JDX" and it sends it
    > to my device, with labview it sends something but my device does not
    > recognize it.
    Hyperterminal adds the carriage return/line feed to the string which is
    generated by the return key to send out the current line. LabVIEW simply
    sends out what you tell it, so try to set the string to "Show \ Display"
    format and add a \r or \n or \r\n to the command you want to send out.
    Assumes of course that you set the right baudr
    ate/bits/parity etc in
    LabVIEW with the VISA property node, when opening the serial port.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Every device (iphone4, iphone4s, ipad2) I try to hook up to iTunes gives me a message "this device cannot connect because the apple mobile device service is not setup" does anyone have ideas as to why it keeps popping up? It just started doing this.

    Every device (iphone4, iphone4s, ipad2) I try to hook up to iTunes gives me a message "this device cannot connect because the apple mobile device service is not setup" does anyone have ideas as to why it keeps popping up? It just started doing this.

    I'd start with the following document with that one:
    iPhone, iPad, iPod touch: How to restart the Apple Mobile Device Service (AMDS) on Windows

  • HT1459 my daughter put a pass code on her i pod and she cant remember it how can i resolve this and i can not read the serial number its to faded and scratched

    my daughter put a pass code on her i pod and she cant remember it how can i resolve this and i can not read the serial number its to faded and scratched

    If you cannot remember the passcode, you will need to Restore your device...
    Connect to iTunes on the computer you usually Sync with and Restore...
    http://support.apple.com/kb/HT1414
    If necessary Place the Device into Recovery mode...
    http://support.apple.com/kb/HT1808

  • Why are all my Apple devices not connecting to the web?

    I have an Airport express and has been working fine up until recently. Now none of my Apple devices are connecting to the web. They all find the network no problem and all connect however they will not connect to the internet. The strange thing is that our Windows laptop works fine but absolutly nothing from Apple, this includes a 2011 MacBook pro, iphone 3gs, ipod touch, Apple tv and 2x 2nd gen ipads. I have reset the airport and  set up a new network, it worked for one day and is back to how it was. Any advice would be great

    I seem to be having a similair issue. I have an AirPort Extreme and my iMac connects fine but now my Kindle and Netflix are unable to connect to the Internet? They see my network but just can't connect to the internet?
    I used to have my cable modem connected to a Vonage phone router, which then connected to my Airport. Everything worked fine then. I recently canceled my Vonage service and removed the phone router. Now my cable modem is connected directly to my Airport. Did removing the phone router casue my problem? Do I need to re-set something to get my kindle and Netflix to work again?

  • How do i fix my wifi if it connects and the bars are blue but no check sign appears next to the wifi name and does not connect to the internet???

    How do i fix my wifi if it connects and the bars are blue but no check sign appears next to the wifi name and does not connect to the internet???

    Did you already try to reset the iPod by holding the sleep and home button for about 10sec, until the Apple logo comes back again? You will not lose data.
    If this does not work, try to reset the network settings in Settings/General/Reset. After that you'll have to put in the passwords for all known networks again.
    More troubleshooting can be found here:
    iOS: Troubleshooting Wi-Fi networks and connections

Maybe you are looking for