program to extract characters from a text file

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

randomguy
New User
Posts: 7
Joined: Tue Dec 19, 2017 5:20 pm

program to extract characters from a text file

Postby randomguy » Tue Dec 19, 2017 5:23 pm

i would like to know if there is a way to create an EV3 program that extracts individual characters from a .txt file and displays them on the EV3 screen
thanks a lot in advance

User avatar
gloomyandy
leJOS Team Member
Posts: 6018
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: program to extract characters from a text file

Postby gloomyandy » Tue Dec 19, 2017 11:44 pm

Yes there is.

So what have you tried so far? You need to split the task into two parts, first read the text from the file (search the web for how to read a text file in Java), then how to display the text on the screen. It is a pretty simple thing to do, why do you want to do it? Is this for some sort of school project?
leJOS news https://lejosnews.wordpress.com/

randomguy
New User
Posts: 7
Joined: Tue Dec 19, 2017 5:20 pm

Re: program to extract characters from a text file

Postby randomguy » Wed Dec 20, 2017 6:28 am

I want to make a robot that takes a string of characters from the user and not only displays them but also prints them out. Kind of like a text to print robot. I have figured out the physical printing part but can't figure out the programming. I don't know how to make the ev3 brick itself do this.
Again thanks a lot

User avatar
gloomyandy
leJOS Team Member
Posts: 6018
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: program to extract characters from a text file

Postby gloomyandy » Wed Dec 20, 2017 3:05 pm

So what is your programming experience? Have you used Java before, have you written any programs using leJOS?
leJOS news https://lejosnews.wordpress.com/

randomguy
New User
Posts: 7
Joined: Tue Dec 19, 2017 5:20 pm

Re: program to extract characters from a text file

Postby randomguy » Wed Dec 20, 2017 7:06 pm

i don't know a lot of stuff just the basic motor and sensor controls in leJOS. i do know java somewhat though.

User avatar
gloomyandy
leJOS Team Member
Posts: 6018
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: program to extract characters from a text file

Postby gloomyandy » Wed Dec 20, 2017 9:17 pm

If you know Java you should be able to work out how to read a text file, leJOS just uses the standard Java mechanisms for that. Displaying text is pretty trivial, just look at the GraphicsLCD and TextLCD classes. You can obtain instances of these classes from the LocalEV3 class. As to having a robot draw the text that is a very different problem and will depend considerably on how your robot/printer has been constructed.

Is this some sort of school/collage project?
leJOS news https://lejosnews.wordpress.com/

randomguy
New User
Posts: 7
Joined: Tue Dec 19, 2017 5:20 pm

Re: program to extract characters from a text file

Postby randomguy » Thu Dec 21, 2017 6:20 am

Thanks a lot for your reply. I really appreciate it.
Also yes this is for a school project

randomguy
New User
Posts: 7
Joined: Tue Dec 19, 2017 5:20 pm

Re: program to extract characters from a text file

Postby randomguy » Wed Dec 27, 2017 1:03 pm

I have been working on this for some time now and haven't been able to figure out some stuff. the .txt file is on my laptop. so is it possible to have one class that retrieves the .txt file and reads it and sends it to another class that is on the ev3 that has different outputs based on the letter.
(also i have figured out the printing part and how the motors should move. i just don't know how to make the ev3 print something that is on my laptop).

User avatar
gloomyandy
leJOS Team Member
Posts: 6018
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: program to extract characters from a text file

Postby gloomyandy » Wed Dec 27, 2017 2:09 pm

If you want to read files from your laptop the best way is to have two programs one that runs on the EV3 and which listens for connections and then accepts commands to print text, the other program tuns on your laptop and reads the text file opens a connection to the EV3 and then sends the text to the EV3 for printing.

The code to do this is all pretty standard Java networking. I'm sure your teacher can point you in the right direction.
leJOS news https://lejosnews.wordpress.com/

randomguy
New User
Posts: 7
Joined: Tue Dec 19, 2017 5:20 pm

Re: program to extract characters from a text file

Postby randomguy » Thu Dec 28, 2017 8:20 am

the problem is that i am on winter break right now and i cant get in touch with my teacher and we haven't learned networking yet. is there any place where i can get resources to learn how to use networking and how to send code overt to the ev3.

User avatar
gloomyandy
leJOS Team Member
Posts: 6018
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: program to extract characters from a text file

Postby gloomyandy » Thu Dec 28, 2017 9:19 am

Just google "java simple networking example"
leJOS news https://lejosnews.wordpress.com/

randomguy
New User
Posts: 7
Joined: Tue Dec 19, 2017 5:20 pm

Re: program to extract characters from a text file

Postby randomguy » Thu Dec 28, 2017 1:34 pm

here is what i have till now. for now i am just tryig to display the text on the ev3 screen. i have ran it through my ev3 but it only gives out errors. can you tell me what is wrong. and what all i need to change.

[code][/code]

public class All {
private static String z;
public static void wew()
{ int[] a = new int[50];
char[] b= new char[50];
int i=0,j;
try {
FileReader reader = new FileReader("C:\\Users\\randomguy\\Google Drive\\memo.txt");

while ((a[i] = reader.read()) != -1) {

i++;

}
reader.close();

} catch (IOException e) {
e.printStackTrace();
}

j=i;
i=0;
for (i=0;i<j;i++)
{
b[i]=((char) a[i]);
}
z= new String (b);
}

public static String kuhaName()
{
return z;
}

}

package mother;
import lejos.hardware.Button;
import lejos.hardware.Sound;
public class stuff{
public static void main(String[] args)
{
All.wew();
String what = All.kuhaName();
System.out.println(what);
System.out.println("Press any key to stop");

Button.LEDPattern(4);
Sound.beepSequenceUp();
Button.waitForAnyPress();
}
}

User avatar
gloomyandy
leJOS Team Member
Posts: 6018
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: program to extract characters from a text file

Postby gloomyandy » Thu Dec 28, 2017 7:16 pm

You can't run that program on the EV3, it is trying to open a file on the C: drive of your PC, that is not going to work. You have also not used the code tags correctly. Please use the "Preview" button to see what your post looks like before posting, without the code tags it is very hard to read the code you post. Your coder needs to be between the two tags.

I'm sorry but it is not really sensible to try and teach someone how to use Java via a forum, perhaps it would be better to wait until you are back at school/collage.
leJOS news https://lejosnews.wordpress.com/


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 2 guests