NXC - main method params?
Re: NXC - main method params?
args.QueueID = MAILBOX1; <- that probably does it
Re: NXC - main method params?
For one thing the NXT ignores any MessageWrite direct commands (what NeXTTools and BricxCC use when sending a message to an NXT) if a program is not running. So the program has to be running in order for a message to actually get written to a mailbox. And that program then needs to read the mailbox after the message is sent by the computer to the NXT.
Your program reads from the mailbox as soon it starts running and exits shortly thereafter. I suspect it will work fine if you loop until a message is received. Or wait for a few seconds at the start of the program before checking the mailbox.
John Hansen
Your program reads from the mailbox as soon it starts running and exits shortly thereafter. I suspect it will work fine if you loop until a message is received. Or wait for a few seconds at the start of the program before checking the mailbox.
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
-
- Posts: 20
- Joined: 16 Feb 2012, 22:59
Re: NXC - main method params?
oh, ok, thank you all very much... oh just one other thing, I'm so sorry for this long thread, starting is often the hardest part of something I guess...
to 'loop until a message is recieved', and then act on it, could I do:Your program reads from the mailbox as soon it starts running and exits shortly thereafter. I suspect it will work fine if you loop until a message is received. Or wait for a few seconds at the start of the program before checking the mailbox.
Code: Select all
task main() {
while (start) {
MessageReadType args; // included in the while statement so that each value will refresh every second.
args.QueueID = MAILBOX1; // 0
if (args.Result == NO_ERR) {
TextOut(0, LCD_LINE1, args.Message);
Wait(SEC_1);
} else {
Wait(SEC_1);
}
}
}
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: NXC - main method params?
If what you are wanting to do is to send a "script" to your NXT, then have the program act on it, you could, instead of using the message paradigm, write a file to the NXT, then have the program read the file.
The following code is what I use to read messages from the Bluetooth:
(Caution, I typed this in while looking at the actual code on another computer - so it might need "repairing".)
The following code is what I use to read messages from the Bluetooth:
Code: Select all
string sMessage;
until (NO_ERR == ReceiveRemoteString(MAILBOX1, false, sMessage))
Wait(50);
ReceiveRemoteString(MAILBOX1, true, sMessage)
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
-
- Posts: 20
- Joined: 16 Feb 2012, 22:59
Re: NXC - main method params?
thanks, yeah something clicked.. it works now Anyway, thanks so much for the help everyone
Re: NXC - main method params?
Sorry can't help nitpicking:
NXC is not object oriented therefore there are no methods only function as methods are member functions.
NXC is not object oriented therefore there are no methods only function as methods are member functions.
Re: NXC - main method params?
Sorry to nitpick but the word "method" and the word "function" do not have the strict meanings that you suggest they have.
John Hansen
In our context, i.e., programming the NXT using something like NXC, the word method and function and procedure are all essentially interchangeable and have not particular meaning like they might have in C++ or Java or some other context.[P]articular words have different meanings, or no particular meaning at all, depending on what type of programming you're talking about. So it is important to make clear the context of the discussion.
In Java "function" doesn't mean anything special. In C, "function" means a program routine. In C++, it can mean the same as it does in C, or it can mean rather the same as "method" does in Java. In functional programming, a "function" has a very strict definition, much tighter than in the procedural/OO languages previously mentioned.
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: NXC - main method params?
sorry to nitpick, but there are maybe some regional fluctuations (Germany/Europe vs. USA), in meaning as well. The word "procedure" is widely used in Pascal (it even is a keyword). In German speaking countries (and maybe French speaking countries as well) Pascal has been widly used for educational reasons since the 1990ies in universities and later even at highschools: This was certainly because it's Swiss developer, Niklaus Wirth, was German speaking, too, he wrote many German publications and textbooks about his programming language right from the start and so has reached a big influence. (I learned a little about it in 1988, and even my son still had to learn it in junior highschool since 2005).
In Pascal "procedure" stands for a "routine which has no returned value". Speaking in C terminology, they are routines with non-existent, i.e. void returned values.
A "function" also has an additional mathematical background meaning, i.e. it is a correspondence ("Abbildung") which has a definition set and a result set:
f: A -> B, A,B: sets;
x |-> y with x ∈ A, y ∈ B, often written as: y=f(x)
Speaking from the view of a programmer, especially from a Pascal background (here also "function" is a keyword), it has an input (x= passed value(s)) and an output (y=returned value(s)), and that's exactly how Pascal defines the difference; the same it is basicly in C .
A "routine" contains the program instructions for a particular task or part of an algorithm. "Subroutine" is a term which has it's roots also in Basic ("sub" in contrast to the "main routine" which formerly only had 1 routine with multiple jump addresses). Both "routine" and "subroutine" can be used as a generic term for both procedures and functions, "sub" itself belongs mainly to Basic and is not used neither by C nor by Pascal.
"Method" is a term which is often used in OOP for routines incapsulated in objects, e.g., also in Object Pascal (later called Delphi).
Although I see that Pascal terminologies is the US will probably not have the same spreading, circulation, or commonness as in our country or even as in Central and Western Europe, it's definitions are very strict, logical, and clear (that's why it once has been developed just for education):
routine: term for a coded algorithm, as a part of the whole sequence of program instructions
subroutine: every routine besides the main routine
procedure: subroutine without returning a value (in C: void function or routine)
function: subroutine which returnes a value (same in C)
method: especially for OOP: routine as a part of an object / incapsulated into an object
These definitions are so clear, reasonable, and comprehensible that I would suggest that they might be a good terminology arrangement also for this forum with it's support for multiple languages, too, to avoid confusions in terms.
In Pascal "procedure" stands for a "routine which has no returned value". Speaking in C terminology, they are routines with non-existent, i.e. void returned values.
A "function" also has an additional mathematical background meaning, i.e. it is a correspondence ("Abbildung") which has a definition set and a result set:
f: A -> B, A,B: sets;
x |-> y with x ∈ A, y ∈ B, often written as: y=f(x)
Speaking from the view of a programmer, especially from a Pascal background (here also "function" is a keyword), it has an input (x= passed value(s)) and an output (y=returned value(s)), and that's exactly how Pascal defines the difference; the same it is basicly in C .
A "routine" contains the program instructions for a particular task or part of an algorithm. "Subroutine" is a term which has it's roots also in Basic ("sub" in contrast to the "main routine" which formerly only had 1 routine with multiple jump addresses). Both "routine" and "subroutine" can be used as a generic term for both procedures and functions, "sub" itself belongs mainly to Basic and is not used neither by C nor by Pascal.
"Method" is a term which is often used in OOP for routines incapsulated in objects, e.g., also in Object Pascal (later called Delphi).
Although I see that Pascal terminologies is the US will probably not have the same spreading, circulation, or commonness as in our country or even as in Central and Western Europe, it's definitions are very strict, logical, and clear (that's why it once has been developed just for education):
routine: term for a coded algorithm, as a part of the whole sequence of program instructions
subroutine: every routine besides the main routine
procedure: subroutine without returning a value (in C: void function or routine)
function: subroutine which returnes a value (same in C)
method: especially for OOP: routine as a part of an object / incapsulated into an object
These definitions are so clear, reasonable, and comprehensible that I would suggest that they might be a good terminology arrangement also for this forum with it's support for multiple languages, too, to avoid confusions in terms.
Re: NXC - main method params?
Code: Select all
routine: term for a coded algorithm, as a part of the whole sequence of program instructions
subroutine: every routine besides the main routine
procedure: subroutine without returning a value (in C: void function or routine)
function: subroutine which returnes a value (same in C)
method: especially for OOP: routine as a part of an object / incapsulated into an object
I took the trouble of summing it all up into a little Haiku:
Methods or functions
Procedures, subroutines
Only pedants care
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
Who is online
Users browsing this forum: No registered users and 19 guests