Fazecast / jSerialComm

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

GetCommPorts returns array of null values #328

Closed kshanawaz closed 2 years ago

kshanawaz commented 3 years ago

Hello,

I am starting with my first project to receive data from a serial port. I have used com0com to set up a virtual COM port CNCA0. I am able to send the date to this port using Serial Port Monitor application. I am now writing a code to read data from this port and every time the code runs, it says port has shutdown or is disconnected.

I am writing this code in Mirth Connect using Javascript and here is the code.

importPackage(Packages.com.fazecast.jSerialComm.*);

var comPort=new Packages.com.fazecast.jSerialComm.SerialPort.getCommPort("CNCA0"); var comPorts=new Packages.com.fazecast.jSerialComm.SerialPort.getCommPorts(); logger.info('Comports->'+JSON.stringify(comPorts)); comPort.openPort(); //comPort.setComPortTimeouts(new Packages.com.fazecast.jSerialComm.SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 0, 0); var indata = new java.lang.StringBuffer();

reader = comPort.getInputStream(); //inFromClient //logger.info('numRead->'+JSON.stringify(reader)+' '+typeof reader+':'+reader) try { for (j = 0; j < 1000;j++) { r=reader.read(); c=new java.lang.Character(r); logger.info('char->'+c); } reader.close(); } catch (e) { logger.info('error->'+e) } comPort.closePort();

: When I tried using get commPorts(), it returned this Comports->[null,null,null,null].

What am I missing here?

hedgecrw commented 3 years ago

I'm unfamiliar with Mirth Connect. If you try using jSerialComm directly through a Java application, are you able to enumerate the ports you expect to see? I suspect there is something wrong with the way the library is getting wrapped inside a Javascript program.

hedgecrw commented 2 years ago

Closing as not a jSerialComm bug but rather a use-case bug which can't be fixed within this library. For bugs related getCommPorts returning an empty list, please refer to #305.