NXC : Start Program command(?)

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
webstorms
Posts: 38
Joined: 10 Mar 2011, 15:27

NXC : Start Program command(?)

Post 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. :)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC : Start Program command(?)

Post 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).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
dudmaster
Posts: 171
Joined: 06 Oct 2010, 02:38
Location: Texas, Santa Fe
Contact:

Re: NXC : Start Program command(?)

Post by dudmaster »

Matt:

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

Web:

Try that. Right click (in BricxCC) and select 'Help Topics'
2Labz.com, My Website
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC : Start Program command(?)

Post 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).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC : Start Program command(?)

Post by mattallen37 »

Actually, I can think of one possible solution; try writing to the IO map from the program.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
ronmcrae
Posts: 33
Joined: 28 Sep 2010, 14:56

Re: NXC : Start Program command(?)

Post 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.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC : Start Program command(?)

Post 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.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC : Start Program command(?)

Post by muntoo »

Is it possible to write commands on the BT input "message box"/whatever the heck it's called to your own NXT?
Image

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


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC : Start Program command(?)

Post 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.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC : Start Program command(?)

Post 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. :)
Image

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


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests