自分の携帯電話モデムがそれを使用している間に、なぜ私のコンピュータのCOM4ポートの自由の状況はありますか?

StackOverflow https://stackoverflow.com/questions/4237997

  •  26-09-2019
  •  | 
  •  

質問

ここに私のコードは次のとおりです。

import java.io.*;
import java.util.*;
import javax.comm.*;

public class SMS {


    public static void main(String[] args) {
            Enumeration lists=CommPortIdentifier.getPortIdentifiers();
            System.out.println(CommPortIdentifier.PORT_SERIAL);
            System.out.println(lists.hasMoreElements());
            while (lists.hasMoreElements()){
                CommPortIdentifier cn=(CommPortIdentifier)lists.nextElement();

                if ((CommPortIdentifier.PORT_SERIAL==cn.getPortType())){
                    System.out.println("Name is serail port "+cn.getName()+" Owned status "+cn.isCurrentlyOwned());

                    try{
                        SerialPort port1=(SerialPort)cn.open("ComControl",800000);
                        port1.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                        System.out.println("Before get stream");
                        OutputStream out=port1.getOutputStream();
                        InputStream input=port1.getInputStream();
                        System.out.println("Before write");
                        out.write("AT".getBytes());
                        System.out.println("After write");
                        int sample=0;
                        //while((( sample=input.read())!=-1)){
                        System.out.println("Before read");
                            //System.out.println(input.read() + "Testing ");
                        //}
                            System.out.println("After read");
                        System.out.println("Receive timeout is "+port1.getReceiveTimeout());
                    }catch(Exception e){
                        System.err.println(e.getMessage());
                    }
                }

                else{
                    System.out.println("Name is parallel port "+cn.getName()+" Owned status "+cn.isCurrentlyOwned()+cn.getPortType()+"    ");
                }
            }
    }

}

このが出力されます:

1
true
Name is serail port COM1 Owned status false
Before get stream
Before write
After write
Before read
After read
Receive timeout is -1
Name is serail port COM2 Owned status false
Before get stream
Before write
After write
Before read
After read
Receive timeout is -1
Name is serail port COM3 Owned status false
Before get stream
Before write
After write
Before read
After read
Receive timeout is -1
Name is serail port COM4 Owned status false
Before get stream
Before write
After write
Before read
After read
Receive timeout is -1
Name is parallel port LPT1 Owned status false2    
Name is parallel port LPT2 Owned status false2    

私のCOM4ポートは、自分の携帯電話モデムで使用されるが、コードをよると、そのステータスは無料でされています。 そこに何かが私はソート方法をすることができますコードで逃したとしました。これらのうち?

役に立ちましたか?

解決

あなたの携帯電話を制御しているものは何でもソフトウェアは、スリープモード、またはそのような何かであるのかもしれませんか?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top