Page 2 of 3
Re: NXC - main method params?
Posted: 17 Feb 2012, 22:00
by spiked33
args.QueueID = MAILBOX1; <- that probably does it
Re: NXC - main method params?
Posted: 18 Feb 2012, 02:37
by afanofosc
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
Re: NXC - main method params?
Posted: 18 Feb 2012, 04:56
by brothman01
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...
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.
to 'loop until a message is recieved', and then act on it, could I do:
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);
}
}
}
Re: NXC - main method params?
Posted: 18 Feb 2012, 14:24
by mcsummation
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:
Code: Select all
string sMessage;
until (NO_ERR == ReceiveRemoteString(MAILBOX1, false, sMessage))
Wait(50);
ReceiveRemoteString(MAILBOX1, true, sMessage)
(Caution, I typed this in while looking at the actual code on another computer - so it might need "repairing".)
Re: NXC - main method params?
Posted: 18 Feb 2012, 20:01
by brothman01
thanks, yeah something clicked.. it works now
Anyway, thanks so much for the help everyone
Re: NXC - main method params?
Posted: 19 Feb 2012, 00:32
by nxt-ai
Sorry can't help nitpicking:
NXC is not object oriented therefore there are no methods only function as methods are member functions.
Re: NXC - main method params?
Posted: 19 Feb 2012, 01:45
by afanofosc
Sorry to nitpick but the word "method" and the word "function" do not have the strict meanings that you suggest they have.
[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.
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.
John Hansen
Re: NXC - main method params?
Posted: 19 Feb 2012, 10:45
by HaWe
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.
Re: NXC - main method params?
Posted: 19 Feb 2012, 18:30
by mightor
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
If we can just agree that all of those terms pretty much mean the same thing in the context of programming in NXC, we can stop this whole discussion and get on with life. People who program OOP will probably make the distinction, the rest of the people won't care.
I took the trouble of summing it all up into a little Haiku:
Methods or functions
Procedures, subroutines
Only pedants care
- Xander
Re: NXC - main method params?
Posted: 19 Feb 2012, 20:24
by HaWe
no, I disagree.