- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两台计算机运行此代码:
import java.io.*;
import java.util.*;
import gnu.io.*;
public class Deb implements SerialPortEventListener, Runnable{
public static final int TIMEOUTSECONDS = 30;
public static final int BAUD = 9600;
static String telefono;
static Boolean llamar = false;
CommPortIdentifier cpiModem = null;
SerialPort modem;
BufferedReader is;
PrintStream os;
Thread hiloMarcado;
int nConnects = 0;
boolean flag = false;
String line;
public static void main(String argv[]) throws PortInUseException, UnsupportedCommOperationException, IOException, InterruptedException, TooManyListenersException {
if (argv.length>0) {
telefono = argv[0];
llamar = true;
}
new Deb();
}
public Deb() throws PortInUseException, UnsupportedCommOperationException, IOException, InterruptedException, TooManyListenersException{
Enumeration pList = CommPortIdentifier.getPortIdentifiers();
while (pList.hasMoreElements()) {
CommPortIdentifier cpi = (CommPortIdentifier)pList.nextElement();
if (cpi.getPortType()==CommPortIdentifier.PORT_SERIAL) {
SerialPort puertoSerie = (SerialPort) cpi.open("DEB", TIMEOUTSECONDS * 1000);
puertoSerie.setSerialPortParams(BAUD, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
puertoSerie.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN & SerialPort.FLOWCONTROL_RTSCTS_OUT);
BufferedReader is = new BufferedReader(new InputStreamReader(puertoSerie.getInputStream()));
PrintStream os = new PrintStream(puertoSerie.getOutputStream(), true);
os.println("AT");
Thread.sleep(TIMEOUTSECONDS * 50);
if (!is.ready()) {
System.out.println("No hay un modem en " + cpi.getName());
} else {
System.out.println("Hay un modem en " + cpi.getName());
cpiModem = cpi;
}
puertoSerie.close();
}
}
modem = (SerialPort) cpiModem.open("DEBita", TIMEOUTSECONDS * 1000);
modem.setSerialPortParams(BAUD, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
modem.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN & SerialPort.FLOWCONTROL_RTSCTS_OUT);
is = new BufferedReader(new InputStreamReader(modem.getInputStream()));
os = new PrintStream(modem.getOutputStream(), true);
modem.addEventListener(this);
modem.notifyOnDataAvailable(true);
modem.notifyOnCarrierDetect(true);
modem.notifyOnBreakInterrupt(true);
modem.notifyOnCTS(true);
modem.notifyOnDSR(true);
modem.notifyOnFramingError(true);
modem.notifyOnOutputEmpty(true);
modem.notifyOnOverrunError(true);
modem.notifyOnParityError(true);
modem.notifyOnRingIndicator(true);
/*System.out.println(is.read());*/
if (llamar) {
hiloMarcado = new Thread(this);
hiloMarcado.start();
}
}
public void serialEvent(SerialPortEvent event) {
switch (event.getEventType()) {
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.DSR:
System.out.println("Data Set Ready.");
break;
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
System.out.println("Ignored event");
break;
case SerialPortEvent.BI:
System.out.println("Break Interrupt");
break;
case SerialPortEvent.CTS:
System.out.println("Clear to send");
break;
case SerialPortEvent.RI:
System.out.println("Pick up the receiver.");
if( event.getNewValue() )
{
System.out.println("Ring Indicator On");
}
else
{
System.out.println("Ring Indicator Off");
}
break;
case SerialPortEvent.CD:
if (event.getNewValue()) {
System.out.println("Connected");
nConnects = nConnects + 1;
} else {
System.out.println("Disconnected");
}
break;
case SerialPortEvent.DATA_AVAILABLE:
handleData();
break;
}
}
public void run() {
while (true) {
if (nConnects == 0) {
try {
if (!modem.isCD()) {
System.err.println("Estamos llamando ...");
os.println("ATDT" + telefono);
}
Thread.sleep(TIMEOUTSECONDS * 2000);
} catch (Exception ex) {
System.err.println("Failed to write message");
}
}
}
}
public void handleData() {
try {
int avail = modem.getInputStream().available();
byte[] response = new byte[avail];
StringBuffer strbuf = new StringBuffer();
modem.getInputStream().read(response, 0, avail);
if (!flag) {
modem.getInputStream().read(response, 0, avail);
for (int i = 0; i < avail; i++) {
Thread.sleep(5);
os.write((char) response[i]);
System.out.print((char) response[i]);
}
}
} catch (IOException ie1) {
System.out.println("File " + ie1);
} catch (InterruptedException in) {
System.out.println("Interrupt " + in);
}
}
}
这不是最终版本,我只是看看它是如何工作的。问题是,当我使用此代码调用电话号码(例如我的手机)时,它可以工作,但反之则不起作用;也就是说,从我的号码调用并将程序充当监听器。我也尝试了两台计算机,但它们都没有接到另一端的调用。难道我做错了什么?我将不胜感激任何帮助。
最佳答案
AT 兼容调制解调器应通过数据线发送“RING”,以通知您有传入振铃事件。也许你可以听听?
关于java - 为什么 SerialEvent.RI 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/771538/
我正在使用 Java 11、Spring Boot 2.1.1 和 Apache CXF 3.2.7 公开导入 XSD 架构的 SOAP Web 服务。在 WSDL 中它显示为: 当我发送查询失败
Jonathans-MacBook-Pro-2:pickaxe jod$ ri ActiveRecord::Base#save Nothing known about ActiveRecord 这应该
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 5 年前。
使用 maven,有几个插件可以支持,例如从 XSD 生成 JAXB 类,例如org.codehaus.mojo:jaxb2-maven-plugin 和 org.jvnet.jaxb2.maven2
当我输入“ri”时,PowerShells的默认设置认为它是“删除项”的别名-如何使用ri命令调用“R” uby“I” ndex? 我尝试cd到C:\ Ruby22并输入: rdoc --all --
我最喜欢 Ruby 的原因之一是它的学习非常简单。如果我想发现新东西,我可以打开 irb 和 ri,然后找到新的方法来轻松地做事。 我发现在 javascript 中做这件事并不容易。 我喜欢能够将开
我们有一个复杂的类结构,我们正在尝试使用 JAXB-RI 将其编码到 xml 文件。编码似乎可以在 Spring 的 jaxb2Marshaller 中正常工作,但在我们尝试使用的 jaxb-ri 中
当您从 OS X 术语窗口运行 Ruby ri 命令以查看特定命令的文档时,您如何“退出”该文档?在文档末尾,显示 (END),但我不知道如何退出。我试过 CTRL-C、CTRL-D、Esc 等,但找
我有一些为我的应用程序生成的自定义 RDoc 数据。我也想创建自定义 RI 文档,但我无法在任何地方找到该命令。这是什么? ri Hash 返回手册页。 ri CustomObject 没有。我希望两
我尝试先安装一个 gem gem install rdoc-data成功安装后,我尝试了 rdoc-data --install 但是,我得到了错误:不支持你的ruby版本2.1.1,只支持1.8.7
我的应用程序中出现以下异常。 com.sun.faces.config.ConfigurationException: It appears the JSP version of the contai
我有两台计算机运行此代码: import java.io.*; import java.util.*; import gnu.io.*; public class Deb implements Ser
我继承了一个代码库,其中一部分是使用 Eclipse 生成器构建的 Web 服务。生成的代码似乎有许多文件路径(用于 wsdls 等),它们引用原始开发人员盒子上的位置。例如,在服务类的静态构造函数中
为此,我主要对 pgsql 感兴趣,但我想知道在任何 RDBMS 中是否有一种方法可以执行插入操作,无需禁用和重新启用任何 FOREIGN KEY 或 NOT NULL约束,在两个相互引用的表上。 (
刚刚使用 rvm 方法将 ruby 新安装到 ubuntu 服务器上。 ruby -v 返回我正在运行的版本,1.9.2 很好,我能够执行我正在尝试学习的书中的基本代码.所以在命令提示符下,如下
在交互式 ruby 控制台中,如果我输入 ri 然后我得到一个未定义的方法错误,我是否明确必须在某处安装文档才能让它工作? irb(main):015:0* ri --help NoMethodE
介绍 我和我的 friend 正在开发一个 JavaFX 应用程序,它充当我们学校的规划师。我们有任务(类作业)、 Activity 、类(class)和学生信息。为了尝试将数据持久存储在用户的硬盘上
假设我有以下两个类: package example.model; public class Model { public static class Inner {} public O
我正在阅读 de Ruby of Pickaxe(ruby 版本 2.0)这本书,但我无法执行此语句 $ export RI="--format ansi --width 70" 我正在使用 Ubun
我在 Mac OS X 上使用 zsh。当我键入 ri 后跟类名时,一切正常。但是,如果我想查找特定的方法文档(例如 Array#new),shell 会告诉我 zsh: no matches fou
我是一名优秀的程序员,十分优秀!