i am trying to connect serial port on ubuntu. However, It doesn't work for me. I succesfully run the same project on Windows just with different drivers. The problem is that I can't load any ports while I am using this:
CommPortIdentifier.getPortIdentifiers(); // i am using rxtx 2.1.7
It always return zero ports. I would like to use port ttyS0 whichworks great with minicon so i am sure that port is not blocked and the machine is not broken.
Anyone has a reason for this ?
It was just becouse low priviligies. I had to add myself to a group which is supposed to work with ttyS0.
I used this command
sudo chmod 666 /dev/ttyUSB0
I had the same problem and it worked the moment after I used this command. Like Smolda said, it is a permission problem.
if nothing helps, you should consider to add this line to your java code:
System.setProperty("gnu.io.rxtx.SerialPorts", "/dev/yourtty");
did it for me. (Only if you work with the RXTX library)
Related
Using Rxtx API.
I am 100% sure there is a serial port available. On Debian, I can see /dev/ttyUSB3 exists when the device is connected.
Tried running getPortIdentifiers() and got nothing when I tried iterating over the hashset
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier("/dev/ttyUSB3");
Also did not work. I got:
Exception Caused by: gnu.io.NoSuchPortException
What am I doing wrong? I am fairly sure rxtx was set up correctly.
The problem here is with how RXTX defines ports. By default, it will only look for certain serial ports(on Linux, /dev/ttySX). There are several options you have to fix this:
Set the gnu.io.rxtx.SerialPorts property when you start Java(either on the command line, or through code. See the Rxtx documentation for more details)
Use a different serial port library that lets you select serial ports manually.
For #2, the following are libraries that I know of:
RXTX
JSSC
PureJavaComm
JavaSerial (disclaimer: this is my library)
I have compiled and executed some proof-of-concept code using the java-ews-api, and have had success when running it under windows. THe same code times out when I run it under linux. Firewalls seem as if they are the most likely suspect, but I can ping the exchange server from eh Linux server.
Could you offer suggestions as to what I should test or research?
Thanks in advance
Thinking about the situation some, it became clear to me that it's simply a firewall issue. The simplest way for me to test connectivity to my Exchange server (using https) was via netcat:
netcat webmail.mydomain.com 443 < /dev/null; echo $?
That will print zero (0) if port 443 is open on that host, and a one (1) if it is closed.
I've beed into a strange problem today and can't find anything to solve it the right way. I have a Java program that is started with /etc/rc.d/rc.local on Slackware 12.1. The program works perfectly. It have to send data on ttyS0 after some requests are made, but in the last installations I needed to send binary data instead of ASCII and this is not working for binary. When I restart the program by the shell, it works perfectly. It seems that there are environment variables or something that cause the RXTX library to enable or disable the canonical mode but can't find this and can't find any settings in RXTX to init serial port in the proper mode.
Thank you,
Alex.
EDIT :
I can simplify the question by asking : Where in Slackware are the serial port initialized to be used in ASCII mode by default? (In my case /etc/rc.d/rc.serial is mode 644 so not executed.
I am very new to programming and setting up Java Servers. Actually its my first time to try it but not successful. I am about to test my first web app in Java but whenever I click the "Start server in debug mode" button in Eclipse I am always having error about my Tomcat server saying that port 8080 is being used. I wanna know how am I gonna check it in the console and close it if possible. Do you know other ways on dealing with this??? I also tried netstat but can't find the port 8080 among the list. Please help me out because I am really getting frustrated. I a tried whatever solution I find in google but still having the same problem. If you can explain to me what's going on that would be very helpful. Thanks in advance.
Use the following command:
netstat -an | find ":8080"
to check whether the port 8080 is open.
try using the following command: \> netstat -a
I need to receive and parse some SNMP traps (messages) and I would appreciate any advice on getting the code I have working on my OS X machine. I have been given some Java code that runs on Windows with net-snmp. I'd like to either get the Java code running on my development machine or whip up some Python code to do the same.
I was able to get the Java code to compile on my OS X machine and it runs without any complaints, including none of the exceptions I would expect to be thrown if it was unable to bind to socket 8255. However, it never reports receiving any SNMP traps, which makes me wonder whether it's really able to read on the socket. Here's what I gather to be the code from the Java program that binds to the socket:
DatagramChannel dgChannel1=DatagramChannel.open();
Selector mux=Selector.open();
dgChannel1.socket().bind(new InetSocketAddress(8255));
dgChannel1.configureBlocking(false);
dgChannel1.register(mux,SelectionKey.OP_READ);
while(mux.select()>0) {
Iterator keyIt = mux.selectedKeys().iterator();
while (keyIt.hasNext()) {
SelectionKey key = (SelectionKey) keyIt.next();
if (key.isReadable()) {
/* processing */
}
}
}
Since I don't know Java and like to mess around with Python, I installed libsnmp via easy_install and tried to get that working. The sample programs traplistener.py and trapsender.py have no problem talking to each other but if I run traplistener.py waiting for my own SNMP signals I again fail to receive anything. I should note that I had to run the python programs via sudo in order to have permission to access the sockets. Running the java program via sudo had no effect.
All this makes me suspect that both programs are having problem with OS X and its sockets, perhaps their permissions. For instance, I had to change the permissions on the /dev/bpf devices for Wireshark to work. Another thought is that it has something to do with my machine having multiple network adapters enabled, including eth0 (ethernet, where I see the trap messages thanks to Wireshark) and eth1 (wifi). Could this be the problem?
As you can see, I know very little about sockets or SNMP, so any help is much appreciated!
Update: Using lsof (sudo lsof -i -n -P to be exact) it appears that my problem is that the java program is only listen on IPv6 when the trap sender is using IPv4. I've tried disabling IPv6 (sudo ip6 -x) and telling java to use IPv4 (java -jar bridge.jar -Djava.net.preferIPv4Stack=true) but I keep finding my program using IPv6. Any thoughts?
java 16444 peter 34u IPv6 0x12f3ad98 0t0 UDP *:8255
Update 2: Ok, I guess I had the java parameter order wrong: java -Djava.net.preferIPv4Stack=true -jar bridge.jar puts the program on IPv4. However, my program still shows no signs of receiving the packets that I know are there.
The standard port number for SNMP traps is 162.
Is there a reason you're specifying a different port number ? You can normally change the port number that traps are sent on/received on, but obviously both ends have to agree. So I'm wondering if this is your problem.
Ok, the solution to get my code working was to run the program as java -Djava.net.preferIPv4Stack=true -jar bridge.jar and to power cycle the SNMP trap sender. Thanks for your help, Brian.