G
G
GlukKazan2012-11-13 14:28:56
Java
GlukKazan, 2012-11-13 14:28:56

Problem using RXTX with MOXA virtual COM port?

I'm trying to connect to Alcatel S12 PBX via Serial-port from Java application. To forward the Serial port over the Internet, MOXA software (NPort Management Suite 3.5) is used, which creates a virtual COM port on the client side. To work with the Serial port from Java SE, I use RXTX .
The problem is:
1. MOXA uses two TCP connections for data transfer: control (port 966) and data stream (port 950)
2. RXTX uses the following code to open the COM port (is it possible to open the port somehow differently, not I know):

void connect ( String portName ) throws Exception
    {
        CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
        if ( portIdentifier.isCurrentlyOwned() )
        {
            System.out.println("Error: Port is currently in use");
        }
        else
        {
            CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);
            
            if ( commPort instanceof SerialPort )
            {
                SerialPort serialPort = (SerialPort) commPort;
                serialPort.setSerialPortParams(57600, SerialPort.DATABITS_8, 
                          SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
                
                InputStream in = serialPort.getInputStream();
                OutputStream out = serialPort.getOutputStream();
                
                (new Thread(new SerialReader(in))).start();
                (new Thread(new SerialWriter(out))).start();

            }
            else
            {
                System.out.println("Error: Only serial ports are handled by this example.");
            }
        }     
    }

3. When executing getPortIdentifier, RXTX for some reason opens the Serial port and then closes it. The call to open attempts to reopen the port.
4. MOXA software closes the data stream (port 950) when the Serial port is closed, and does not open it during the subsequent open, as a result, it is impossible to work with the Serial port after that.
If anyone has come across this problem, please help. The following options are of interest:
1. Possible ways to work around the problem using RXTX (possibly with minor changes to its Java code, but without fixing the dll) 2. Java libraries
for working with the Serial port, other than RXTX
JNDI, under Windows, is being considered, but is rated as overly labor intensive.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
P
ProstoTyoma, 2012-11-13
@ProstoTyoma

Worked with NPort, but not from Java. The thing is really buggy, but I have not seen such a glitch specifically. You can try to somehow make a delay between two openings. Also for C ++ there was something like the NPort API, which allows you to work with the MOXA device directly without virtual ports, but I have not seen this for Java.
I periodically stopped opening ports in general. Deleting\adding ports in NPort Admin helped.

G
GlukKazan, 2012-11-13
@GlukKazan

The NPort API is included, but for now I want to do without JNDI. Delay I will try, but most likely will not help. I went through this code under the debugger and paused for ~3 seconds

G
GlukKazan, 2012-11-13
@GlukKazan

I will try jSSC . Many thanks to the author

G
GlukKazan, 2012-11-19
@GlukKazan

It was possible to connect to the station via TCP

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question