开发者

Change baud rate in C# without closing connection

开发者 https://www.devze.com 2023-03-26 16:35 出处:网络
I have a similar problem to the following link. How to change baud rate without closing the connection?. But i use C# in stead of java. I am beginning with baud rate 300. Then after a hand shake i hav

I have a similar problem to the following link. How to change baud rate without closing the connection?. But i use C# in stead of java. I am beginning with baud rate 300. Then after a hand shake i have to change my baud rate to 4800. I send a command to the device to do this. And I change my serialport's baud rate. After that i can never continue the communicati开发者_运维百科on with the device. (If i stay in 300 baud and send command to the device for 300 baud i can continue the communication)

I have a third party software which also reads from this device. I am listening the port when that software is running. It sends the same commands that i am sending to the device. It sends command to set 4800 baud to the device and can get the answer from the device. It does not close or reopen the port during baud change. I have to do the same thing. But when i send command to change to 4800 baud i get no answer from the device ever.

I am waiting for your answers. Thank you, FERDA

This is the output from serial port monitoring program Port opened by process "ReadY.vshost.exe" (PID: 2608)

01 42 30 03 71 .B0.q

Answer: 09.08.2011 10:55:40.81864 (+0.2656 seconds)

06 .

Request: 09.08.2011 10:55:41.06864 (+1.2500 seconds)

2F 3F 31 31 39 39 39 30 30 34 21 0D 0A /?11999004!..

Answer: 09.08.2011 10:55:41.58464 (+0.5156 seconds)

2F 53 54 52 34 5F 42 53 4D 31 33 31 0D 0A /STR4_BSM131..

Request: 09.08.2011 10:55:42.31864 (+0.2969 seconds)

06 30 34 31 0D 0A .041..


In my experience baud rate switches require closing and reopening the serial port hardware: I would suggest trying that. Send the baud rate switch command then close the port, set the baud rate and then re-open the port. Opening/closing the port should be transparent to the device on the other side (unless you are using the CTS/RTS/DTR/DSR lines).


To change baud rate of a device, follow these steps. eg: To Start communication with a baud rate of 1200.

  1. Send data command for changing the baud rate to 1200.
  2. Receive the acknowledgement from the device.
  3. If the ACK is proper, set the Port.BaudRate=1200.

Next you want to change the baud rate to 4800, then follow these steps

  1. Send data command for changing the baud rate to 4800.
  2. Receive the acknowledgement from the device.
  3. If the ACK is proper, set the Port.BaudRate=4800.

NOTE: Change the Port.BaudRate after receving the ACK from the controller device. The communciation will be started with the previously set BaudRate.

0

精彩评论

暂无评论...
验证码 换一张
取 消