Push a file

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
mcsummation
Posts: 220
Joined: 23 Jan 2012, 17:07
Location: Round Rock, TX

Push a file

Post by mcsummation »

I have a file written on my local NXT. How can I push the file to a remote NXT (over BT). It ought to be a Remote... command but I'm not having any luck finding it. (Once I have the file over there, I know how to launch the program that will read it and execute it.)
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: Push a file

Post by h-g-t »

If you want to do it yourself then page 43 of this guide shows you how -

http://cache.lego.com/downloads/educati ... _US_low.pd

I have seen something on sending files between NXTs and will post the reference if I can find it.


Update - there was a thread on this about a year ago but it just fizzled out without any conclusions -

https://sourceforge.net/apps/phpbb/mind ... ile*#p4375
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: Push a file

Post by afanofosc »

So, this may be possible using the enhanced firmware's CommExecuteFunction system call as h.g.t mentioned. I've never tried it but when you use the built-in menu system on the NXT interactively to choose a file and tell the NXT to send it to another NXT it uses the SENDFILE Comm function to do that just like the CommExecuteFunction system call allows you to do from a running program. It would not hurt to try this. Whether it will work the same as it does when executed interactively is a question worth exploring. I don't know if sending a file from one NXT to another via the interactive menus requires any sort of user interaction on the receiving end. If it does then this probably won't work non-interactively.

In theory, you could use the Remote* API functions that implement the system command protocol routines that let a PC upload a file to an NXT. These are completely untested and some of them currently suffer from an API header defect that I just fixed which is not yet available to the general public.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mcsummation
Posts: 220
Joined: 23 Jan 2012, 17:07
Location: Round Rock, TX

Re: Push a file

Post by mcsummation »

I've got this working and will post back the code later in the day. I'm going to write a macro so it isn't so ugly looking in the using source code.

No action required on the receiving end of the connection, just like the receiving end doesn't require action for "connect Bluetooth", "execute remote program", and probably several other actions.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: Push a file

Post by afanofosc »

I'm glad to hear that it worked as you hoped.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mcsummation
Posts: 220
Joined: 23 Jan 2012, 17:07
Location: Round Rock, TX

Re: Push a file

Post by mcsummation »

Here's the code for "sending a file from one NXT to another NXT over a Bluetooth link":

Code: Select all

inline int BTSendFile(byte Conn, string FileName) {
#ifndef JHS_CEFT
#define JHS_CEFT
            CommExecuteFunctionType JHS_CEFT_args;
#endif
            JHS_CEFT_args.Cmd = INTF_SENDFILE;
            JHS_CEFT_args.Param1 = Conn;
            JHS_CEFT_args.Name = FileName;
            SysCommExecuteFunction(JHS_CEFT_args);
            until (RemoteConnectionIdle(Conn)) Yield();
            return JHS_CEFT_args.Result;
        }
I have this in a program and it runs properly.

The one caveat is: It won't replace a file. You need to use RemoteDeleteFile first. Then wait (I'm waiting 1000 ms) for the Delete to complete before sending over the new file.

Edit: I made an error in the waiting of the RemoteConnectionIdle statement. :oops:
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests