如何在不关闭连接的情况下更改波特率? [英] How to change baud rate without closing the connection?

查看:212
本文介绍了如何在不关闭连接的情况下更改波特率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想连接到连接到串口(COM4)且初始波特率为300的设备,设备可以通过命令将其波特率更改为9600,我的Java代码将此命令发送到设备和波特率设备已更改,但我不知道如何在不关闭连接的情况下更改程序中的波特率。当连接关闭时,设备将恢复到初始波特率。

I want to connect to a device that connected to serial port (COM4) with initial baud rate 300, the device can change its baud rate to 9600 with a command, my Java code send this command to device and baud rate of the device changed, but i don't know how to change baud rate in my program without closing the connection. When connection has been closed, device comeback to the initial baud rate.

在连接打开时,有没有办法改变Java中的波特率?

Is there any way to change baud rate in Java while the connection is open?

在我向设备发送更改波特率命令后,当下面的代码执行设备丢失了连接。我认为这种方法只是用于初始化,而不是用于在通信过程中改变波特率。

After I send the "change baud rate" command to device, when below code executed device lost the connection. I think this method is just for initializing, not for changing baud rate in the middle of communication.

port.setSerialPortParams(
    9600,
    SerialPort.DATABITS_8,
    SerialPort.STOPBITS_1,
    SerialPort.PARITY_NONE);


推荐答案

设备很可能感知到DTR或RTS。当端口打开时,Windows将切换它们,并在端口关闭时恢复它们。因此,您有3个选项。我不确定哪一个会起作用 - 你可能要全部尝试一下,我没有带有串口的windows box。

Most likely the device senses either DTR or RTS. Windows will toggle them when port is open, and restore them when port is closed. Thus, you have 3 options. I am not sure which one will work -- you might have to try them all, I do not have windows box with serial port.


  1. 使用不同的Java库,例如librxtx的gnu.io.RXTXPort,它可以在不关闭连接的情况下更改波特率。

  1. Use a different Java library, like "gnu.io.RXTXPort" of librxtx, which can change baudrate without closing the connection.

尝试使用windowsmode命令:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/mode.mspx
尝试将RTS和DSR设置为开和关,并查看是否有任何设置有帮助。请注意,如果成功,即使退出java程序,设备也永远不会被重置。您将不得不再次调用模式来重置设备。

Try to use windows "mode" command: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/mode.mspx . Try both RTS and DSR to "on" and "off", and see if any setting helps. Note that if this succeeds, the device will never get reset, even if you exit your java program. You will have to call "mode" again to reset the device.

获取一条特殊的串行电缆,它不会传递DTR信号。这些被称为3线(仅限RX和TX)或5线(RX / TX + RTS / CTS)RS232电缆,并且易于制作。

Get a special serial cable, which does not pass DTR signals. These are called "3-wire" (RX and TX only) or "5-wire" (RX/TX + RTS/CTS) RS232 cables, and there are easy to make.

这篇关于如何在不关闭连接的情况下更改波特率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