Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

transfer data from PC to electronic device in what format?

Status
Not open for further replies.

oem_odm

New Member
Hi all,

What's the best format of data exported from PC software into an electronic product (via USB).

The product is an electronic game counter. Players type in their scored points and select their name, then the level they finished. Later on, the device is connected to USB to import score data (in TXT format), PC software displays graph's of who scored what where etc. Using the same software, user's can add levels, and add players (and much more).

What I don't understand is in what format data should be exported from the PC software so the device can use it? Data would be something like:

>> admin
device name,my electronic pet
password,hellokitty

>> players
john,322
jeremy,300
james,50
terry,41
sarah,392

>> stages
Level 1,16
Level 2,15
Level 3,300
Centre point,245

So, their would be a list of players (anything from 2 to 200), stages (same, 2 to 200) - Their will be sub-categories as well. The device itself will have a USB connection, a simple Dot Matrix LCD, and an 8-bit MCU with C-Language code/software. What I'd like to know is how the PC software should export the above data?

For example, it could be exported in a TXT file, and when for example the players need to be displayed 1 by 1 on the LCD - the MCU will search in TXT file for PLAYERS sub-section, then display Line 1/row 1, then row 2, etc etc (I don't know the right terms) - at the end of PLAYERS, i guess some sort of END or return to row 1 prompt?

But then I think... TXT file is not appropriate - some other file extension would be easier for the MCU to work with...

Hoping for some insight - many thanks
 
Plain text is proobably the easiest all round - dead simple to deal with either end, and the absolute easiest format for trouble shooting (as you can simply hang a terminal program on it).

Bear in mind you probably don't need to transfer full name strings, just A, B, C etc. is probably all you need to do.
 
Hello and thankyou Nigel,

So you mean a PC can output to the device a TXT file. In that file can be "strings", so the MCU will refer to string A for PLAYERS, and string B for STAGES etc.

right?
 
Hello and thankyou Nigel,

So you mean a PC can output to the device a TXT file. In that file can be "strings", so the MCU will refer to string A for PLAYERS, and string B for STAGES etc.

right?

Yes, you're as well to stick with ASCII strings as it avoids any potential problems with control codes - using single character 'indexes' makes it simpler, as you don't need to continually check for an entire string, and it's much faster to send as well.
 
Hi Nigel,

So, lets say my product LCD at a particular point in its use needed to show the first PLAYER NAME, the MCU would instruct something like:

Show sub-string 2, line 1, from file.txt
(when the user presses the NEXT button - the MCU would instruct something like)
Show sub-string 2, line 2, from file.txt

File txt would be something like this:

1
device name,my electronic pet
password,hellokitty

2
john,322
jeremy,300
james,50
terry,41
sarah,392

3
Level 1,16
Level 2,15
Level 3,300
Centre point,245

....one more question. The TXT file exported from PC software for the PLAYER string will have for each line the PLAYER NAME, and their SCORE so far, something like:

john,322

Both are on the same line, seperated by a comma. How does the MCU pick out only the name, or only the 322. For example I might like to display the score of Player John, the MCU would need to instruct something like:

Show sub-string 2,line 1, "data after comma 1" < ?

(you're probably laughing now...)

thanks again
 
You could, transfer the data as Nigel suggested, with character indexes, and then you could look for a delimiter, in your case a comma, you may be able to find a simple CSV parser for C using standard char indexing. (Comma Seperated Values), the other option is to use an index for the player and score, so Player[0] score will be Score[0].

Be aware though, of the memory limitation of your PIC, if you are only requesting a single line then it will be fine, if you are requesting the whole text file to be put into an array then you may have issues with memory.
 
You could, transfer the data as Nigel suggested, with character indexes, and then you could look for a delimiter, in your case a comma, you may be able to find a simple CSV parser for C using standard char indexing. (Comma Seperated Values), the other option is to use an index for the player and score, so Player[0] score will be Score[0].

Be aware though, of the memory limitation of your PIC, if you are only requesting a single line then it will be fine, if you are requesting the whole text file to be put into an array then you may have issues with memory.

Hi Wilksey - thanks

So if my players and scores were:

john,322
jeremy,300
james,50
terry,41
sarah,392

How would I fetch 322 to show on the LCD (bearing in mind the 322 score could be anything for Player John, and not always 322 - and even "john" could be sarah)

Get value, file.txt,line1,score

?
 
Ok, so, your data doesn't have to be fixed, thats the whole point, you could hardcode the values then.

I dont know what requests what, but from what you have said, if the "character index" is "2" it will parse the players and scores, until it hits a single character of "3" then it will parse some other data.
So, your players and scores are in a single line format, so you are either sending each line in turn or seperating the lines, either way you will end up with a comma seperated list of 2 indexes.

Index 1 would be player name, so "John", Index 2 would be player score, "322", as long as your seperator is just a single "," and this character would not be used for anything else in the player name or score as i'm guessing it wont, then all you would need to do is (in generic C code)

void ParseData(char* RecData)
{
int i = 0;
char* Player;
char* Score;
char Seperator = ',';
bool Got_Seperator = false;
for(i=0; i < strlen(RecData); i++)
{
if(!Got_Seperator)
{
if(RecData != Seperator)
{
Player += RecData;
}
else
{
Got_Seperator = true;
}
}
else
{
Score += RecData;
}
}
_PutToLCD(Score);
}

Something like the above code will work in seperating the values, it may be slightly incorrect, but you should get the general idea.
_PutToLCD is your own compiler function for putting the data to the LCD.

RecData would be the character array passed from your receive function, i'm guessing USART?
Obviously you will need to disregard "\r\n" (carriage return line feeds), and filter by character index, which could be done for checking for a line only 1 character in length, or a line without a ",".

Does that help you out at all?

Wilksey
 
Hi Wilksey - wish i could knock that out as quick as you :p

I understand you...each player will have their score (and possibly other measurements) all on the same line, each seperated by a "," - so each one could be indexed. So if the MCU had to pull the score of James to the LCD, and the imported TXT file was:

File txt would be something like this:

string 1
device name,my electronic pet
password,hellokitty

string 2
john,322
jeremy,300
james,50
terry,41
sarah,392

string 3
Level 1,16
Level 2,15
Level 3,300
Centre point,245

Then the MCU would do something like

Go to file.txt, goto string2, goto line 3,goto index 2, put to lcd

in very basic terms... right?

(in fact every player will have their own id number (on the same line))
 
Essentially, yes, it's just the coding to actually do this which is where the "fun" starts!

You could even just read in one line with all the players and scores as one long line.

Player1,200,Player2,300,Player3,400, etc.

So for each comma you know the left most value is the player name, and the right most value is the score.

Wilksey
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top