0
votes

I have a program (jruby with rxtx on ubuntu-machine) which opens 2 seperate serial ports. Is it possible to connect both of them to one hardware port i.e. ttyUSB0, or alternatively to a virtual serial port (I have a program to simulate the hardware)?

Is there something like a software repeater/hub to connect 2 serial ports? I checked socat but this one only connects 2 ends with one another. I have read hint for vde2 and hint for slip/slattach but could not find a solution.

No socat specialists out there?

1
I would recomend to check if there is any Java libs available. Because you using JRuby, calling Java from your code is very easy.arkadiy kraportov
Thanks for the hint. I did not want to change my jruby code, I rather like to solve this external, like prepare ports for use...user2025166

1 Answers

0
votes

I finaly could solve this problem only with port ownership in the java class. No way with socat, I think because of the framing problems.

I created an ownership handler like in

Managing Serial Port Ownership (in rxtx)

in jruby it looks like

class SerialOwnershipHandler
include CommPortOwnershipListener

def initialize serial_port
  @serial_port = serial_port
  @id = serial_port.id
  @port_name = serial_port.port_name
end

def ownershipChange type
  case type
    when CommPortOwnershipListener::PORT_OWNED
      p @id.to_s + "  OwnershipListener: got the port for " + @port_name.to_s
      #break
    when CommPortOwnershipListener::PORT_UNOWNED
      p @id.to_s + "  OwnershipListener: just lost it's port ownership for " + @port_name.to_s
      #break
    when CommPortOwnershipListener::PORT_OWNERSHIP_REQUESTED
      p @id.to_s + "  OwnershipListener: someone is asking port ownership for " + @port_name.to_s
      @serial_port.close
      #break
  end
end...

In my serial port class initialize method I call

    @serial_ownership_handler = SerialOwnershipHandler.new self  ## implements CommPortOwnershipListener
    @port_id.add_port_ownership_listener @serial_ownership_handler

Only disadvantage. You cannot have more than one open line. You have to always close one connection before opening anohter one (the one who requests the port)