Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:11 02 Aug 2025 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 : Comm Port Still open after Watchdog timeout

Author Message
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 986
Posted: 09:24pm 19 Dec 2021
Copy link to clipboard 
Print this post

Does anyone have any ideas how I would get around this situation on a ArmMite F4 running MMB5.5?

Watchdog timeout
SDLogFile= Created 00:20:10 20-12-2021

SDCard Ready
TEST MODE = OFF

201221 002012 From PC: 15
[390] Open CFN$ For Append As #4
Error: File number already open

OA47
Edited 2021-12-20 07:28 by OA47
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7938
Posted: 09:47pm 19 Dec 2021
Copy link to clipboard 
Print this post

Could you trap the watchdog timeout using ON ERROR SKIP nn then check MM.WATCHDOG to see if you've had a watchdog timeout. If you have then close all files and ON ERROR ABORT cleanly.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 10:00pm 19 Dec 2021
Copy link to clipboard 
Print this post

on error skip
Open CFN$ For Append As #4
if mm.errno <> 0 then ' do something


~
Edited 2021-12-20 08:02 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 06:07am 20 Dec 2021
Copy link to clipboard 
Print this post

Is there any harm in simply closing it before opening or will that throw an error (don't have a MM in front of me to test)?
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 06:41am 20 Dec 2021
Copy link to clipboard 
Print this post

"closing it before opening or will that throw an error (don't have a MM in front of me to test)?"
From memory it does. 2 solutions

1
on error skip
close #4

2
Open it before the loop so there is something to close on the first pass.
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 986
Posted: 11:58pm 20 Dec 2021
Copy link to clipboard 
Print this post

Here is the amended code I have implemented, fingers crossed.

     If MM.Info$(SDCARD)="Ready" Then
       Pin(PA6)=0
       On Error Skip
       Close #4
       If MM.Errno <> 0 Then
         Open CFN$ For Append As #4
       EndIf
       Print #4, ScrnMsg$
       Close #4
       Pin(PA6)=1
     Else
       GUI DELETE SVE
       GUI BUTTON SVE, "SD ERROR",230, 20,80,20,RGB(RED), RGB(yellow)
     EndIf

Thanks for the help shedders.
OA47
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 12:44am 21 Dec 2021
Copy link to clipboard 
Print this post

" If MM.Errno <> 0 Then"

Is this needed? Either it has just been closed or was never open, either way it can now be opened.
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 986
Posted: 01:29am 21 Dec 2021
Copy link to clipboard 
Print this post

  Quote  " If MM.Errno <> 0 Then"

Is this needed? Either it has just been closed or was never open, either way it can now be opened.


It is needed as if you try to close an already closed port you get an error.

> close #1
Error : File number is not open


OA47
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 04:48am 21 Dec 2021
Copy link to clipboard 
Print this post

Trying to figure how that would be useful.

Pretty certain that an already closed port in MS BASIC doesn't complain....I could be wrong though.
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 06:20am 21 Dec 2021
Copy link to clipboard 
Print this post

The purpose of the
On Error Skip
is to prevent the next line stopping the program.

Manual Page 140
ON ERROR SKIP will ignore an error in a number of commands (specified by
the number 'nn') executed following this command. 'nn' is optional, the default
if not specified is one. After the number of commands has completed (with an
error or not) the behaviour of MMBasic will revert to ON ERROR ABORT.
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 07:07am 21 Dec 2021
Copy link to clipboard 
Print this post

  phil99 said  The purpose of the
On Error Skip
is to prevent the next line stopping the program.

Manual Page 140
ON ERROR SKIP will ignore an error in a number of commands (specified by
the number 'nn') executed following this command. 'nn' is optional, the default
if not specified is one. After the number of commands has completed (with an
error or not) the behaviour of MMBasic will revert to ON ERROR ABORT.


Understood but why would MMBasic care if a port was already closed?
If I set an output-bit low, for example, I don't get a "output already low" if I do it repeatedly.
Just trying to imagine a context where it would protect/prevent something naughty.  
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 07:20am 21 Dec 2021
Copy link to clipboard 
Print this post

"why would MMBasic care if a port was already closed?"

That is a good question, but it does so there must have been a reason.
For OA47's purpose On Error Skip should sidestep the issue.
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2170
Posted: 08:49am 21 Dec 2021
Copy link to clipboard 
Print this post

  Tinine said  Trying to figure how that would be useful.

Pretty certain that an already closed port in MS BASIC doesn't complain....I could be wrong though.


+1

always been a mystery to me... If it's closed and your intention is to close it - who cares if it's already closed? I suppose it gives the possibility of fine(r) control over a system (and it plays to my "you decide how to handle stuff" - don't like languages to make assumptions) - am I reaching?

I don't remember this throwing an error on any flavour of basic I used, but I could easily be wrong.

EDIT: QB45 definitely didn't. I found this the other week... bemused by what my thinking must have been when I wrote it 30+ years ago.



If QB did the "file already closed" thing, this would have been a solid error throw. And it wasn't.
.
Edited 2021-12-21 19:02 by CaptainBoing
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2642
Posted: 12:54pm 21 Dec 2021
Copy link to clipboard 
Print this post

"you decide how to handle stuff"
In Explicit Mode that is the case, but otherwise all sorts of default assumptions are made. That is one of the advantages of BASIC, you don't have to specify every little detail if you know the defaults.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:14pm 21 Dec 2021
Copy link to clipboard 
Print this post

In PureBasic there are functions like isSerial() for you to test before trying to open or close.
If IsSerialPort(#MaximitePort)
   CloseSerialPort(#MaximitePort)
 EndIf

In Liberty Basic, I had to keep flafs to prevent erors when closing
if TooltipsOnMM=1 then re=ReleaseTooltipMemory(hTipMM)
   if configWin=1 then close #config
   if chatWin=1 then close #chat
   if mmchat=1 then re=disconnectSER(connectionID) ' close #MM


In MMBasic, I am happy using flags or 'on error skip'. The choice is yours.
ON ERROR SKIP is more robust when trying to recover form system crashes.

Jim
VK7JH
MMedit
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 08:30pm 21 Dec 2021
Copy link to clipboard 
Print this post

@TassyJim

Devil's advocate: Isn't there the possibility of skipping a legitimate error, though?
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 09:05pm 21 Dec 2021
Copy link to clipboard 
Print this post

  Tinine said  Devil's advocate: Isn't there the possibility of skipping a legitimate error, though?


You can always do
if mm.errno <> 0 then ' do something

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 09:55pm 21 Dec 2021
Copy link to clipboard 
Print this post

  lizby said  
  Tinine said  Devil's advocate: Isn't there the possibility of skipping a legitimate error, though?


You can always do
if mm.errno <> 0 then ' do something


Pretty mind-blowing just how much they crammed in to this thing.  
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025