Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用连接USB或HSDPA加密狗的Java进行呼叫_Java - Fatal编程技术网

使用连接USB或HSDPA加密狗的Java进行呼叫

使用连接USB或HSDPA加密狗的Java进行呼叫,java,Java,我在google上找不到任何关于“使用java和HSDPA加密狗进行PlaceCall”的文章。我已完成端口初始化,但不知道如何进行呼叫。 1) 我正在使用华为加密狗 2) 我发现错误“无承运人” 3) 我正在使用以下代码检测端口或调制解调器,并试图拨打电话,但它给我“无载波”错误!我在这里犯了什么错误请帮帮我 import java.io.*; import java.util.*; import gnu.io.*; import java.io.*; import javax.sound.s

我在google上找不到任何关于“使用java和HSDPA加密狗进行PlaceCall”的文章。我已完成端口初始化,但不知道如何进行呼叫。
1) 我正在使用华为加密狗

2) 我发现错误“无承运人”

3) 我正在使用以下代码检测端口或调制解调器,并试图拨打电话,但它给我“无载波”错误!我在这里犯了什么错误请帮帮我

import java.io.*;
import java.util.*;
import gnu.io.*;
import java.io.*;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import org.apache.log4j.chainsaw.Main;
import sun.audio.*;

public class GSMConnect implements SerialPortEventListener, 
 CommPortOwnershipListener {

 private static String comPort = "COM6"; // This COM Port must be connect with GSM Modem or your mobile phone
 private String messageString = "";
 private CommPortIdentifier portId = null;
 private Enumeration portList;
 private InputStream inputStream = null;
 private OutputStream outputStream = null;
 private SerialPort serialPort;
 String readBufferTrial = "";
 /** Creates a new instance of GSMConnect */
 public GSMConnect(String comm) {

   this.comPort = comm;

 }

 public boolean init() {
   portList = CommPortIdentifier.getPortIdentifiers();
   while (portList.hasMoreElements()) {
     portId = (CommPortIdentifier) portList.nextElement();
     if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
       if (portId.getName().equals(comPort)) {
           System.out.println("Got PortName");
         return true;
       }
     }
   }
   return false;
 }

 public void checkStatus() {
   send("AT+CREG?\r\n");
 }

 public void dial(String phoneNumber) {
   try {
//dial to this phone number

     messageString = "ATD" + phoneNumber + ";\r\n";
     outputStream.write(messageString.getBytes());
     System.out.println("Called ");
   } catch (IOException e) {
     e.printStackTrace();
   }
 }

 public void send(String cmd) {
   try {
     outputStream.write(cmd.getBytes());
   } catch (IOException e) {
     e.printStackTrace();
   }
 }

 public void sendMessage(String phoneNumber, String message) {
       char quotes ='"';
   send("AT+CMGS="+quotes + phoneNumber +quotes+ "\r\n");
   try {
    Thread.sleep(2000);
} catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
    //   send("AT+CMGS=\""+ phoneNumber +"\"\r\n");
   send(message + '\032');
   System.out.println("Message Sent");
 }

 public void hangup() {
   send("ATH\r\n");
 }
 public void welcomeMessage(){

     // open the sound file as a Java input stream
        String gongFile = "C:\\Users\\SACHIN\\Desktop\\7001110.mp3";
        InputStream in;
        try {
            in = new FileInputStream(gongFile);
             // create an audiostream from the inputstream
           // AudioStream audioStream = new AudioStream(in);
            // play the audio clip with the audioplayer class
           // AudioPlayer.player.start(audioStream);
            Clip clip = AudioSystem.getClip();
            AudioInputStream inputStream = AudioSystem.getAudioInputStream(
              Main.class.getResourceAsStream(gongFile));
            clip.open(inputStream);
            clip.start(); 
        } catch (IOException | UnsupportedAudioFileException | LineUnavailableException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }





 }
 public void connect() throws NullPointerException {
   if (portId != null) {
     try {
       portId.addPortOwnershipListener(this);

       serialPort = (SerialPort) portId.open("MobileGateWay", 2000);
       serialPort.setSerialPortParams(115200,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
     } catch (PortInUseException | UnsupportedCommOperationException e) {
       e.printStackTrace();
     }

     try {
       inputStream = serialPort.getInputStream();
       outputStream = serialPort.getOutputStream();

     } catch (IOException e) {
       e.printStackTrace();
     }

     try {
       /** These are the events we want to know about*/
       serialPort.addEventListener(this);
       serialPort.notifyOnDataAvailable(true);
       serialPort.notifyOnRingIndicator(true);
     } catch (TooManyListenersException e) {
       e.printStackTrace();
     }

//Register to home network of sim card

     send("ATZ\r\n");

   } else {
     throw new NullPointerException("COM Port not found!!");
   }
 }

 public void serialEvent(SerialPortEvent serialPortEvent) {
   switch (serialPortEvent.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:
         System.out.println("Ringing");

    /*try {
        Thread.sleep(5000);
        send("ATA");
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }*/
    break;
     case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
     case SerialPortEvent.DATA_AVAILABLE:

       byte[] readBuffer = new byte[2048];
       try {
         while (inputStream.available() > 0) 
         {
           int numBytes = inputStream.read(readBuffer);

           System.out.print(numBytes);
           if((readBuffer.toString()).contains("RING")){
           System.out.println("Enter Inside if RING Loop");    


           welcomeMessage();
           }
         }
         //readBufferTrial=readBufferTria;//+new String(readBuffer)+new Date();
         //print response message
         System.out.print(new String(readBuffer));
       } catch (IOException e) {
       }
       break;
   }
 }
 public void outCommand(){
     System.out.print(readBufferTrial);
 }
 public void ownershipChange(int type) {
   switch (type) {
     case CommPortOwnershipListener.PORT_UNOWNED:
       System.out.println(portId.getName() + ": PORT_UNOWNED");
       break;
     case CommPortOwnershipListener.PORT_OWNED:
       System.out.println(portId.getName() + ": PORT_OWNED");
       break;
     case CommPortOwnershipListener.PORT_OWNERSHIP_REQUESTED:
       System.out.println(portId.getName() + ": PORT_INUSED");
       break;
   }

 }
 public void closePort(){

    serialPort.close(); 
 }

 public static void main(String args[]) {
   GSMConnect gsm = new GSMConnect(comPort);
   if (gsm.init()) {
     try {
         System.out.println("Initialization Success");
       gsm.connect();
       Thread.sleep(5000);
       gsm.checkStatus();
       Thread.sleep(5000);
       System.out.println("Before Auto Answer");
       gsm.send("ATS0=1");


       Thread.sleep(1000);
       gsm.dial("87SSSXXX9105");

     //  Thread.sleep(1000);
     //  gsm.welcomeMessage();
    //   Thread.sleep(1000);
     //  gsm.welcomeMessage();// for turning on Echo ATE1&W

       Thread.sleep(20000);

       gsm.hangup();
       Thread.sleep(1000);
       gsm.closePort();
       gsm.outCommand();
       System.exit(1);


     } catch (Exception e) {
       e.printStackTrace();
     }
   } else {
     System.out.println("Can't init this card");
   }
 }

}

首先,您必须检查您的HSDPA加密狗是否真的支持呼叫。许多HSDPA棒只支持短信和数据


如果有,并且您有一个虚拟串行端口,您可以使用Java RXTX从Java程序连接到它,并向斗杆发送AT命令,如
ATDT01234567
(拨01234567)

请出示您的代码并告诉我们您在哪一步遇到问题。我已再次编辑了我的问题,请检查代码并告诉我错误。谢谢,先生,我成功地完成了操作,但没有听到声音!HSDPA杆是否在设备管理器中添加音频设备?如果不是,我会假设只有IP流量是可能的。使用LTE stick VoLTE(LTE上的语音-移动网络的一种特殊形式的VoIP)是可能的,但在HSDPA VoIP上,运营商网络通常不支持这一点(仅支持Skype等常规VoIP服务)。