Page 1 of 2

NXC : Start Program command(?)

Posted: 17 Apr 2011, 10:36
by webstorms
Hello,

For my current project it would be pretty handy to have a command that could tell the NXT to stop the current running program and switch to an alternative one? Would this be possible, I can't find the command in the NXC references that are available.

Help appreciated. :)

Re: NXC : Start Program command(?)

Posted: 17 Apr 2011, 13:58
by mattallen37
There is no command to start another program directly from a running program.

I can think of a couple alternatives though:
  • I am pretty sure you can start a program from another NXT (through BT, and maybe now through RS-485). You could have one NXT tell the other one which program to make it start.
    You could build a state machine. Make one program that contains all of the code, and at a certain command, it could switch to running a different set of code (still the same program).

Re: NXC : Start Program command(?)

Posted: 17 Apr 2011, 17:16
by dudmaster
Matt:

There is a RemoteStart() API command. It use it alot.

Web:

Try that. Right click (in BricxCC) and select 'Help Topics'

Re: NXC : Start Program command(?)

Posted: 17 Apr 2011, 17:24
by mattallen37
Hmm, never heard of it before. I looked in both the HTML and the online help and couldn't find it. The closest I could find, was RemoteStartProgram, which is the command I was talking about (done by another NXT).

Re: NXC : Start Program command(?)

Posted: 17 Apr 2011, 17:26
by mattallen37
Actually, I can think of one possible solution; try writing to the IO map from the program.

Re: NXC : Start Program command(?)

Posted: 18 Apr 2011, 15:05
by ronmcrae
mattallen37 wrote:Actually, I can think of one possible solution; try writing to the IO map from the program.
If RemoteStartProgram() is used via BT, but a program is already running on the remote brick, then the program that you attempted to start will run as soon as the current program quits.

Thus if the same actions that RemoteStartProgram takes can somhow be emulated on the local brick then it should be possible to cause a running program to get the brick into a state whereby it'll run a different program when the present one quits.

Ron.

Re: NXC : Start Program command(?)

Posted: 18 Apr 2011, 16:39
by mattallen37
That is what I meant about using the IO map directly. However, I have only used it for more basic things (such as the program knowing if it is plugged into USB...). Perhaps John can tell us if it is possible.

Re: NXC : Start Program command(?)

Posted: 19 Apr 2011, 00:20
by muntoo
Is it possible to write commands on the BT input "message box"/whatever the heck it's called to your own NXT?

Re: NXC : Start Program command(?)

Posted: 19 Apr 2011, 02:05
by mattallen37
Well, that's what I am wondering. John said RS485 writes directly to the IO map... In that case, the FW must either be looking at the data as it is coming in, or reading the IO map to see if it contains the right string to trigger a direct command. If it is looking at the IO map, then it should be fairly simple in theory.

Re: NXC : Start Program command(?)

Posted: 19 Apr 2011, 03:51
by muntoo
CommBTWrite looks promising.

The NXC docs don't have much info, so I'll quote LEGO's SDK RXE Specs:
NXTCommBTWrite

Return Value:
Status Code SBYTE

Parameters:
Connection: Buffer
UBYTE: UBYTE array
input: input
Port. The four valid ports are 0, 1, 2, and 3.: Up to 256 bytes for writing to specified port.

[Try to make sense of that :)]

This syscall method copies data from the buffer input to an internal Bluetooth buffer and instructs the NXT
firmware to send the data to the device configured on the specified port.
If the return value is 0, the method successfully started a communication transaction. Use
NXTCommBTCheckStatus to monitor the status of the transaction.
Not sure what to do about the underlined part, though...

-----

Also, there's Comm Module ID...

Now if I could just find the right offsets... EDIT: Hmmm... No luck so far. Gotta do my homework. :)