I am using rxtx api to read data from a GPS device over a com port. Right now I'm finding the correct com port by reading a config file and looking for the port listed. The problem that I'm having is that if the device is unplugged the com port could change then the user has to know to change the config file. I wrote an app similar to this in c# and was able to list the windows device name instead of the com port and I cycled through the com ports until the device name matched the name in the config file. Using that method nothing in the config file has to change even if the com port being used changes. Is there a way to do that with the rxtx api?
Thanks in advance!
If anyone is interested...
I created a windows service in C# that monitors a socket. If a client connects to that socket the service gathers port name, and device id that is on that port and sends the data in a string over the com port the client can then parse apart the string to get the data it needs.
In my case the string being passed is:
"ACPI\PNP0501 *PNP0501 ,COM1 ,PCI\VEN_8086&DEV_29B7&SUBSYS_02111028&REV_02 PCI\VEN_8086&DEV_29B7&SUBSYS_02111028 PCI\VEN_8086&DEV_29B7&CC_070002 PCI\VEN_8086&DEV_29B7&CC_0700 ,COM3 ,USB\Vid_067b&Pid_2303&Rev_0400 USB\Vid_067b&Pid_2303 ,COM5"
When I parse it I can see that ACPI\PNP0501 *PNP0501 is the device id for COM 1, there are three device id's for COM3, and two device ids on COM5.
This may not be the best way to handle this but it is good enough for my needs and it saved me from JNI. :)
CommPortIdentifier.getPortIdentifiers lists all ports in the system that are usable by the Javacomm API. Iterate through them to find the port your device is connected to.
If you want to get the name associated with the device on the COM port (particularly if a driver is installed to provide it), you'll have to do so with a smidge of the dreaded Java->Native Interface to talk to the Windows APIs that gather this information. C# is nice, in that this information is gathered and provided to you, but in Java you have to go this extra step.
Windows Function Discovery may prove useful. I'm not certain exactly what API provides this functionality.
Related
I have created an application which sends SMS using Java.
Whith this, I must enter the com port number of dongle manually to code segment.
I would like to do this automatically using code.
How can I do this?
You may want to have a look at jUSB, which provides an API for USB programming. Get a Host from a HostFactory, iterate over it's Buses, and walk the device tree (you can get the number of devices from each Device, #0 is usually the device itself). Then you just need to find out what kind of Configuration your device has and search by that.
Is there any way I can read hyper-terminal data in JAVA to display it in a desktop software.
I am using hyper-terminal with a weighing machine connected with a port COMM 3.
I am not able to get how to read the data from it and how to display it into a screen of desktop software.
normally you can read a hyper terminal like all other com Ports.
Same times you must send a specified symbol to the device. This you will find in
in the device data sheet.
Here is an example to read a com Port.
Com Port
I am trying to create a java program making use of SSDP to get the list of IP's of the systems connected to a server. Is it possible? If so can anyone tell me the method? Because as per I read they have just mentioned we can find the particular service over the network not all the services.
thanks in advance
The idea of "IPs being connected to a server" doesn't really match what happens in SSDP, but you can search for all services and devices that advertize over SSDP in a given local network: use the search target ssdp:all instead of a specific service type string when you send your M-SEARCH message.
If you are thinking of building this from scratch, I suggest using a UPnP (or SSDP) library/framework: it'll probably make life easier.
I want to develop an application that use the Linux Bluetooth API Bluez by mean allow an Android device to send and receive data.
For the PC side i have looked at this code:
http://people.csail.mit.edu/albert/bluez-intro/x502.html
because Android use RFCOMM protocol, or i guess that since is impossible to set manually the protocol.
Since in Android is only possible to use the Java API (Bluez API locked) and the SDP in not working very well i have to use this call:
InsecureBluetooth.createRfcommSocket(BlueDevice , Channel , false);
When i set the channel for example to 0xC (12) that is one of the channel returned by the command:
sdptool browse local | grep Channel
the android application can connect correctly to the PC.
The problem is that i can't figure out what are the parameter to allow the two applications to communicate. To the PC side i have only a port number with value 1. To the Android side i have a channel that is assigned to a service available by SDP. But SDP is not working in Android so how i can do that ?
Any help is appreciated. Thanks
I have solved in this way:
For the PC side using the SDP record. We have to record the service to a well know channel that must be FREE, i mean not used by other service. To chek it do the command:
sdptool record local
The code to do that is at http://people.csail.mit.edu/albert/bluez-intro/x604.html
Section Example 4-9. Describing a service
This two line must be added after // set the general service ID
// set the service class ID
sdp_list_t service_class = {NULL, &svc_uuid};
sdp_set_service_classes( record, &service_class);
and we have to change the channel to one not used by other service. For example the channel 1 :
uint8_t rfcomm_channel = 1;
Now that we have something listening to the PC side we have to connect with the android device directly to the channel one by the well know reflection method because unfortunately the SDP now work at all in android.
Method bluetoothConnect;
bluetoothConnect = BlueDevice.getClass().getMethod("createRfcommSocket", new Class[]{int.class} );
CommunicationChannel = (BluetoothSocket) bluetoothConnect.invoke(BlueDevice, 1);
CommunicationChannel.connect();
Of course BlueDevice is a device discored by the startDiscovery() method and the "1" stand for channel 1.
I know this doesn't answer your question, I think bluecove (http://bluecove.org/) would be better choice for this. It supports most operating systems, and provides decent library for Java.
I don't think bluez will work for Windows, you need a WIDCOMM or BlueSoleil stack for it, and bluecove will use appropriate stack for you.
I wish to connect 10 usb modems to a windows/linux pc and send AT comments to them to send sms and receive sms from them. Is this possible in Java?
I think it is possible. You just have to know the COMM port ID for each modem. I do not know pure java way to discover these IDs. So, you need some platform specific way (e.g. WMI on windows or some command on Unix). But once you have ID it should not be a problem.
Assuming the USB modem implements a serial interface, it should get a COMM port id. If so, you can use RXTX to talk to the model.
afaik, you can use serial communication while talking to usb devices as long as device hardware contains an ftdi chip or so. I used a c++ serial lib in a Qt project, talking to an Arduino connected on a usb port. arduino appears as a com device.
otherwise, you may look at the jusb project: http://www.ibm.com/developerworks/library/j-usb/index.html