NPort W2150A-W4/W2250A-W4 Series User Manual
108
MxNPortAPI Function Groups
The supported functions in this API are listed below:
Port Control
Input/Output
Port Status Inquiry
Miscellaneous
open
close
setIoctlMode
setFlowCtrl
setBaud
setRTS
setDTR
flush
read
write
getBaud
getFlowCtrl
getIoctlMode
getLineStatus
getModemStatus
getOQueue
setBreak
Example Program
To make sure this API is workable with the device server on an Android platform, see the example program
below:
Thread thread = new Thread()
{
@Override
public void run() {
/* Enumerate and initialize NPorts on system */
List<MxNPort> NPortList = MxNPortService.getNPortInfoList();
if(NPortList!=null){
MxNPort.IoctlMode mode = new MxNPort.IoctlMode();
mode.baudRate = 38400;
mode.dataBits = MxNPort.DATA_BITS_8;
mode.parity = MxNPort.PARITY_NONE;
mode.stopBits = MxNPort.STOP_BITS_1;
MxNPort mxNPort = NPortList.get(0);
/* Get first NPort device */
try {
byte[] buf = {'H','e','l','l','o',' ','W','o','r','l','d'};
mxNPort.open();
/*open port*/
mxNPort.setIoctlMode(mode);
/*serial parameters setting*/
mxNPort.write(buf, buf.length);
/*write data*/
mxNPort.close(); /*close port*/
} catch (MxException e){
/*Error handling*/
}
}
}
};
thread.start();