using ^C in BASIC module

ettikudiappan

Member
Join Date
Apr 2002
Location
Singapore
Posts
131
Hi

I have a BASIC module program that disables stopping the program using ^C after initial delay of 5 seconds. The problem is, even if I press ^C within the designated 5 sec, the program does not stop. I am not able to list the program either. I need to do this to backup the BASIC module program. I have set the jumpers such that PRT1 is a program port and the cable used is also of the proper type. I have uploaded sucessfully using the same cable and hyperterminal from other BASIC module that do not disable ^C.

For those interested, I am listing the program below.

5 REM **Reset LED's 1 & 2 - Ctrl-C Is Now Active**
10 PUSH 0 : PUSH 0 : CALL 112
20 REM
50 REM **Delay Before disabling Ctrl-C**
60 FOR X=1 TO 5000 : NEXT X
70 REM **Disable Ctrl-C**
80 REM CALL 19
90 REM
100 REM **Setup Ports 1 & 2**
110 MODE (PRT1,9600,N,8,1,N,R)
120 MODE (PRT2,9600,N,8,1,N,R)
130 REM
150 REM **Setup Port 1 For Data Xfer From Port 1 to M1:e.0 (12 Bytes)**
160 PUSH 1 : PUSH 12 : PUSH 10 : PUSH 1 : PUSH 0 : PUSH 0 : PUSH 1
170 CALL 22 : POP X
180 REM
200 REM **Setup Port 2 For Data Xfer From O:e.2 To Port 2**
210 PUSH 4 : PUSH 0 : PUSH 2 : PUSH 0 : PUSH 1
220 CALL 23 : POP X
230 REM
250 REM **Setup Port 2 For Data Xfer From Port 2 to I:e.2 (1 Byte)**
260 PUSH 2 : PUSH 1 : PUSH 0 : PUSH 0 : PUSH 2 : PUSH 0 : PUSH 1
270 CALL 22 : POP X
280 REM
300 REM **Clear Basic/SLC I/O Buffers**
310 PUSH 15 : CALL 120
320 REM
350 REM **Clear Port 2 I/O Buffers**
360 PUSH 2 : CALL 37
370 REM
400 REM **Clear Port 1 I/O Buffers**
410 PUSH 2 : CALL 96
420 REM
500 REM **Alternate LED's To Indicate Ctrl-C Disabled**
510 DO
520 PUSH 1 : PUSH 0 : CALL 112
530 FOR X=1 TO 100 : NEXT X
540 PUSH 0 : PUSH 1 : CALL 112
550 FOR X=1 TO 100 : NEXT X
560 UNTIL 1=2
1000 END
 
I don't expect that your program is actually taking five seconds to get to the "CALL 19" instruction. Have a look at the CLOCK0, CLOCK1, and TIME functions. My comments are based on the PLC version of the basic card - that's the one I've used. I would expect the SLC version to be similar.

Note, you can re-enable the CTRL-C functionality by using "CALL 18" somewhere else in your program.

In any event, once "CALL 19" has executed, the User Manual (Publication 1771-6.5.113 November 1994) states:

"you cannot stop program execution through a BASIC command. In this case, set jumper JW4 of the BASIC module in the factory default position and cycle power to stop program execution."
 
On line 80 remove the rem statement before the call 19.

Can you explain how the program works and what its doing I'm trying to learn basic programming as well.
Thanks
Drewcrew6

5 REM **Reset LED's 1 & 2 - Ctrl-C Is Now Active**
10 PUSH 0 : PUSH 0 : CALL 112
20 REM
50 REM **Delay Before disabling Ctrl-C**
60 FOR X=1 TO 5000 : NEXT X
70 REM **Disable Ctrl-C**
80 REM CALL 19
90 REM
100 REM **Setup Ports 1 & 2**
110 MODE (PRT1,9600,N,8,1,N,R)
120 MODE (PRT2,9600,N,8,1,N,R)
130 REM
150 REM **Setup Port 1 For Data Xfer From Port 1 to M1:e.0 (12 Bytes)**
160 PUSH 1 : PUSH 12 : PUSH 10 : PUSH 1 : PUSH 0 : PUSH 0 : PUSH 1
170 CALL 22 : POP X
180 REM
200 REM **Setup Port 2 For Data Xfer From O:e.2 To Port 2**
210 PUSH 4 : PUSH 0 : PUSH 2 : PUSH 0 : PUSH 1
220 CALL 23 : POP X
230 REM
250 REM **Setup Port 2 For Data Xfer From Port 2 to I:e.2 (1 Byte)**
260 PUSH 2 : PUSH 1 : PUSH 0 : PUSH 0 : PUSH 2 : PUSH 0 : PUSH 1
270 CALL 22 : POP X
280 REM
300 REM **Clear Basic/SLC I/O Buffers**
310 PUSH 15 : CALL 120
320 REM
350 REM **Clear Port 2 I/O Buffers**
360 PUSH 2 : CALL 37
370 REM
400 REM **Clear Port 1 I/O Buffers**
410 PUSH 2 : CALL 96
420 REM
500 REM **Alternate LED's To Indicate Ctrl-C Disabled**
510 DO
520 PUSH 1 : PUSH 0 : CALL 112
530 FOR X=1 TO 100 : NEXT X
540 PUSH 0 : PUSH 1 : CALL 112
550 FOR X=1 TO 100 : NEXT X
560 UNTIL 1=2
1000 END
 
