Error Win XP setting serial port state - java

I have the following code fragment to show a HELLO WORLD by a USB Device (Display Posiflex PD-2800 for POS).
I use the GiovynetDrive library to manage a virtual COM port.
The code runs perfectly (assuming the COM3 is available).
SerialPort = new SerialPort();
Parameters settings = new Parameters();
settings.setPort("COM3");
settings.setBaudRate(Baud._19200);
Port = new Com(settings); //<<--Seting crash when restart
Port.sendString("HELLO WORLD");
Port.close();
My problem is that when I turn off the computer, it doesn't turn off the device (USB power). This cause that the next startup, the code throws the Exception:
java.lang.Exception: Error setting serial port COM3 state.
at giovynet.nativelink.SerialPort.openPortC(Native Method)
at giovynet.serial.Com.<init>(Com.java:48)
.........
This forces me to unplug and plug the USB device and then it works well again.
I think this behavior of the S.O. is configurable, but I don't know as.
UPDATE:
When the USB device is in the restart pending state, I can make a print test without problems using a text only printer (generic driver of the S.O.). Then I can see the print test by my viewer but from my java code still not working until I unplug it.
The S.O. is Windows XP and the USB root HUB (of the device management) have unabled the option "Allow the computer turn off the device to save energy".

Related

Android Emulator - Connecting two emulator Instances via networking with different API-Level

I'm trying to develope an android application (with min-API-Level 28) with Java that communicates with an other device over a socket connection. One device is creating a Server instance and the other device should connect to this server.
For this purpose, I'm using Android-Emulator instances provided by Android Studio.
I followed the instructions at https://developer.android.com/studio/run/emulator-networking#connecting , but encountered that the provided IP-Adress ranges are not the same for every API-Level.
One Emulator-Instance running API 28 is using 192.168.232.0/24 address range, the other one running API-30 is using the provided 10.0.2.0/24 range.
So given the following scenario:
the Server (running on an API-28 Emulator-Instance) is creating the ServerSocket:
this.serverSocket = new ServerSocket();
// 192.168.232.2 is the device's IP-Address IF(!) the Emulator-Instance uses API Level 28
// 55555 the specific ServerPort
this.serverSocket.bind(new InetSocketAddress("192.168.232.2", 55555));
and after that accept incoming connections:
client = this.serverSocket.accept();
the Client (running on an API-30 Emulator-Instance) is trying to connect to this Server:
this.server = new Socket("10.0.2.2", 55556);
as described in the provided docs, 10.0.2.2 is the developement Device aka my Computer and 55556 a chosen local-port.
On the Server-Instance I added a redirect via the android emulator console
redir add tcp:55556:55555
But the Client can't connect to the Server. So far I'm clueless.
Any ideas what went wrong here?
#Edit - Tried to clarify that I'm using Android Emulators instead of real Devices

Shout out to linux gurus. Permission exception

I have a thermal printer that I am trying to configure with my Raspberry Pi 3b. I have a Wildfly server running a java app and I am trying to use this driver to communicate with the printer using the TSPL language.
Whenever I try to call connect I get an exception saying Permission denied: not enough privileges.
I tried to add a new permission in /lib/udev/rules.d
SUBSYSTEM=="usb", ATTR{idVendor}=="20d1", ATTR{idProduct}=="7001", MODE="0666", GROUP="wildfly"
And then run udevadm control --reload-rules to reload the rules but still no success.
I even tried to run:
sudo chown -R wildfly:wildfly /dev/usb/lp0
But still no success. Any help would be really appreciated at this moment. My printer is the HPRT LPQ58.
If I manually send commands to the /dev/usb/lp0 with the cat command those work, but with java I am not able to connect to the usb port.
Nevermind I found the problem. After a reboot it worked. It seems that
udevadm control --reload-rules
does not reload the rules if the printer is already plugged in the usb, so you either have to unplug and plug it back in or run:
udevadm control --reload-rules && udevadm trigger

Error overflow reading serial number of USB device

I'm trying to read the serial number of a device using javax usb library,
and I'm getting this error :
[javax.usb.UsbPlatformException: USB error 8: Unable to get string descriptor languages: Overflow]
The line is simply :
device.getUsbStringDescriptor(descript.iManufacturer());
Someone already had this error ?
Thanks,
I had this error because I hadn't the right driver on a CDC device.
With the Zadig application http://zadig.akeo.ie/
I could install the WINUSB driver on my device.
And this worked fine on a Microchip Demo Board.
Yet the exception remained on my own prototype board. The VUSB connection was not correct.This works fine correctly now in the power-off mode (i.e. the power is not provided by the USB)

Could not find COM port and port list is empty

