Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,159 members, 7,818,529 topics. Date: Sunday, 05 May 2024 at 06:01 PM

Trying To Read Input From Avery Weighing Scale Into An Application - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Trying To Read Input From Avery Weighing Scale Into An Application (766 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"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;
}
}
}

(1) (Reply)

New File Transfer Service Called Multisends / Fulltime Intermediate Fullstack Developer(php/laravel/javascript) N150k-n200k / If You Are A Non-us Citizen And Want A No-fee Broker For US Stocks, Message Me

(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. 16
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.