Calling a subroutine in a separate file
28 Jan 2010 18:43 #1672
by Tim.G
Calling a subroutine in a separate file was created by Tim.G
I am trying to call a subroutine in a separate file, the files look as follows;
File 1.ngc:
(msg,1)
o"2.ngc" call
(msg, 3)
M2
File: 2.ngc:
o<2.ngc> sub
(msg,2)
o<2.ngc> endsub
M2
The code is not doing a lot; it should display 3 messages, containing 1, 2 and 3 respectively. This is purely to demonstrate subroutine calling.
what happens is that the message in the called subroutine does not get displayed.
Has anyone done this type of thing before? Is it at all possible?
File 1.ngc:
(msg,1)
o"2.ngc" call
(msg, 3)
M2
File: 2.ngc:
o<2.ngc> sub
(msg,2)
o<2.ngc> endsub
M2
The code is not doing a lot; it should display 3 messages, containing 1, 2 and 3 respectively. This is purely to demonstrate subroutine calling.
what happens is that the message in the called subroutine does not get displayed.
Has anyone done this type of thing before? Is it at all possible?
Please Log in or Create an account to join the conversation.
01 Feb 2010 12:15 #1721
by BigJohnT
Replied by BigJohnT on topic Re:Calling a subroutine in a separate file
If the file name is 2.ngc then the syntax would be
o<2> call
and the 2.ngc file would have the following syntax
o<2> sub
...
o<2> endsub
M2
John
o<2> call
and the 2.ngc file would have the following syntax
o<2> sub
...
o<2> endsub
M2
John
Please Log in or Create an account to join the conversation.
24 Feb 2010 16:01 #2045
by zramaro
Replied by zramaro on topic Re:Calling a subroutine in a separate file
Hello,
I have the same issue, I can't see what I'm doing wrong.
FIle test.ngc:
o<1> call
M2
File 1.ngc (in directory path PROGRAM_PREFIX):
o<1> sub
(msg.test)
o<1> endsub
M2
When running test.ngc with axis 2.2.8, I get an error message "Near line 2 of test.ngc: Bad number format".
Thanks for any help.
I have the same issue, I can't see what I'm doing wrong.
FIle test.ngc:
o<1> call
M2
File 1.ngc (in directory path PROGRAM_PREFIX):
o<1> sub
(msg.test)
o<1> endsub
M2
When running test.ngc with axis 2.2.8, I get an error message "Near line 2 of test.ngc: Bad number format".
Thanks for any help.
Please Log in or Create an account to join the conversation.
29 Apr 2010 08:07 - 30 Apr 2010 07:48 #2747
by ArcEye
Replied by ArcEye on topic Re:Calling a subroutine in a separate file
Hi All,
I tried this and initially had the same problems but have now solved it.?!
Put your subroutines in a numbered file, not a named one.
This is the norm for industrial controllers anyway.
Make sure the number is above the 1 to 54 -56 ( can't remember which) numbers used in parameter passing to subs.
As I use 1xx numbers for subs normally, I went to 2xx for external files
Make sure your file path is set in the .ini file as previously mentioned.
File 1 - test.ngc
(MSG,1)
O200 CALL
(MSG, 3)
M2
File2 - 200.ngc
O200 Sub
(MSG,2)
O200 Endsub
M2
This will result in the correct output of 1, 2, 3 on the message line
Note the calling syntax is the same as numbered subs in the same code file and no < > brackets.
No matter what I put in those, I could not get named files to work.
Someone on the emc-users lists suggested putting
[RS274NGC]
LAZY_CLOSE = 1
in the .ini file.
From research, this appears to enable O calls from the MDI line but has no effect on calling from within .ngc code
regards
ArcEye
PS
The number that I was trying to remember was 60.
1 - 30 are the possible parameters to the sub routine and 31 - 60 the possible return values.
I don't know if there is a possibility of a clash, but seems sensible to avoid anything which could confuse the controller, or oneself!
I tried this and initially had the same problems but have now solved it.?!
Put your subroutines in a numbered file, not a named one.
This is the norm for industrial controllers anyway.
Make sure the number is above the 1 to 54 -56 ( can't remember which) numbers used in parameter passing to subs.
As I use 1xx numbers for subs normally, I went to 2xx for external files
Make sure your file path is set in the .ini file as previously mentioned.
File 1 - test.ngc
(MSG,1)
O200 CALL
(MSG, 3)
M2
File2 - 200.ngc
O200 Sub
(MSG,2)
O200 Endsub
M2
This will result in the correct output of 1, 2, 3 on the message line
Note the calling syntax is the same as numbered subs in the same code file and no < > brackets.
No matter what I put in those, I could not get named files to work.
Someone on the emc-users lists suggested putting
[RS274NGC]
LAZY_CLOSE = 1
in the .ini file.
From research, this appears to enable O calls from the MDI line but has no effect on calling from within .ngc code
regards
ArcEye
PS
The number that I was trying to remember was 60.
1 - 30 are the possible parameters to the sub routine and 31 - 60 the possible return values.
I don't know if there is a possibility of a clash, but seems sensible to avoid anything which could confuse the controller, or oneself!
Last edit: 30 Apr 2010 07:48 by ArcEye. Reason: additional info
The following user(s) said Thank You: xaxxes
Please Log in or Create an account to join the conversation.
Time to create page: 0.065 seconds