Hey i would like to connect my eclipse programs written in Java with an Arduino. Previously i used Processing but now i am working on something more difficult: I will connect a Leap to an Arduino, but i get the following message when i try to connect to my port.
I am using a Mac and the port i used in processing was tty.usbserial-AM01VBFC
However this does not work with the given example from: http://playground.arduino.cc/interfacing/java
I changed this to match my port:
private static final String PORT_NAMES[] = {
"/dev/tty.usbserial-AM01VBFC", // Mac OS X
"/dev/ttyACM0", // Raspberry Pi
"/dev/ttyUSB0", // Linux
"COM3", // Windows
};
and the result is:
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
Could not find COM port.
Started
The port list is empty in my opinion because:
portEnum.hasMoreElements()
is false.
The full code can be found in the link above the only thing i changed is the port name for Mac OS X.
I have found only one guy with the same problem and he found a solution for ubuntu i do not understand: http://forum.arduino.cc/index.php?topic=73350.0;wap2
Hoping for some help,
Georgi
I found a solution for the problem:
System.setProperty("gnu.io.rxtx.SerialPorts", "/dev/tty.usbArduino");
the line above has to be commented out and you have to delete your lock files for a "fresh" USB connection!
Thanks to all the answers that lead me to the right way!
edit: it was "/dev/tty.usbArduino" because i made a symlink of my ports! I deleted the symlink afterwards
Follow Tim's advice and print the ports, running:
ls /dev/tty.*
in Terminal. This should allow you to double check if "/dev/tty.usbserial-AM01VBFC" is actually the correct name.
If nothing prefixed by tty.usbserial while your device is connected try this:
Install the FTDI VCP driver
Only if 1 doesn't work and you're using Mavericks try to unload Apple's FTDI driver: sudo kextunload -b com.apple.driver.AppleUSBFTDI (note that this need to be done once per OSX boot)
There are two types of cable:
Charging Cable
Data Transfer Cable
So, try changing cable if you have tried every usb driver and port.
Else, install driver using this link, http://www.wch.cn/download/CH341SER_MAC_ZIP.html
After installing if it doesn't work then change cable.
It worked for me after changing the cable.

Android + JDBC: No route to host (it works on the desktop, why not on android?)

I've searched through the site and haven't quite found a post that answers my problem.
I wrote a desktop application (Java/swing/JDBC) to connect to a local database via JDBC. This database is hosted on an IBM i-series (AS400) (though I'm quite certain this isn't an as400-only problem) and is only available on the internal network. I'm working on translating that application into an android app to be used onside in the warehouse via wireless connection.
I have my JDBC connection in it's own thread. The app asks the user for username/password before attempting a connection. The connection fails every time with the same message: java.sql.SQLException: The application requester cannot establish the connection. (No route to host)
Here is the offending code:
try
{
// Use the AS400 driver.
DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
// Now connect
connection = DriverManager.getConnection(
"jdbc:as400://" + IP_ADDRESS + "/" + SCHEMA +
";naming=sql;errors=full",
USER_ID, PASSWORD);
System.out.println("Connection established using the AS400 driver(s)");
}
catch(Exception as400)
{
String message = "Error setting driver and connection using\n "
+ "the AS400 drivers. The error message is as follows:\n "
+ as400.getMessage();
System.out.println(message);
throw new Exception(message);
}
It registers the driver then hits No route to host, pauses for a second, then throws an error, completely stalling the device instead of letting my error handler safely close the app.
I have double (triple) checked to ensure the credentials are correctly passed and the IP and schema are both correctly set. This code is a direct copy of my desktop code. The only difference is I use a jar optimized for android instead of the desktop. The jar simply contains a translation layer between native AS400 code and Java, but works the same as any SQL jar.
This is our primary database server used throughout the entire company. It is always available and SQL is enabled on it. I am testing this using a physical android device (not an emulated one) and it is connected to our internal wireless network.
Any suggestions on how to fix this or even a direction to look in? Why is there such a difference between the desktop and my android despite both using JDBC? Do I need to do something special for address resolution or something similar? Google-fu is failing me badly. Thanks for your help!
It's not uncommon for wireless traffic to be restricted due to corporate security policies.
Verify that you can connect to DRDA (tcp port 446) on the IBM i from the device on the wireless network.
See TCP/IP Ports Required for iSeries Access for Windows for more information.
JTOpen/Toolbox has a proxy mode if security requirements prevent allowing direct access to the IBM i.
The lightweight version of the JTOpen/Toolbox jar's are also more suited to installation in a cpu and memory restricted environment such as an Android device.
The full JTOpen/Toolbox can be run as a proxy server as follows:
java -cp jt400.jar com.ibm.as400.access.ProxyServer -verbose -port 3470
Add the proxy server option to your connection string:
jdbc:as400:<url>;proxy server=<proxy server address:port>

Categories

Resources