Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,731 members, 7,955,783 topics. Date: Sunday, 22 September 2024 at 02:56 PM |
Nairaland Forum / Science/Technology / Programming / Trying To Read Input From Avery Weighing Scale Into An Application (789 Views)
I Need Serious Input From Experts On This Project. / Having Difficulty Running An Application Built With Visual Studio 2017. / I Built An Application That Allows You Marry Your Celebrity Crush Online (2) (3) (4)
(1) (Reply)
Trying To Read Input From Avery Weighing Scale Into An Application by Charlipaedia: 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") { // if (portId.getName().equals("/dev/term/a") { USBTesting reader = new USBTesting(); System.out.println("Welcome" } else{ System.out.println("Port not found" } } } } 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" } System.out.println(new String(readBuffer,0, numBytes, "UTF-8"); //System.out.println(str); } catch (IOException e) {System.out.println(e);} break; } } } |
(1) (Reply)
Fulltime Intermediate Fullstack Developer(php/laravel/javascript) N150k-n200k / Save Time Building Great Websites / Web page Auto Refresh with Selenium
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 8 |