using UART with STM32f746g-DISCO in MicroEj - java

I'm trying to use UART serial communication with MicroEj in STM32F7 using java, and I've got exception throw opening the Com Port. Here is the simple code to open a connection:
private static final String CONNECTION_STRING = "comm:com42;baudrate=9600;bitsperchar=8;stopbits=1;parity=none";
try {
CommConnection comm = (CommConnection) Connector.open(CONNECTION_STRING);
} catch (IOException e1) {
e1.printStackTrace();
}
And here is the exception:
java.io.IOException: ECOM-COMM: Invalid connection descriptor.
I think there might be some problems with the CONNECTION_STRING but I couldn't find any examples. anyone can help me?

Try with com51.
You can find the correct value in launch parameters/Configuration tab/Libraries/ECOM/Comm Connection

Related

pass Ctrl+] over socket connection using java

I have connected telnet server using socket, I am passing various command using this connection, now as per my requirement after getting output I have to pass command like "Ctrl+]" over socket using java.
can you anyone explain me how I pass the same command using java.
below are the method for reference:
public void logout(){
System.out.println("TelnetHelper : Inside logout()");
try {
telnetWrapper.send("\u001d");
telnetWrapper.send("quit");
} catch (IOException e) {
System.out.println("logout() : IOExcepton - "+e.getMessage());
} catch (Exception e) {
System.out.println("logout() : General Excepton - "+e.getMessage());
}
System.out.println("TelnetHelper : logout() Finished");
}
But this is not working in my case
Just close the connection, I suppose that would be telnetWrapper.close();
I think you may want to send \u001b ...
http://wiki.bash-hackers.org/scripting/terminalcodes

How to create a "FTPS" Mock Server to unit test File Transfer in Java

I have a CreateFTPConnection class which create a FTPS connection. Using this connection, files are transferred. Here is the code of TransferFile class
public class TransferFile
{
private CreateFTPConnection ftpConnection;
private FTPSClient client;
public TransferFile(CreateFTPConnection ftpConnection) {
this.ftpConnection = ftpConnection;
this.client = ftpConnection.getClient();
}
public void transfer(Message<?> msg)
{
InputStream inputStream = null;
try
{
if(!client.isConnected()){
ftpConnection.init();
client = ftpConnection.getClient();
}
File file = (File) msg.getPayload();
inputStream = new FileInputStream(file);
client.storeFile(file.getName(), inputStream);
client.sendNoOp();
} catch (Exception e) {
try
{
client.disconnect();
}
catch (IOException e1) {
e1.printStackTrace();
}
}
finally
{
try {
inputStream.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}
I have to write jUnit Testcase for this class. For this, I have to create a FTPS Mock Server connection and have to use that connection to test the File Transfer. So can anyone plz give me any idea of how to make FTPS Mock Server and do the test case. I googled on this, but what I get is on FTP or SFTP, not FTPS. Please help me.
You might find this useful MockFTPServer
The issue is that these mock servers don't implement the TLS portion from what I can see. You may need to do a little work to allow connections via TLS.
You should be able to search around and find some articles here on SO about dealing with certificates, (or in some cases, bypassing them) for the sake of your testing.
Here's another Article that goes through the steps of creating a basic FTP server Test.
Short of a full blown FTP server (Apache http w/ mod_ftp add on), there doesn't seem to be anything useful to do this.

Test SNMP connection availability

Is there a way to test SNMP connection availability in java? I am using Ireasoning api.
try {
long timeTicks = System.currentTimeMillis();
while (timeTicks > 4294967295L) { timeTicks-= 4294967295L; }
SnmpTrap trap = new SnmpTrap(timeTicks, new SnmpOID(oid));
try {
InetAddress inet = InetAddress.getByName(agentIp);
agentIp = inet.getHostAddress();
} catch (Exception e2) {
System.out.println("SendSNMPTrap::sendVersion2c unable to resolve "+agentIp+" to real IP. Exception="+e2.toString());
}
trap.addVarBinds(vb.getVarbinds());
SnmpTrapSender.sendTrap(destHost, port, trap, true, community);
} catch (Exception e) {
logger.error("SendSNMPTrap::sendVersion2c Exception="+e.toString());
result = false;
}
The best way to test the availability of any resources to try to use it. You have to deal with failure when you use it anyway. Why write the same code twice? And why try to predict the future?
You can use INFORM PDU instead of TRAP PDU. This way the Trap Receiver will send you a response back to acknowledge that it has received the INFORM.

How to handle java.rmi.UnknownHostException

I'm working with Eclipse and the code below is the code that I use for RMI initialization.
public void init(String serviceName) throws RemoteException {
try {
String host = InetAddress.getLocalHost().getHostName();
String url = "rmi://"+ host + serviceName;
Naming.rebind(url,this);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
I'm getting an UnknownHostException.
Since I'm new to this issue, the question may be simple, but I could not handle it.
Thanks in advance.
UnknownHostException means it can't find that host at the network level. There's no handling this type of exception because it means something is broken. I'd print out the URL sent to RMI. It should look something like this:
//localhost/ServiceImTryingToAccess
If you didn't put a leading "/" on your service it might be:
//localhostServiceImTryingToAccess
And that certainly would create an UnknownHostException. You really don't need to use InetAddress.getLocalHost() as you could just simply do:
String url = "//localhost" + serviceName;
Also notice I dropped the rmi:// scheme portion of the URL. It's in the docs that's not needed.
http://docs.oracle.com/javase/1.4.2/docs/api/java/rmi/Naming.html

Client Exception: Software caused connection abort: recv failed

I've been playing around with my Java client app. Behaviour is very similar to this post (and others):
java.net.SocketException: Software caused connection abort: recv failed
As yet I've not found the answer - hence this post. I have a idea what is wrong but I'm not sure what to do about it.
The protocol is simple - read some data in, send back an ACK and repeat (until terminted).
I've been looking at what is going on with WireShark, and is seems the TCP window is filling up. I'm performing a flush() on the DataOutputStream (For the ACKs) but doesn't change the fact at after a while I get this exception (I can see on WireShark that there is always a window problem right before the Java exception).
So how to I make sure in Java that my TCP windows/buffers are clear (Which I think is the root cause of the problem?) seems to be no flush on the DataInputStream. Make be wonder that whilst I might be reading it the TCP stack is filling up.
Many Thanks
Mark
I've attached the basic code calls below:
public void connectToServer()
{
//Create socket connection
try
{
if (lSocket == null)
{
lSocket = new Socket("localhost", 7651);
lSocket.setSoTimeout(0);
lInDataStream = new DataInputStream(lSocket.getInputStream());
lOutDataStream = new DataOutputStream(lSocket.getOutputStream());
}
}
catch (UnknownHostException e)
{
System.out.println("Unknown host: localhost");
}
catch (IOException e)
{
System.out.println("No I/O");
}
}
public void readSocket() throws IOException
{
//Receive data from ROS SerialtoNetwork server
if (lSocket != null)
{
lInDataStream.readInt();
lInDataStream.readFully(cbuf);
lOutDataStream.writeBytes("Ack");
lOutDataStream.flush();
//String lstr = new String(cbuf);
//System.out.print(lstr);
//System.out.println("");
}
}
public String getDataBuffer()
{
String lstr = new String(cbuf);
return lstr;
}
This indicates persistent network errors. There are several (repetitive) MSDN article on this error, e.g. this one.

Categories