Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 02:27 24 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Draft Serial Terminal Program

Author Message
Ray B
Senior Member

Joined: 16/02/2007
Location: Australia
Posts: 219
Posted: 02:41pm 03 Sep 2011
Copy link to clipboard 
Print this post

Now with Serial Comms a reality I thought I'd have a bash at customising a terminal program I've found on the net.

Now working OK from menu to set Com Port & speed but when I try to go to CHAT mode I have a problem setting a serial data array.

Line 8 I have: DIM MODEMIN$(80) which should make space available to store 80 characters
But in line 510 I get an error : Array must be dimensioned first

Any help appreciated at this late stage of the night....

Code follows:

1 REM This program by Aaron Cake (aaron.cake@blackhole.xg.com)
2 REM You are free to use it, give it away or modify it, as long
3 REM as this message remains intact.
4 REM http://www.execulink.com/~cake/ http://www.lmcs.edu.on.ca/jp2/students/aaronc/index.html
' 8 KEY OFF
'
7 COMPORT$ = "COM1:9600" ' set default Serial Port & Speed
8 DIM MODEMIN$(80) ' set a single dimension array for comms data
'
9 ON ERROR GOTO 540
10 CLS
20 LOCATE 1,1
30 PRINT CHR$(201);
40 FOR I = 1 TO 78
50 PRINT CHR$(205);
60 NEXT I
70 PRINT CHR$(187);
80 PRINT CHR$(186);
90 FOR I=1 TO 78
100 PRINT " ";
110 NEXT I
120 PRINT CHR$(186);
130 PRINT CHR$(200);
140 FOR I=1 TO 78
150 PRINT CHR$(205);
160 NEXT I
170 PRINT CHR$(188);
180 LOCATE 2,2:PRINT "<D>ial, <H>ang up, <S>etup, <E>xit. Press ESC to close menu & goto CHAT mode."
190 MENUCHOICE$=INKEY$
200 IF MENUCHOICE$="d" THEN GOTO 370
210 IF MENUCHOICE$="h" THEN CLOSE #1:CLOSE #2
220 IF MENUCHOICE$="s" THEN GOTO 251
230 IF MENUCHOICE$="e" THEN CLS:END
240 IF MENUCHOICE$=CHR$(27) THEN GOTO 488
250 GOTO 190
251 LOCATE 2,2
260 FOR I=1 TO 78
270 PRINT " ";
280 NEXT I
290 LOCATE 2,2:PRINT "Enter COM port (1 or 2) followed by RTN... then on new line: Speed: (e.g. 9600) ";
300 LOCATE 2,21:LINE INPUT PORTNUM$
310 LOCATE 2,32:LINE INPUT SPEED$
320 COMANDSPEED$= "COM" + PORTNUM$ + ":"+SPEED$
325 PRINT "In SETUP you Specified COM" + PORTNUM$ + " and SPEED as " + SPEED$
330 OPEN "terminal.cfg" FOR OUTPUT AS #1
340 PRINT #1, COMANDSPEED$
350 CLOSE #1
355 CLS: LOCATE 2,2 : print "we just saved setup to disk as " + COMANDSPEED$ : PAUSE 5000 : CLS
360 GOTO 180
370 LOCATE 2,2
380 FOR I=1 TO 78
390 PRINT " ";
400 NEXT I
410 LOCATE 2,2
420 INPUT "Enter number to dial: ", NUMBER$
430 OPEN "terminal.cfg" FOR INPUT AS #1
440 LINE INPUT #1, COMPORT$
450 CLOSE #1
'460 OPEN COMPORT$ + ",N,8,1" AS #1
460 OPEN COMPORT$ +,1024" AS #1 ' Open Serial Port with 1024 buffer size
470 OPEN "con" FOR OUTPUT AS #2
471 LOCATE 4,1
480 PRINT #1, "ATDT" + NUMBER$
483 FOR Q=1 TO 2
486 NEXT Q
488 CLS: LOCATE 2,2 : print "ENTERING CHAT MODE .......": PAUSE 5000 : CLS
'489 OPEN COMPORT$ + ",N,8,1" AS #1 open serial port
489 OPEN COMPORT$ + ",1024" AS #1 open serial port with 1024 buffer
' 490 DIM MODEMIN$(80) ' set a single dimension array for comms data
495 USERINPUT$=INKEY$
500 IF USERINPUT$ <> "" THEN PRINT #1, USERINPUT$;
501 IF USERINPUT$=CHR$(27) THEN GOTO 20
510 IF NOT EOF(1) THEN MODEMIN$=INPUT$(LOC(1),#1):PRINT #2, MODEMIN$;
520 GOTO 490
530 END
540 IF ERR=24 THEN LOCATE 2,2:PRINT "Modem not connected. ";:INPUT " ",TEMP$:GOTO 10
550 IF ERR=52 THEN LOCATE 2,2:PRINT "Cannot open COM port. ";:INPUT " ",TEMP$:GOTO 10
560 IF ERR=57 THEN CLOSE #1:OPEN COMPORT$ + ",N,8,1" FOR RANDOM AS #1: GOTO 480
570 END


RayB from Perth WA
 
ajkw
Senior Member

Joined: 29/06/2011
Location: Australia
Posts: 290
Posted: 03:24pm 03 Sep 2011
Copy link to clipboard 
Print this post

  Ray B said  
510 IF NOT EOF(1) THEN MODEMIN$=INPUT$(LOC(1),#1):):PRINT #2, MODEMIN$;



Ray,
I don't like the bit I have highlighted. It doesn't seem to be in the correct format for inputing from a file or serial.

It is later on the east coast!!

Cheers,
Anthony.


 
seco61
Senior Member

Joined: 15/06/2011
Location: Australia
Posts: 205
Posted: 11:02pm 03 Sep 2011
Copy link to clipboard 
Print this post

Hi Ray.

In the following line:


510 IF NOT EOF(1) THEN MODEMIN$=INPUT$(LOC(1),#1):PRINT #2, MODEMIN$;


The "LOC(1)" is causing your error message. LOC is not a MMBasic function or command and therefore the interpreter treats it as an array - which has not been "DIM"ed!

Also, be aware that MODEMIN$ and MODEMIN$() are 2 totally different variables. The first is a standard string variable, the second an array of strings. And they can both exist at the same time.

To further elaborate on this, all strings in MMBasic allocate space for 255 characters. So using MODEMIN$ accesses a string variable that will contain between 0 and 255 characters. In your program, the array MODEMIN$(80) (which allocates space for 80 strings, each of which can contain between 0 and 255 characters) is never accessed as the interpreter treats the name of this array as "MODEMIN$(".Edited by seco61 2011-09-05

Regards

Gerard (vk3cg/vk3grs)
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 12:28am 04 Sep 2011
Copy link to clipboard 
Print this post

Also "IF NOT EOF(1) THEN ..." in line 510 should be changed to "IF EOF(1) THEN ...".

This is because I changed the EOF() function to return the number of characters waiting (and zero if not) whereas in Microsoft's BASIC EOF() would return false (zero) if there were some characters waiting.

Using my syntax the line should be:
510 IF EOF(1) > 0 THEN MODEMIN$=INPUT$(EOF(1),#1):PRINT #2, MODEMIN$;

I am beginning to regret this, I believe that standards are great and I should not be breaking them. So in the final version I plan to make EOF() work the same as in Microsoft BASIC and add LOC() to return the number of characters waiting. Line 510 would then work without change.

Does this sound OK?

Geoff
Geoff Graham - http://geoffg.net
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2914
Posted: 12:54am 04 Sep 2011
Copy link to clipboard 
Print this post

  Geoffg said  
I am beginning to regret this, I believe that standards are great and I should not be breaking them. So in the final version I plan to make EOF() work the same as in Microsoft BASIC and add LOC() to return the number of characters waiting. Line 510 would then work without change.

Does this sound OK?

Geoff


Sounds ok by me Geoff, I think it SHOULD be standard Basic as much as possible, unless there is a `real' benefit in enhancing the commands.

Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6094
Posted: 01:25am 04 Sep 2011
Copy link to clipboard 
Print this post

  Geoffg said   So in the final version I plan to make EOF() work the same as in Microsoft BASIC and add LOC() to return the number of characters waiting. Line 510 would then work without change.

Does this sound OK?

Geoff

Another choice would be LOF(), a function that would be useful for disk files as well.

If I have read the help files correctly, Microsoft QB used LOC() for bytes waiting in the input buffer and LOF() for bytes free in the output buffer.

Now the buffers are usually big enough and the processing fast enough so buffer overflow is not usually a concern.

Jim
VK7JH
MMedit   MMBasic Help
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 01:39am 04 Sep 2011
Copy link to clipboard 
Print this post

In my reference LOF() returns the number of bytes free in the input buffer.

I am not sure if that is of any benefit as you know the size of the buffer (specified in the OPEN command) and it would be easy to calculate this number.

Geoff
Geoff Graham - http://geoffg.net
 
Ray B
Senior Member

Joined: 16/02/2007
Location: Australia
Posts: 219
Posted: 02:14am 04 Sep 2011
Copy link to clipboard 
Print this post

Thanks for all of the valuable comments. I'll get back into this tonight.

Part of the intent of this exercise is to provide a working example for others to follow.

Once reliable comms is established then the obvious thing to do is make the program more GUI friendly with separate TX and RX windows. All of this development demonstrates the retention of the VGA capability.
Cheers
RayB from Perth WA
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6094
Posted: 04:13am 04 Sep 2011
Copy link to clipboard 
Print this post

  Geoffg said   In my reference LOF() returns the number of bytes free in the input buffer.

I am not sure if that is of any benefit as you know the size of the buffer (specified in the OPEN command) and it would be easy to calculate this number.

Geoff


Looking further into the LOC() LOF() options,
The QuickBasic 4.5 handbook has:
quote..
EOF Whether or not any characters are waiting to be read from the input buffer.

LOC The number of characters waiting in the input buffer.

LOF The amount of space remaining (in bytes) in the output buffer.

end of quote..

Too many standards!

If you are using flow control, it is possible for the application to 'hang' waiting for the output buffer to empty.
We need a timeout option or LOF()
If you are not using flow control, the programmer can feed the data slow enough to prevent a full buffer and if it does fill up, the program will resume eventually anyway.

Because the INPUT$() function returns with whatever is available, and the interupt can be set when there is data available, there is no risk of program hangups.

Jim
VK7JH
MMedit   MMBasic Help
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 05:42am 04 Sep 2011
Copy link to clipboard 
Print this post

Sounds good, both LOC() and LOF() will be in the final version. LOF() will return the amount of space remaining in the output buffer.

I am trying to stop adding too many keywords but I am obviously not succeeding... mumble, mumble

Geoff
Geoff Graham - http://geoffg.net
 
BobDevries

Senior Member

Joined: 08/06/2011
Location: Australia
Posts: 266
Posted: 05:48am 04 Sep 2011
Copy link to clipboard 
Print this post

Just to throw a spanner in the works.....

If in the future RANDOM ACCESS files are introduced, then LOF() has a different meaning. Here's the meaning from that perspective, from the GWBasic manual:


LOF Function
Purpose:

To return the length (number of bytes) allocated to the file.

Syntax:

LOF(file number)
Comments:

file number is the number of the file that the file was opened under.

With communications files, LOF returns the amount of free space in the input buffers.

Examples:

The following sequence gets the last record of the random-access file file.big, and assumes that the file was created with a default record length of 128 bytes:

10 OPEN "R",1,"FILE.BIG"
20 GET #1,LOF(1)/128
.
.
.


Regards,
Bob Devries
Dalby, QLD, Australia
 
Ray B
Senior Member

Joined: 16/02/2007
Location: Australia
Posts: 219
Posted: 01:45pm 04 Sep 2011
Copy link to clipboard 
Print this post

SUCCESS ???? Code now seems to be running OK without crashing and with a logic probe I can see Sent Data. Need to now set up a max232 or maybe run output into my MM LCD code on the same protoboard.

Tried linking Tx & Rx with 1000 ohm resistor for a loop back but that didn't work - nothing is simple.

Interesting that the MM pins 15 & 16 clash with those allocated previously with Geoff's original LCD interface D4 & D5 and COM1 Tx & Rx but then the LCD EN & RS lines won't be active so may still work if all connected at same time.

As a group we maybe need to consider the default allocation of certain I/O lines to certain purposes, but that's is another story.

Following is my revised working code.

1 REM This program by Aaron Cake (aaron.cake@blackhole.xg.com)
2 REM You are free to use it, give it away or modify it, as long
3 REM as this message remains intact.
4 REM http://www.execulink.com/~cake/ http://www.lmcs.edu.on.ca/jp2/students/aaronc/index.html
' 8 KEY OFF
'
7 COMPORT$ = "COM1:9600" ' set default Serial Port & Speed
9 ON ERROR GOTO 540
10 CLS
20 LOCATE 1,1
30 PRINT CHR$(201);
40 FOR I = 1 TO 78
50 PRINT CHR$(205);
60 NEXT I
70 PRINT CHR$(187);
80 PRINT CHR$(186);
90 FOR I=1 TO 78
100 PRINT " ";
110 NEXT I
120 PRINT CHR$(186);
130 PRINT CHR$(200);
140 FOR I=1 TO 78
150 PRINT CHR$(205);
160 NEXT I
170 PRINT CHR$(188);
' *************** SHOW MENU **********************************
180 LOCATE 2,2:PRINT "<D>ial, <H>ang up, <S>etup, <E>xit. Press ESC to close menu & goto CHAT mode."
190 MENUCHOICE$=INKEY$
200 IF MENUCHOICE$="d" THEN GOTO 370 ' goto DIAL
210 IF MENUCHOICE$="h" THEN CLOSE #1:CLOSE #2 ' HANG UP then run through lines then back to

menuchoice
220 IF MENUCHOICE$="s" THEN GOTO 251 ' goto SETUP
230 IF MENUCHOICE$="e" THEN CLS:END ' EXIT out of program
240 IF MENUCHOICE$=CHR$(27) THEN GOTO 488 ' ESC to CHAT MODE
250 GOTO 190
' ************* SETUP COMM PORT & SPEED **********************
251 LOCATE 2,2
260 FOR I=1 TO 78
270 PRINT " "; ' clear line
280 NEXT I
290 LOCATE 2,2:PRINT "Enter COM port (1 or 2) followed by RTN... then on new line: Speed: (e.g.

9600) ";
300 LOCATE 2,21:LINE INPUT PORTNUM$
310 LOCATE 2,32:LINE INPUT SPEED$
320 COMANDSPEED$= "COM" + PORTNUM$ + ":"+SPEED$
325 PRINT "In SETUP you Specified COM" + PORTNUM$ + " and SPEED as " + SPEED$
330 OPEN "terminal.cfg" FOR OUTPUT AS #1
340 PRINT #1, COMANDSPEED$
350 CLOSE #1
355 CLS: LOCATE 2,2 : print "we just saved setup to disk as " + COMANDSPEED$ : PAUSE 5000 : CLS
360 GOTO 180
' ************** START OF CODE TO DIAL INTO MODEM *************
370 LOCATE 2,2
380 FOR I=1 TO 78
390 PRINT " ";
400 NEXT I
410 LOCATE 2,2
420 INPUT "Enter number to dial: ", NUMBER$
430 OPEN "terminal.cfg" FOR INPUT AS #1
440 LINE INPUT #1, COMPORT$
450 CLOSE #1
'460 OPEN COMPORT$ + ",N,8,1" AS #1
460 OPEN COMPORT$ +,1024" AS #1 ' Open Serial Port with 1024 buffer size
470 OPEN "con" FOR OUTPUT AS #2
471 LOCATE 4,1
480 PRINT #1, "ATDT" + NUMBER$
483 FOR Q=1 TO 2
486 NEXT Q
' **************** END OF DIAL CODE **************************
'
' **************** START OF CHAT MODE ***********************
488 CLS: LOCATE 2,2 : print "ENTERING CHAT MODE .......": PAUSE 5000 : CLS
'489 OPEN COMPORT$ + ",N,8,1" AS #1 open serial port
489 OPEN COMPORT$ + ",1024" AS #1 open serial port with 1024 buffer
490 OPEN "con" FOR OUTPUT AS #2
495 USERINPUT$=INKEY$
500 IF USERINPUT$ <> "" THEN PRINT #1, USERINPUT$;
501 IF USERINPUT$=CHR$(27) THEN GOTO 20 ' test for ESC
'510 IF NOT EOF(1) THEN MODEMIN$=INPUT$(LOC(1),#1):PRINT #2, MODEMIN$;
510 IF EOF(1) > 0 THEN MODEMIN$=INPUT$(EOF(1),#1):PRINT #2, MODEMIN$; ' geoffs suggestion
520 GOTO 495
530 END
' **************** ERROR HANDLER ******************************
540 IF ERR=24 THEN LOCATE 2,2:PRINT "Modem not connected. ";:INPUT " ",TEMP$:GOTO 10
550 IF ERR=52 THEN LOCATE 2,2:PRINT "Cannot open COM port. ";:INPUT " ",TEMP$:GOTO 10
560 IF ERR=57 THEN CLOSE #1:OPEN COMPORT$ +,1024" AS #1: GOTO 480
570 END





RayB from Perth WA
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 09:28pm 04 Sep 2011
Copy link to clipboard 
Print this post

Just a few comments...

Linking Tx & Rx should work. Don't know what is going on there.

You will not be able to share i/o pins with the LCD driver as MMBasic will throw an error when you use PIN() on them (while the COM port is opened).

In the beginning 20 i/o lines seemed like a lot but it is getting a bit limited now, especially as we only have 10 5V tolerant lines.

Geoff
Geoff Graham - http://geoffg.net
 
VK6MRG

Guru

Joined: 08/06/2011
Location: Australia
Posts: 347
Posted: 08:34am 10 Sep 2011
Copy link to clipboard 
Print this post

Running low on I/O's?
100 pin version of the Maximite........
Its easier to ask forgiveness than to seek permission!

............VK6MRG.............VK3MGR............
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024