Open lucas-pedroso-developer opened 8 years ago
I have the same issue.
Try mine, it actually works ;-) https://github.com/xxxajk/PhysicaloidLibrary
@xxxajk Could you please turn it into a .jar file with your ammendments? Many thanks!
Certainly! I'll do that some time later today.
On Tue, Mar 28, 2017 at 7:32 PM, Chris notifications@github.com wrote:
@xxxajk https://github.com/xxxajk Could you please turn it into a .jar file with your ammendments? Many thanks!
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ksksue/PhysicaloidLibrary/issues/25#issuecomment-289936715, or mute the thread https://github.com/notifications/unsubscribe-auth/ADskzLtVSsQU6Shw_59c1yrl5Vlewn6Uks5rqZiTgaJpZM4KjcHp .
-- Visit my github for awesome Arduino code @ https://github.com/xxxajk
Thanks @xxxajk - I've build an android project that uses your library as a module and I'm getting some odd behaviour. I've a bunch of odd behaviours that I hope you (or someone could help with):
1: The readSize often returns zero? So I hit a read button and immediately TextView some values. Why is this? If we hit read again, it comes up with the data fine.
2: I've taking in ascii that I'm using scanner to convert to doubles to use in GraphView - the scanner works fine, but double conversion fails (!). Any ideas?
Happy to share code: essentially, it take Arduino uno data to a Samsung tablet to read/view ascii, then plot via GraphView. Thoughts/comments/insults welcome! C
< 0 should be an error 0 == no bytes and > 0 == number of bytes that came in
Thanks - So is it usual to have to run the method twice to get data out? We're at 9600 baud as we find that bits are often missed at higher rates, and we can see the LEDs light up saying that data is coming. But perhaps it's triggering filling a buffer, and it doesn't get 'transferred' until the next read. Not sure.
I fixed point 2, using String[] s = str.split(","); etc.
What you may want to do is run the data gathering in a separate thread at a low priority that sleeps for 1ms, and has a way to be told to quit. While it loops you store data as you need it someplace, perhaps a queue, or a structure, or whatever you need. For a structure, when you have the amount of data you want, you can wake up the task to tell it so, or set a flag, or whatever. That is how I use it for structured data.
Yes it is normal for it to return no data-- obviously it has not arrived yet, so there is nothing to read.
I see. Is there a sample you could share on how that should work? That would be an excellent addition to your fork! It takes 4s-20s (worst case) to complete collection. Again, super helpful! C
Sure, here's something brief. It has the nice advantage that you get a double buffer, which helps prevent data loss. Let's pretend you want 3 bytes at a time...
import com.physicaloid.lib.usb.driver.uart.ReadLisener;
import com.physicaloid.misc.RingBuffer;
private RingBuffer mBuffer = new RingBuffer(1024); // Adjust to your needs
private ReadLisener ReadL;
then in your class...
public boolean check_data() {
int i = mBuffer.getBufferdLength();
if(i > 2) {
byte[] buf = new byte[3];
mBuffer.get(buf, 3);
// do something with the three bytes...
// This allows the target to tell us to close.
// if(buf == some kind of pattern for exit) return true;
}
return false; // keep running.
}
public Runnable _check_data = new Runnable() {
@Override
public void run() {
// Don't hog the CPU. Only run on Idle time.
// This nice trick gives this thread the lowest possible
// priority. You may or may not want to raise it a little bit,
// but that depends on how much CPU you want to waste in this thread.
android.os.Process.setThreadPriority(-20);
do {
if(check_data()) {
// Exit this thread
break;
}
} while(ReadL != null);
}
};
After serial is started, perhaps in your onCreate()
or someplace else...
ReadL = new ReadLisener() {
public void onRead(int i) {
byte[] buf = new byte[i];
mSerial.read(buf, i);
if((mBuffer.getBufferdLength() + i) > mBuffer.getRingBufferSize()) {
i = mBuffer.getRingBufferSize() - mBuffer.getBufferdLength();
}
if(i > 0) {
mBuffer.add(buf, i);
}
}
};
mSerial.addReadListener(ReadL);
new Thread(_check_data).start();
Two ways that this shuts down the thread:
ReadL
becomes NULL
HTH 8-)
Hey guys, I used this library in my project , it worked very well with arduino Uno , but this time I used the arduino mini pro 5V 328 `mPhysicaloid = new Physicaloid(this); mPhysicaloid.upload(Boards.ARDUINO_PRO_5V_328, "/sdcard/arduino/Blink.hex"); mPhysicaloid.setBaudrate(57600); if(mPhysicaloid.open() ) {
mPhysicaloid.addReadListener(new ReadLisener() {
@Override
public void onRead(int size) {
byte[] buf = new byte[size];
mPhysicaloid.read(buf, size);
}
});
},` but connection won't open, I installed other applications and i can read the output of the arduino mini but i can't in my app, i don't know why this happen.
@xxxajk could you please post the link for your .jar or give more details of how to use that library with Android studio?
https://github.com/xxxajk/PhysicaloidLibrary
There will be more interesting improvements coming up, such as connection via ESP8266. That will give you OTA on android to ESP8266 and/or/arduino connected to ESP.
Nice @xxxajk I appreciate this nice job but isn't there a packet .jar file that i can use on Android studio? I am not really skilled with java and I a unsure of how to import this library there if not by dragging the jar to the app libs folder. I found this d2xx.jar there but I'm not sure if it is the right jar.
Sorry for the newbie questions, I am aware i could simply make my own .jar somehow or just use the way it is there possibly.
Well, first off, I never use android studio. From my experience, you should be able to add it as a library project and it should build when you build your android project.
I start use this library in my project two months ago, it worked very well, but yesterday the library stop work, in this condition "if(mPhysicaloid.open())" don't open, i don't know why this happen.
My manifest code
My Activity code