Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:51 09 May 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 : Com Error on Pi Pico

Author Message
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 982
Posted: 03:02am 08 Mar 2025
Copy link to clipboard 
Print this post

Can someone help me with this error?
........
On Error Skip
Open "COM1:9600" As #1
RCMsg$=Input$(80,#1)
.........

ERROR: File number is not open
[303] RCMsg$=Input$(80,#1)

This is on a 2040 running MM.ver=60001

Am I interpreting the On Error Skip correctly?
OA47
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2414
Posted: 03:25am 08 Mar 2025
Copy link to clipboard 
Print this post

On Error Skip only skips errors in 1 statement unless you specify more.

Try
........
On Error Skip 2
Open "COM1:9600" As #1
RCMsg$=Input$(80,#1)
.........
or
........
Open "COM1:9600" As #1
On Error Skip
RCMsg$=Input$(80,#1)
.........
Both should work.

PS You may want a 5 to 10mS Pause after Open to ensure the port is ready for the data.
Edited 2025-03-08 13:29 by phil99
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9482
Posted: 03:25am 08 Mar 2025
Copy link to clipboard 
Print this post

Have you set the pins for COM1?
Manual page 175, Appendix A...

I get the same error, until I comment-out the ON ERROR SKIP command.
I suspect you have forgotten to assign the COM1 port pins.
The code then skips opening the port(cos it can't as the pins are not assigned), and executes the next line, which is you trying to suck data from the buffer - at which point the interpreter falls over and moans that the port is not open.  



Edited 2025-03-08 13:28 by Grogster
Smoke makes things work. When the smoke gets out, it stops!
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 982
Posted: 03:29am 08 Mar 2025
Copy link to clipboard 
Print this post

@ Grogster
  Quote  Have you set the pins for COM1?


Yes I have set them early in the program.

It is my interpretation that I can use the On Error Skip prior to the Open command so that the program does not trip up if the port is currently Open. Does that make sense?

OA47
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9482
Posted: 03:31am 08 Mar 2025
Copy link to clipboard 
Print this post

Please comment out the ON ERROR SKIP command, rerun the code, and see what error message you get...

If I set the COM port pins, and use your exact code, it runs without issue....  



Edited 2025-03-08 13:35 by Grogster
Smoke makes things work. When the smoke gets out, it stops!
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 982
Posted: 03:35am 08 Mar 2025
Copy link to clipboard 
Print this post

  Quote  Please comment out the ON ERROR SKIP command, rerun the code, and see what error message you get...

The Result is:

ERROR : Already open


OA47
Edited 2025-03-08 13:37 by OA47
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9482
Posted: 03:40am 08 Mar 2025
Copy link to clipboard 
Print this post

THAT is weird..
It's telling you both that the port is NOT open, and also that it is.....
Smoke makes things work. When the smoke gets out, it stops!
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 982
Posted: 03:42am 08 Mar 2025
Copy link to clipboard 
Print this post

My configuration is:
SetPin GP1,GP0,COM1
SetPin GP5,GP4,COM2

As I think is per the manual.

OA47
Edited 2025-03-08 13:42 by OA47
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9482
Posted: 03:49am 08 Mar 2025
Copy link to clipboard 
Print this post

My guess at this point, is that somewhere else in your code, the port is being closed before it gets back around to your original code problem you posted at the start.

At this point, I would probably be using flags(not ON ERROR SKIP) to tell your code when the ports are open and closed, then you can test the flags in your loops as your code runs.

If you don't know what I mean, let me know and I can post some examples, but you might already know the method I mean, so....  
Smoke makes things work. When the smoke gets out, it stops!
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 982
Posted: 03:58am 08 Mar 2025
Copy link to clipboard 
Print this post

@Grogs
I understand your thought process. I have been porting over this code from an ARMITE F4 on which the code works but without the ON Error Skip and OPEN "COM1:9600" as #1. (As I open the port early in the program)

Using the original code when I get to RCMsg$=Input(80,1) I get the Error : File is not open so I thought I would try using the skip and then open in case.

OA47
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2414
Posted: 04:01am 08 Mar 2025
Copy link to clipboard 
Print this post

Unless you have a particular reason to keep opening and closing the port open it before the main loop and just leave it open.
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 982
Posted: 04:10am 08 Mar 2025
Copy link to clipboard 
Print this post

  Quote  Unless you have a particular reason to keep opening and closing the port open it before the main loop and just leave it open


IIRC I did this because of an issue with the F4 firmware many years ago. I also thought that closing the ports would clear the buffers in case of a power loss.

OA47
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2414
Posted: 04:31am 08 Mar 2025
Copy link to clipboard 
Print this post

To clear the buffer before new data is expected to arrive I use:-
RCMsg$ = Input$(255,#1) : RCMsg$ = ""
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 982
Posted: 05:24am 08 Mar 2025
Copy link to clipboard 
Print this post

I went through and commented out all open and close statements other than one just after the ports are defined and the program has been running for an hour. I suspect it is the lower speed of the 2040 that is causing the issue in getting jobs done.
Phil I will implement your buffer clearance code.


Thankyou for your assistance.

OA47
 
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