Sending a file in NXC

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: Sending a file in NXC

Post by muntoo »

doc-helmut wrote:muntoo,
no, what I mean are program(s) which let me automatically store a file (created by my NXC program) into a PC folder (sent by USB), e.g. every time when I press a specific NXC button.
Ah, OK.

Here would be my approach:

Use the NXC function GetUSBOutputBuffer() and write data to it using some File Transferring Protocol you'll have to implement/create.

Have a program on the PC-side running continuously in the background (resource hog :) ), receiving input from the USB. Your "FTP" should let it recognize when the data is a new file/etc.
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Sending a file in NXC

Post by HaWe »

using some File Transferring Protocol you'll have to implement/create.
Have a program on the PC-side running continuously in the background...
that was the problem described in my post -
how exactly? - that was the question!
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: Sending a file in NXC

Post by muntoo »

doc-helmut wrote:
using some File Transferring Protocol you'll have to implement/create.
Have a program on the PC-side running continuously in the background...
that was the problem described in my post -
how exactly? - that was the question!
I might have been wrong about the Fantom SDK (or not, I don't really know ;) ), but look right here.

Then, it's just the FTP you make. Here's one really unoptimized one I just came up with in 4.2 seconds:

Code: Select all

// "Random" values. :)
#define BEGIN 0x42
#define NEW_BYTE 0x13
#define BYTE_RECEIVED 0x0D
#define END 0x2A
PC-Side:

Code: Select all

bool nextIsNew = false;
std::string buf;

while(!newInput());
while(receive() != BEGIN);
while(1)
{
    if(newInput())
        i = receive();

    if(nextIsNew)
    {
        Send(BYTE_RECEIVED);
        buf += (char)i;
        nextIsNew = false;
    }
    else if(i == NEW_BYTE)
    {
        Send(i);
        nextIsNew = true;
    }
    else if(i == END)
    {
        Send("Why? Why have you ended this?!");
        break;
    }
    // This is impossible. Well... unless a butterfly flaps its wings.
    else
    {
        Send(END);
        commit("suicide");
    }
}

NXT-Side:

Code: Select all

Send(BEGIN);
for(i = 0; i < buf.length(); i++)
{
    Send(NEW_BYTE);
    while(receive() != NEW_BYTE);
    Send(buf[i]);
    while(receive() != BYTE_RECEIVED);
}
Send(END);
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: Sending a file in NXC

Post by h-g-t »

Sivan Toledo has been carrying out experiments into BT communication between the NXT and a pc. If I have read it correctly, the NXT must be the master if you it want to send messages. Unfortunately, he does not give details of the programs he was using. http://www.tau.ac.il/~stoledo/lego/btperformance.html
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.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Sending a file in NXC

Post by HaWe »

I don't have any experience using fantom and as I wrote I have no idea how to write a program like you suggested running on the PC side using fantom.
It must be something already finished (EXE file).

And I want to transfer complete files, not just bytes.

One idea: imagine that it might work something like the DOS command
XCOPY source destination
* and ? allowed as jokers.

a) Running on the NXT, it should be able to use it like
XCOPY.rxe ????.wpt d:\myfiles\programming\project\FFT\*.*
(of course the routines used by XCOPY.rxe actually should be available as a function
void XCOPY(string source, string destination){...}
used by NXC)

b) Other way round if running on the PC, it might pick up files from the NXT flash drive - mounted e.g. as drive N: or \\NXT\A: - and copy them to a PC directory.
I.e. functionality of the NxtExplorer, but sort of remote-controlled by the NXT.

In these cases this PC-program must be started by a NXT command via USB to the PC:
C:\nXtCOPY.EXE N\????.wpt d:\programming\project\FFT\*.*
or
C:\nXtCOPY.EXE \\NXT\A\????.wpt d:\programming\project\FFT\*.*
(NXT Flash disk accessed like a local USB drive OR mounted like a PC network drive, given a drive letter like a PC drive)

Of course there possibly could be many other ways to copy files from NXT to PC "in a whole"...
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: Sending a file in NXC

Post by h-g-t »

Well, there are already NXC codes to send messages via BT and I believe there is also a system call you can use to send files the same way.

I am no expert on this subject but is seems to me that once the NXT has been set as the master, it should be possible to send a file and have the pc respond in the same way it would do for any other BT communication involving information.

What happens when a mobile phone or pda initiates a BT call to a pc? Would the pc not respond in the same way?

http://blog.ashfame.com/2008/01/bluetoo ... -computer/
http://www.ehow.com/how_2244416_phone-c ... tooth.html
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.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Sending a file in NXC

Post by HaWe »

well, an answer like "I believe there is also a system call..it seems to me ... it should be possible to send a file ...would the pc not respond in the same way?" actually doesn't really help me along.
Show me your code, that's what I'm looking for, - and I'll try it!
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: Sending a file in NXC

Post by muntoo »

Can anyone [John] post a link to the SVN Repository to NeXT Explorer's source code? If we can figure out how to download a file from NXT->PC, the rest should be "easy".

NXT tells PC to download a specific file using the NXC API function I mentioned earlier, PC somehow reads it, and gets the file.
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: Sending a file in NXC

Post by h-g-t »

I hope that the code from Explorer will help but I suspect that it uses processes initiated by the PC to get the files.

There is reference in the NXC API to 'INTF_SENDFILE' which is described as 'Send a file over a Bluetooth connection'.

Unfortunately, there are no examples and it is not mentioned in John's book. In the list of low-level calls at the back he mentions a generic call which might be used to invoke this but I don't know nearly enough about NXC to try.

I attempted looking this up in the Lego SDK but got hopelessly lost and gave up!

Quote from the NXC Programmer's Guide by John Hansen :-

SysCommExecuteFunction (CommExecuteFunctionType & args) Function (+)

This function lets you directly execute the Comm module's primary function using the
values specified via the CommExecuteFunctionType structure. The structure type
declaration is shown below. The values for these fields are documented in the table
below. If a field member is shown as 'x' it is ignored by the specified display command.

struct CommExecuteFunctionType {
unsigned int Result;
byte Cmd;
byte Param1;
byte Param2;
byte Param3;
string Name;
unsigned int RetVal;
};

INTF_SENDFILE Send a file over a Bluetooth connection (Connection,x,x,Filename)
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.
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 0 guests