File Transfer Widget
3 posters
File Transfer Widget
ok I see the newest version (1.9.3) has a file transfer widget. and I see the latest manual has some info about it on page 20-21 of latest published manual http://www.roboremo.com/uploads/2/4/5/7/24571986/manual_v192.pdf]1.9.2
I used it to write a new "cmdStartsWith" section to use it...all my debug stuff is on because its not quite working....also, I learned everything I know about arduino coding from watching police academy movies.
If I use the example "file 5 6\na.txtqwerty" and paste that into my serial window, it works. When I add the widget to my RR interface, I can send the file, but it never works. I turned on more debug and it looks like the CMD recieved from sending from RR is "file 8 49" No filename, no data...but proper data count and filename length. It looks like either broken widget, or I misconfigured it somehow.
here is a cleaner version without all the notes and debug
I used it to write a new "cmdStartsWith" section to use it...all my debug stuff is on because its not quite working....also, I learned everything I know about arduino coding from watching police academy movies.
If I use the example "file 5 6\na.txtqwerty" and paste that into my serial window, it works. When I add the widget to my RR interface, I can send the file, but it never works. I turned on more debug and it looks like the CMD recieved from sending from RR is "file 8 49" No filename, no data...but proper data count and filename length. It looks like either broken widget, or I misconfigured it somehow.
- Code:
if(cmdStartsWith("file")) {
// Redux
//“file 5 6\na.txtqwerty”
Serial.print("CMD:");
Serial.println(cmd);
char Tdelimiters[] = "\\n";
char* TvalPosition;
String CstringOne = cmd;
int Dlen=0;
//This initializes strtok with our string to tokenize
TvalPosition = strtok(cmd, Tdelimiters);
var = 0;
while(TvalPosition != NULL){
String TstringOne = TvalPosition;
if (var == 0) {
char Fdelimiters[] = " ";
char* FvalPosition;
Dlen= 2 + (TstringOne.length());
FvalPosition = strtok(TvalPosition, Fdelimiters);
while(FvalPosition != NULL){
String FstringOne = FvalPosition;
if (Fvar == 0) {
Serial.print("This should Say File:");
Serial.println(FstringOne);
}
if (Fvar == 1) {
Serial.print("file name character count:");
Gtemp = atof(FvalPosition+0);
Serial.println(Gtemp);
}
if (Fvar == 2) {
Serial.print("This be count of file data characters:");
Serial.println(FstringOne);
}
FvalPosition = strtok(NULL, Fdelimiters);
Fvar++;
}
}
TvalPosition = strtok(NULL, Tdelimiters);
var++;
}
//file tranfer DATA
Serial.print("Filename:");
Serial.println(CstringOne.substring(Dlen, Dlen+Gtemp));
Serial.print("Data:");
Serial.println(CstringOne.substring(Dlen+Gtemp));
String SDFilenameT = CstringOne.substring(Dlen, Dlen+Gtemp);
String SDFileDataT = CstringOne.substring(Dlen+Gtemp);
// Length (with one extra character for the null terminator)
int name_len = SDFilenameT.length() + 1;
int data_len = SDFileDataT.length() + 2;
// Prepare the character array (the buffer)
char SDFilename[name_len];
char SDFileData[data_len];
// Copy it over
SDFilenameT.toCharArray(SDFilename, name_len);
SDFileDataT.toCharArray(SDFileData, data_len);
SDhandle(2,SDFilename,SDFileData);
//startswith file (redux)
}
here is a cleaner version without all the notes and debug
- Code:
if(cmdStartsWith("file")) {
char Tdelimiters[] = "\\n";
char* TvalPosition;
String CstringOne = cmd;
int Dlen=0;
TvalPosition = strtok(cmd, Tdelimiters);
var = 0;
while(TvalPosition != NULL){
String TstringOne = TvalPosition;
if (var == 0) {
char Fdelimiters[] = " ";
char* FvalPosition;
Dlen= 2 + (TstringOne.length());
FvalPosition = strtok(TvalPosition, Fdelimiters);
while(FvalPosition != NULL){
String FstringOne = FvalPosition;
if (Fvar == 1) {Gtemp = atof(FvalPosition+0); }
FvalPosition = strtok(NULL, Fdelimiters);
Fvar++;
}
}
TvalPosition = strtok(NULL, Tdelimiters);
var++;
}
String SDFilenameT = CstringOne.substring(Dlen, Dlen+Gtemp);
String SDFileDataT = CstringOne.substring(Dlen+Gtemp);
int name_len = SDFilenameT.length() + 1;
int data_len = SDFileDataT.length() + 2;
char SDFilename[name_len];
char SDFileData[data_len];
SDFilenameT.toCharArray(SDFilename, name_len);
SDFileDataT.toCharArray(SDFileData, data_len);
SDhandle(2,SDFilename,SDFileData);
}
grb352- Posts : 11
Join date : 2016-05-22
Re: File Transfer Widget
a button with the ID "file 5 11\nq.txtqwertry it!" and it doesn't work either, it must be the \n triggering a new cmd
grb352- Posts : 11
Join date : 2016-05-22
Re: File Transfer Widget
Hi,
the exeCmd() will receive only the command, for example "file 5 6"
The next bytes (for file name and data) should be read in loop().
Here I made an example for you, hope it helps:
the exeCmd() will receive only the command, for example "file 5 6"
The next bytes (for file name and data) should be read in loop().
Here I made an example for you, hope it helps:
- Code:
// File transfer example for RoboRemo
// www.roboremo.com
char cmd[100];
int cmdIndex;
boolean cmdStartsWith(char *st) {
for(int i=0; ; i++) {
if(st[i]==0) return true;
if(cmd[i]==0) return false;
if(cmd[i]!=st[i]) return false;;
}
return false;
}
int fileNameLen = 0;
int fileDataLen = 0;
char fileNameBuffer[100];
char fileDataBuffer[1024];
int fni = 0;
int fdi = 0;
void exeCmd() {
if(cmdStartsWith("file ")) { // example: cmd = "file 5 6"
char *p = cmd+5; // "5 6"
int spaceIndex = -1;
for(int i=0; p[i]!=0; i++) {
if(p[i]==' ') {
spaceIndex = i;
break;
}
}
if(spaceIndex==-1) { // RoboRemo did not send the fileName
fileNameLen = 0;
fileDataLen = atoi(p);
} else {
char *p2 = p+(spaceIndex+1);
p[spaceIndex] = 0;
fileNameLen = atoi(p);
fileDataLen = atoi(p2);
}
}
}
void setup() {
delay(500);
Serial.begin(115200);
cmdIndex = 0;
fileNameBuffer[0] = 0;
}
char c = 0;
void loop() {
if(Serial.available()) {
c = (char)Serial.read();
// routing the incoming data:
if(fileNameLen>0) {
fileNameBuffer[fni++] = c;
fileNameLen--;
if(fileNameLen==0) {
fileNameBuffer[fni] = 0;
fni = 0;
}
} else if(fileDataLen>0) {
fileDataBuffer[fdi++] = c;
fileDataLen--;
if(fileDataLen==0) {
// file received
// fileNameBuffer is a null-terminated char array
// containing the file name (if it was sent from RoboRemo)
// fileDataBuffer contains the file data
// the length of the data in fileDataBuffer is given by the value of fdi
////////////////////////////////////////
// TODO: do something with the file here
Serial.print((String)"fileName: " + fileNameBuffer + "\n");
Serial.print((String)"data:\n");
for(int i=0; i<fdi; i++) {
Serial.print(fileDataBuffer[i]);
}
////////////////////////////////////////
fdi = 0; // reset fdi
fileNameBuffer[0] = 0; // reset fileName
}
} else {
if(c=='\n') {
cmd[cmdIndex] = 0;
exeCmd(); // execute the command
cmdIndex = 0; // reset the cmdIndex
} else {
cmd[cmdIndex] = c;
if(cmdIndex<99) cmdIndex++;
}
}
}
}
Re: File Transfer Widget
Hi
Is it possible to add such a function
microcontroller sends "file (HEX 13)" - when suspending(pause) transmission of packets(block)
When the microcontroller sends "file (HEX 11)" - continues(resumes) transmission of packets(block)
https://en.wikipedia.org/wiki/Software_flow_control
is the standard for 3D printers useful for transmission G-code
Example: How is it done in the program CIMCO EDIT
thanks for RoboRemo
Is it possible to add such a function
microcontroller sends "file (HEX 13)" - when suspending(pause) transmission of packets(block)
When the microcontroller sends "file (HEX 11)" - continues(resumes) transmission of packets(block)
https://en.wikipedia.org/wiki/Software_flow_control
is the standard for 3D printers useful for transmission G-code
Example: How is it done in the program CIMCO EDIT
thanks for RoboRemo
astonet- Posts : 15
Join date : 2016-03-23
Permissions in this forum:
You cannot reply to topics in this forum