I want to lookup in my system (using java) for all network cards and network interfaces. So, more exactly, I want to get the whole output from ifconfig command (in Linux) but in Java. I know if I use NetworkInterface.getNetworkInterfaces() will return only configured network interfaces.
A rough approach I found at this link. It is OK, but I'm interested if there are other
possibilities on this.
You can use Runtime.getRuntime().exec("ipconfig") for Windows and Runtime.getRuntime().exec("ifconfig") for linux to get ifconfig result in java
There is no way to get to the gory details here in 100% Java. You can either execute commands or write JNI.
Related
i am working on a method to import files which are stored on an usb device to my database.
I already done it for Mac and Windows, but I don't know how to get the path to the usb device when the application is used under Linux/Ubuntu with java.
Is there a way to find the path?
I don't think there is any way that is guaranteed to work on all Linux systems. There are a few approaches I have used, with varying degrees of success.
A method that requires no external utilities is to enumerate and parse the pseudo-files in /dev/disk, /proc/mounts, and /sys/bus/usb, and build a representation of the USB devices that hold storage. There might be more than one, so you might still have to make some guesses, or offer users a choice. This is a pretty tedious method, but I think it is the most general. You can just look at /media, /run/media, as somebody else suggested, but this only works on some Linux installations, and only if that form of auto-mounting is enabled.
A less tedious approach is to invoke the utility udisksctl from your program. I think this utility exists for almost all Linux variants, but it isn't always installed by default. The output of the utility has to be parsed, but it's less hassle that working directly with the kernel psedofiles.
To get a list of disk devices, execute udisksctl status. This will tell you the model name, which will often include the text "USB", and the block device (e.g., /dev/sdb). Then you can execute udisksctl info -b /dev/sdb and look for the line that begins "MountPoints". If the device is not mount you could, if you wished, force it by executing udisksctl mount.... There's a heap of other useful stuff that udisksctl can do -- see its man page.
In Java you can use Runtime.exec() to run udisksctl, but it's probably friendlier to users to check that it is installed first, by check for the existence of /usr/bin/udisksctl.
The easiest way I found is using the Volumes directory.
/Volumes/NAME_OF_USB_DRIVE/file.whatever
I have a basic understanding of network programming but i have never had anything to do with USB ports.
This is what i am trying to achieve
I need to write a program in Java, to communicate to a device which is connected to USB port and then later send commands.
I tried terminal as follows earlier but it didn't quite work
ls -l /dev/tty.*
screen /dev/tty.usbserrial-FTYRDSX7 9600
The above didn't work out.
So if someone can just guide with what Java classes i should be looking into and if there are any APIs that should help me get started
Unless you're required to build it from the ground up, use a library such as usb4java (also here). Trying to manage it as a block device and interpreting whatever protocols etc., etc is not worth the effort unless there something very unique to your problem.
So i ended up using jssc which is much easier to use with strait forward syntax and methods
I want to send AT commands in my Android application, but I could not find the right syntax. How can I do this?
The invokeOemRilRequestRaw() and invokeOemRilRequestStrings() methods which have implementations in a number of classes (RIL, PhoneProxy, PhoneBase, and some others) are what you need, but they are not available through the SDK and thus off-limits to us mere mortals.
There is a great review of this in the XDA forum thread:
How to talk to the Modem with AT commands.
That thread show you how to send AT commands (ATC) with a remote
terminal (USB connected to you PC), but it has not yet solved the
problem of how to use a local (phone) terminal to talk to the
phone Modem.
You need a terminal application/program to do any talking to the
modem (remember, its a 2-way communication). So that's why you need
a rooted device, since the root kit usually come with Busybox
(that includes a microcom terminal program). Otherwise you have to
write your own program.
AFAIK. You can disconnect incoming calls in many other and easier
ways than with AT commands.
Use syntax like this and let me know:
echo -e "AT+CFUN=?\r\n" > /dev/ttyUSB0
I'm currently doing a project where I have to interact with a circuit I made through the parallel port of a computer. However, my computer doesn't have a parallel port so I borrowed a Parallel to USB adapter cable. The cable didn't come with any drivers, but it's recognized by the device manager as a "USB Printing Support" controller, under the USB section.
It seems that old parallel printers can be plugged in and work properly without any problems. So my question is, if I write a program in Java that tries to interact with a parallel port directly, will it work? And if not, can anyone give me some pointers as to what I need to do to interact with it?
Thanks.
I think you should head toward javax.comm library here.. there is also a different version that is supposed to work better, called librxtx.. take a look here (it's a pluggable replacement for javax.comm)..
I used both of them for an embedded device and they worked great, they manage serial and parallel port.. maybe also usb in your case.
I can't speak for parallel or Java but I've done something similar with serial-via-USB and C#. In that case it was exactly the same as a native controller. YMMV.
As for testing things: get an old dot-matrix printer (and put it in hex dump mode if you really want the nitty-gritty).
If you really want drivers for the thing, find a utility (I think the windows device manager can do it) that gives you the vendor ID and product ID numbers and from those you can look up all kinds of fun stuff (many Linux distributions have a plain text file that maps the numbers to the name of the manufacturer and what not) that plus Google should give you a driver installer.
You need java parallel port drivers which I haven't found for free. You'll have to pay for the driver for Windows.
I think there might be some free drivers if you use Linux.
USB "parallel port" adapters and cables generally aren't. They contain chips that emulate USB printers and send the print data out the parallel port like it might be sent to a similar printer using a parallel (printer) port.
Unless the device you have is actually a printer, there are probably very few (if any) adapters that will work.
There are ways of attaching GPIO "parallel"/bus pins into USB including certain FTDI chips, UARTs and various microcontrollers. If you can write software to use one of these, it could let you drive arbitrary circuits the way olde PC parallel ports were (not through the same MMIO, though).
Is there a way to determine programatically if a particular directory is actually remotely mounted? Can this be done with Java, and if not can it be done with native C code over JNI?
Since this is Java it could be running under Linux or Windows or Mac, so a proper solution needs to address all these platforms. (Again if its multiple separate solutions with C over JNI thats ok). And there may be different cases like with NFS or samba or anything else.
Thanks.
for Linux, and possibly Macintosh, you can use system library through JNI.
The relevant system call is getmntent, described here.
There is a field in mntent you can use to check to see if mount point is from device or a server, mnt_fsname, in a similar field you can get filesystem type, `mnt_type"
For Linux, you can parse /etc/mtab to find the filesystem type (nfs, smb, etc.) and match it against known network filesystem types in your program.
EDIT: column 2 is what you want in /etc/mtab
I need that as well and might end up implementing it using this command:
df -k
That works under Linux, Mac OS and Solaris.
Maybe this is something else that will be added to JDK 7 since they're also going to support symlinks.