![]() |
Forum Index : Microcontroller and PC projects : Comm Port Still open after Watchdog timeout
Author | Message | ||||
OA47 Guru ![]() Joined: 11/04/2012 Location: AustraliaPosts: 986 |
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 KingdomPosts: 7938 |
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 StatesPosts: 3378 |
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 KingdomPosts: 1646 |
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: AustraliaPosts: 2642 |
"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: AustraliaPosts: 986 |
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: AustraliaPosts: 2642 |
" 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: AustraliaPosts: 986 |
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 KingdomPosts: 1646 |
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: AustraliaPosts: 2642 |
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 KingdomPosts: 1646 |
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: AustraliaPosts: 2642 |
"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 KingdomPosts: 2170 |
+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: AustraliaPosts: 2642 |
"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: AustraliaPosts: 6283 |
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 KingdomPosts: 1646 |
@TassyJim Devil's advocate: Isn't there the possibility of skipping a legitimate error, though? |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3378 |
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 KingdomPosts: 1646 |
Pretty mind-blowing just how much they crammed in to this thing. ![]() |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |