Fazecast / jSerialComm

Platform-independent serial port access for Java
GNU Lesser General Public License v3.0
1.34k stars 287 forks source link

jSerialComm baud rates are not being respected on a serial port/USB adapter #423

Closed Inglonias closed 1 year ago

Inglonias commented 2 years ago

My team is trying to use JSerialComm to talk to various external measuring devices. We're hitting a problem with configuring the serial port, though, and while I'm not sure this is something you have control over, I wanted to check here nonetheless.

We're using a Digi EdgePort/1 to give our computers a serial port (jSerialComm sees the device as "Edgeport [E70502430] Serial Port - 1 (COM10)") and based on my tests, changing the baud rate using jSerialComm does nothing. Regardless of what baud rate we set in Java, the baud rate that is actually used remains the same. I suspect this is because we're using an external adapter device rather than a real serial port. The EdgePort does have a configuration utility program, and we can also change the baud rate from the Windows Device Manager, but doing those things is a pain in the butt, since this is actual work, with actual IT rules that prevent me from just going ahead and doing that - I need to ask permission.

Basically, I'm asking if there's something that I can do to force the serial port adapter to respect the baud rate that I set in the code. I suspect the answer is "no", but I figured I would ask anyway.

Inglonias commented 2 years ago

Here's the data sheet for the adapter we're using, in case that would be helpful. https://hub.digi.com/dp/path=/marketing/asset/prd_usb_edgeport

tinitus91 commented 2 years ago

Just to have a comparison point, did you try to use teraterm or other hyperterminal to see if in this case parameters are applied ?

Inglonias commented 2 years ago

@tinitus91 Unfortunately I can't install software on my work computer to try this.

NorbertSandor commented 2 years ago

I think that setting the baud rate with jSerialComm only sets the baud rate on the "computer" side. You should set the same baud rate on the "measuring device" side as well by configuring it accordingly. (Or your "measuring device" may support "automatic baud rate detection", you should check it.)

I use jSerialComm for communicating with Arduinos, and the baud rate must be set to the same value both on the computer side (in Java, using jSerialComm) and on the Arduino side (in C++, using the Arduino API Serial.begin()). If you fail to match the baud rates then you will see "trash" transmitted data, and maybe freeze one of your devices.

Example docs: https://www.analog.com/en/analog-dialogue/articles/uart-a-hardware-communication-protocol.html

For UART and most serial communications, the baud rate needs to be set the same on both the transmitting and receiving device. The baud rate is the rate at which information is transferred to a communication channel. In the serial port context, the set baud rate will serve as the maximum number of bits per second to be transferred.

The UART interface does not use a clock signal to synchronize the transmitter and receiver devices; it transmits data asynchronously. Instead of a clock signal, the transmitter generates a bitstream based on its clock signal while the receiver is using its internal clock signal to sample the incoming data. The point of synchronization is managed by having the same baud rate on both devices. Failure to do so may affect the timing of sending and receiving data that can cause discrepancies during data handling. The allowable difference of baud rate is up to 10% before the timing of bits gets too far off.

To summarize: if you cannot control the baud rate (and other related) settings of the "measuring device" then I think you have to adapt to its supported baud rate...

tinitus91 commented 2 years ago

Also ask your ISD to install an hyperTerminal, its a minimum requirement when you work with this kind of devices.

NorbertSandor commented 2 years ago

"to install an hyperTerminal" - or a portable version might be available as well (I don't know "hyperTerminal" but eg. Putty has portable versions)

tinitus91 commented 2 years ago

Yes you are right but I said intall in a global way. May be is better to have an authorization rather they realize afterward. All depends of the atmosphere at work :D

hedgecrw commented 2 years ago

Following up on this, were you ever able to get this resolved? As you stated in your initial post, jSerialComm doesn't have any control over baud rates other than those set on the specific port that jSerialComm itself is using, so I don't think there is anything to be done on the library end.

hedgecrw commented 1 year ago

Closing due to inactivity, not solvable in library.