steveohara / j2mod

Enhanced Modbus library implemented in the Java programming language
Apache License 2.0
275 stars 110 forks source link

Cannot open specific virtual COM port configured 8N2 on Windows, which works on legacy javax.comm driver #125

Closed pan-henryk closed 1 year ago

pan-henryk commented 2 years ago

Expected Behavior

  1. 8N2 (8 data bits, no parity two stop bits) port opened normally via j2mod
  2. 8N2 (8 data bits, no parity two stop bits) port opened normally via old javax.comm serial library
  3. 8N1 (8 data bits, no parity one stop bits) port opened normally via j2mod

Actual Behavior

  1. j2mod throws exception java.io.IOException: Port [COM55] cannot be opened after [3] attempts - valid ports are: [COM1,COM11,COM12,COM13,COM14,COM15,COM16,COM2,COM21,COM22,COM3,COM30,COM32,COM33,COM35,COM36,COM37,COM38,COM39,COM4,COM40,COM41,COM45,COM46,COM47,COM5,COM55,COM6,COM7,COM8,COM9] at com.ghgande.j2mod.modbus.net.SerialConnection.open(SerialConnection.java:135) ~[j2mod-3.0.0.jar:3.0.0]

  2. The same port port opened normally via old javax.comm serial library

  3. 8N1 (8 data bits, no parity one stop bit) port opened normally via j2mod

Steps to Reproduce the Problem

I have a virtual COM port configured 8N2, that opens and communicates normally via legacy javax.comm driver, but fails to open via j2mod/jserialcomm. I have tried several different version combinations ranging from quite old to latest and all produce the same effect. When I try change the configuration from 2 stop bits to 1, everything works fine. I am repoirting it here, as I see j2mod exception, but maybe it should be reported to jserialcomm developer?

Specifications

steveohara commented 1 year ago

I can't replicate this on the latest version 3.2.0 Can you try this again and report back

steveohara commented 1 year ago

The opening of serial comms ports is handled by jserialcomm so you will have better luck talking to those guys

pan-henryk commented 1 year ago

I think I got it :) Serial Parameters doc says stopBits passed as int means "number of stopbits" while in fact it should be a reference to jserial comm constant defined as following: ONE_STOP_BIT= 1 ONE_POINT_FIVE_STOP_BITS = 2 TWO_STOP_BITS = 3 So I was passing 2 as an int and it meant something different than I thought. Maybe you could update javadoc to reflect this?