Hi

Thanks to all who responded. I have figured out what the problem was. First thing, when BASIC unit is in default factory set mode, the baud rate becomes 1200 and not 9600. Even after changing the baud rate, I still had problems. Then I noticed that the jumpers for RS232, 485 or 422 was set to RS422 and not RS232. Once I changed to RS232, I was able to upload the program using the LIST statement.

For those who want to understand the program, it is simply a port read and write, but with additional code to turn ON and turn OFF the PRT1 and PRT2 LEDS so that they keep blinking when the program is running.
 
I have one more question, lines 510 to 560 will be in an infinite loop. Hence how does this program still work? I mean, I am still able read and write to PRT1 and PRT2 even though the PORT handling portion of the code (Upto line no. 500) is executed only once.
 
When you first posted your code, I only looked at the "timer" to disable CTRL-C. As Drewcrew6 pointed out though, CTRL-C is not being disabled in the code you supplied because the CALL 19 is preceded by REM.

After your latest post, I spent a few minutes looking at your entire code, and my question to you is: are you sure it does anything?

Did you write the code? If not, how did you get the code to post?

Looks to me like you are only setting port parameters and clearing buffers. Then as you pointed out, you are getting into an infinite loop . . .
 
I didn't look at the whole program the first time either If I would have looked then I would've understood it.

If I recall the call 22 and call 23 work continuosly until they are told to stop by another call 22 or call 23. I belive they are port isolated and run in the background but can cause the program to halt, but not sure about the halt part. I am not sure if you can setup a call 22 and call 23 and have both run simultaniously.

Possibly might be a setup string ( in plc file O:e.2) that needs to go out port 2 then it only monitors input from that port and sends it to the plc file I:e.2.
Looks like port 1 also only monitors the info and sends it to the plc file M1:e.0.
There also has to be some programming in the plc to accept the info from the M1:e.0 file.

What devices are connected to the ports?
Is this existing or a new project?

Hopefully this helps everyone out as I have yet to find someone that really understands the entire basic programing setup in these cards although they are outdated they still get used. When I do find someone I have plenty of questions myself!!!!!!!

Drewcrew6
 
First thing, this is a perfectly running program that has been working for years. All I am trying to do is understand it.
During normal RUN mode, the BASIC module reads data from PORT1 continuously. On PORT2, the basic module sends a request and receives a reply. All this keeps happening when the LED1 and 2 flash alternately!! This is what bugged me.

Even if we assume that once CALL 22 & 23 are established they keep running continously, if you see the lines 310, 360 and 410 they keep clearing the PRT and SLC buffers.
So it looks like once CALL 22, 23, 120, 37 and 96 are executed, they keep executing in the same order as they were programmed even though these lines never execute more than once!!!!!

As for the REM statement before CALL 19, I added it to allow Cntrl C to be used.
 
Okay that sounds right except the only calls that run continuos are the call 22 and call 23. So on the first scan both call 22 and the call 23 are setup and running. The rest of the calls are executed once like the others but do not run continuos in the background. Then the program goes into the continuos loop and blinks the leds.

The reason for the call 120, call 37, and call 96 is to clear all old data from these to begin new.

Does that help?

Drewcrew6
 
I figured out the confusion (in my mind anyhow) - you are using the SLC version of the basic module, which has a slightly different call list than the PLC version that I am using.

In the PLC version, Call 33 transfers data continuously from the port to the BT buffer (which then requires addional code in the PLC). This transfer happens automatically after every line of (basic) code. For the PLC basic module, Call 22 & 23 are just number format conversion commands. When I saw these Calls in your code I said - "nothing's happening".

But, in the SLC version, Call 22 does is basically equivalent to Call 33 (for port reads) - so something is indeed happening.

In the PLC version, Call 34 does transfers data continuously (for port writes), while Call 23 is the SLC equivalent.


So - Drewcrew is absolutely correct - in your SLC basic module, call 22 and 23 should be called only once in your code for a given port, and they will be evaluated by the basic module in the background including during the execution of your infinite loop.

Sorry if I caused confusion for not picking up on the significance of the PLC vs. SLC difference.

Marc


PS: Here's a link to the SLC basic module for anyone interested.

http://www.ab.com/manuals/io/1746/1746-rm001a-en-p.pdf
 

Similar Topics

Hello there, world! The problem i'm facing up is about a registry I need to do in order to compare the set point versus the real variable I got...
Replies
2
Views
1,578
Anyone have an idea of how to create a FIFO que and storage network using only the folowing instructions (and,or,not,xor). I'm working on a...
Replies
17
Views
8,155
Hello, I'm working on a project where I have two encoders (which I'm reading through counters). What happens at the line is that an inspector is...
Replies
7
Views
2,807
In another thread I asked questions about problems I have had with AB Panelview. I have long felt that it might be cost effective and offer more...
Replies
5
Views
3,695
Hi everyone, I need a help for designing PLC ladder programming simulation software using visual basic 6.0. I have no idea how to start with...
Replies
2
Views
6,508
Back
Top Bottom