₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,326,646 members, 8,427,429 topics. Date: Monday, 15 June 2026 at 10:12 PM

Toggle theme

Charlipaedia's Posts

Nairaland ForumCharlipaedia's ProfileCharlipaedia's Posts

1 (of 1 pages)

ProgrammingTrying To Read Input From Avery Weighing Scale Into An Application by Charlipaedia(op): 2:31pm On Mar 28, 2018
Hello guys, am trying to read a data input from an Avery Weighing Scale into an application but I keep getting an output like this: ***** plus small boxes. Please I urgently need to rectify this challenge urgently can anyone please help. Thank you.

Below is the code am using for this:

import gnu.io.*;
import java.io.*;
import java.util.*;


public class USBTesting implements Runnable, SerialPortEventListener {

static CommPortIdentifier portId;
static Enumeration portList;

InputStream inputStream;
SerialPort serialPort;
Thread readThread;

public static void main(String[] args) {


portList = CommPortIdentifier.getPortIdentifiers();
portId = (CommPortIdentifier) portList.nextElement();

//System.out.println("Welcome: "+portId);
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();

if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM4"wink) {
// if (portId.getName().equals("/dev/term/a"wink) {
USBTesting reader = new USBTesting();
System.out.println("Welcome"wink;
} else{
System.out.println("Port not found"wink;
}
}
}
}

public USBTesting() {
try {
serialPort = (SerialPort) portId.open("USBTesting", 2000);
} catch (PortInUseException e) {System.out.println(e);}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {System.out.println(e);}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {System.out.println(e);}
serialPort.notifyOnDataAvailable(true);
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {System.out.println(e);}
readThread = new Thread(this);
readThread.start();
}

public void run() {
try {
Thread.sleep(20000);
} catch (InterruptedException e) {System.out.println(e);}
}

public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[8];
String str = "";
int NEW_LINE_ASCII = 10;
String logText = "";


try {
int numBytes = 0;
while (inputStream.available() > 0) {
numBytes = inputStream.read(readBuffer);
//System.out.println("Data"wink;
}

System.out.println(new String(readBuffer,0, numBytes, "UTF-8"wink);
//System.out.println(str);
} catch (IOException e) {System.out.println(e);}
break;
}
}
}
Jobs/VacanciesRe: PwC Nigeria Graduate Recruitment 2017 by Charlipaedia: 8:56am On Feb 17, 2017
Please can also get a mail for past pwc question chidicharles@outlook.com thanks in anticipation
Jobs/VacanciesRe: PwC Nigeria Graduate Recruitment 2017 by Charlipaedia: 8:44am On Feb 17, 2017
Please I also need the pwc past question chidicharles@outlook.com thanks

1 (of 1 pages)