Pages: [1]   Go Down
Author Topic: No data from COM (problems with getting data)  (Read 802 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello! I'm new for this forum, can you please help me?

I'm trying to get values from my Arduino Leonardo's AnalogPort through USB (COM port) at my PC. "Arduino" programme and Processing works well, I can make plots and calculations, but the task is to create an independent application (exe). I've tried many tutorials and guides, such as http://www.negtronics.com/simplot and others. There is no data from these aplications  (the plot is empty). In every application I usually get messages like "COM port is open" but unfortunatelly I haven't data at all. I have Windows 7 x32 and I tried to use my friend's computer, but it was unsuccessfull.

This is a part of my diploma research. I do research using friction test machine and values are analog, I need to analize data at PC and present my work at June.

Thanx for your advise and help.
Logged

DELHI
Online Online
God Member
*****
Karma: 7
Posts: 814
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you post your code.
I cant understand What you are doing.
Code:
, but the task is to create an independent application (exe)
What is this meant by??
Logged

AMPS

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 625
Posts: 34106
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@AMPS
Quote
What is this meant by??
An exe is a file extension for an executable file on a windows PC.

@levh92
Are you saying that you can use the Processing language successfully?
You can run Processing apps with a double click you know if you save it as a java app.
Do you then get nothing when you try these other applications?
Are you sure you have set up the serial port correctly in these other applications?

If you have checked these then we need to see the code that is running on the Arduino. If it is long or complex then a cut down version to see the problem is best. Then we need to know exactly what application you are trying.
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Or, you can use Ardulink.

This is a tutorial on how you can do it.
http://www.ardulink.org/how-to-manage-input-from-arduino/
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I've tried tu use arduilink and ALProtcol. I'm able to get event from Digital PIN in a GUI as in  http://www.ardulink.org/how-to-manage-input-from-arduino/.
But i failed to do this in a no GUI code. The listener don't get any events. I think that i haven't implement correctly main method to get system event

Any one have an example of this use case or can help me?

Thanks =
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you post your code?
What if you use a RawDataListener? Can you receive messages from Arduino?

Now I'm not with my arduino and I cannot post an example but I'll do asap.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I've test with this small piece of code :

Code:
package com.enduchronos.gettop;

import org.zu.ardulink.Link;
import org.zu.ardulink.event.DigitalReadChangeEvent;
import org.zu.ardulink.event.DigitalReadChangeListener;

public class ArduinoConnect extends Thread{
public static void main (String[] args) {

Thread mega = new ArduinoConnect();
mega.start();
}

public void run() {

String connectionPort = "COM3";
int baudRate = 9600;
Link link = Link.getDefaultInstance();
// 9. Let's go. Link it to Arduino.
boolean connected = link.getDefaultInstance().connect(connectionPort, baudRate);

//Affichage de l'état de la connection
if(connected) {
System.out.println("Arduino connected");
System.out.println(link.getProtocolName());
} else {
System.out.println("Arduino NOT connected");
}

link.addDigitalReadChangeListener(new DigitalReadChangeListener(){
@Override
public void stateChanged(DigitalReadChangeEvent e) {
System.out.println(e.getValue());
int value = e.getValue();
if(value == DigitalReadChangeEvent.POWER_HIGH) {
System.out.println("High");
} else if(value == DigitalReadChangeEvent.POWER_LOW) {
System.out.println("Low");
}
}
@Override
public int getPinListening() {
// TODO Auto-generated method stub
return 2;
}

});
}

}

I'm a beginner in java language.
I think that their is a link with the fact that i don't use awt and his event catching capabilities. Raw listener don't work too.

I've try to run classe in a thread as when we are in a awt context, but without succeed...

Thanks for your help

Jordane
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Your code seems good. You don't need for a thread. I've to try with an arduino. However I've noted you use a connection baud rate different from the default ardulink rate (9600 instead of 115200). Have you changed accordingly Arduino sketch you have to upload?

Let me know
   Luciano
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Of course, I've synchronyse connection baudrate between arduino's scketch and java code. I try to do this to listenen an IR sensor

The same code work with sensor  when i use the listener in the  http://www.ardulink.org/how-to-manage-input-from-arduino/ GUI code.

Regards
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, the problem is that between connection and the first command, Arduino needs for a while to receive messages. So you have simply to add a Thread.sleep() statement.

This code works very well (I've connected PIN 4 to PIN 2 with a simple wire).

Code:
package org.zu.ardulink.tutorial;

import org.zu.ardulink.Link;
import org.zu.ardulink.event.ConnectionEvent;
import org.zu.ardulink.event.ConnectionListener;
import org.zu.ardulink.event.DigitalReadChangeEvent;
import org.zu.ardulink.event.DigitalReadChangeListener;
import org.zu.ardulink.event.DisconnectionEvent;
import org.zu.ardulink.protocol.IProtocol;

public class InputTest {

public static void main(String[] args) {
Link link = Link.getDefaultInstance();

link.addConnectionListener(new ConnectionListener() {

@Override
public void disconnected(DisconnectionEvent e) {
System.out.println("Board disconnected");
}

@Override
public void connected(ConnectionEvent e) {
System.out.println("Board connected");
}
});

link.connect("COM19");
try {
System.out.println("wait for a while");
Thread.sleep(2000);
System.out.println("proceed");
} catch (InterruptedException e1) {
e1.printStackTrace();
}

System.out.println("start Listening");
link.addDigitalReadChangeListener(new DigitalReadChangeListener() {

@Override
public void stateChanged(DigitalReadChangeEvent e) {
System.out.println("PIN: " + e.getPin() + " STATE: " + e.getValue());
System.out.println(e.getIncomingMessage());
}

@Override
public int getPinListening() {
return 2;
}
});

for(int i = 0; i < 5; i++) {
try {
Thread.sleep(1000);
System.out.println("sendPowerON");
link.sendPowerPinSwitch(4, IProtocol.HIGH);
Thread.sleep(1000);
System.out.println("sendPowerOFF");
link.sendPowerPinSwitch(4, IProtocol.LOW);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}

try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
link.disconnect();
}
}

This is the output:

Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
5-giu-2014 20.36.50 org.zu.ardulink.ConnectionContactImpl writeLog
INFO: connection on COM19 established
Board connected
wait for a while
proceed
start Listening
PIN: 2 STATE: 0
alp://dred/2/0
sendPowerON
PIN: 2 STATE: 1
alp://dred/2/1
sendPowerOFF
PIN: 2 STATE: 0
alp://dred/2/0
sendPowerON
PIN: 2 STATE: 1
alp://dred/2/1
sendPowerOFF
PIN: 2 STATE: 0
alp://dred/2/0
sendPowerON
PIN: 2 STATE: 1
alp://dred/2/1
sendPowerOFF
PIN: 2 STATE: 0
alp://dred/2/0
sendPowerON
PIN: 2 STATE: 1
alp://dred/2/1
sendPowerOFF
PIN: 2 STATE: 0
alp://dred/2/0
sendPowerON
PIN: 2 STATE: 1
alp://dred/2/1
sendPowerOFF
PIN: 2 STATE: 0
alp://dred/2/0
Board disconnected
5-giu-2014 20.37.03 org.zu.ardulink.ConnectionContactImpl writeLog
INFO: connection disconnected

I'll modify the article http://www.ardulink.org/how-to-manage-input-from-arduino/ adding this sample code. I hope this can solve your problem.

If you do some interesting project with my library let me know, I'll be happy to post an article about it.
   Luciano
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your help

I will back to you  to present my little project throught your website contact form when it will be far advanced.

Regards

Jordane
Logged

Pages: [1]   Go Up
Jump to: