Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:03 13 Nov 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 : PEEK-ing a COM port....

Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9755
Posted: 02:13am 29 Aug 2019
Copy link to clipboard 
Print this post

Hello.

Is there a PEEK location for the status of the COM ports that I can read inside a code to know if the port is open or closed?

I often run into the problem where if I try to open the COM port, MMBASIC says it is already open, or if I try to close it, MMBASIC says it is not open.  Being able to check a PEEK address to find out if a COM port is open or not would be really helpful.
Smoke makes things work. When the smoke gets out, it stops!
 
BrianP
Senior Member

Joined: 30/03/2017
Location: Australia
Posts: 292
Posted: 03:08am 29 Aug 2019
Copy link to clipboard 
Print this post

Following up on Grog's issue:
I have an installation where we run a Windows PC talking to a CMM over the serial bus. Whenever the PC is rebooted (Windows remember) the Com port is re-established but DOS MMbasic can't talk to the CMM until I open a terminal program (GFXterm) & manually connect. After then closing GFXterm DOS MMbasic can then talk to the CMM.
I haven't been able to get my head around what I might need to do to not have to manually connect to the CMM before DOS MMbasic can talk to it. I know I've missed something very basic (no pun) but it still escapes me.

Hope I haven't hijacked your thread Grogs

B
 
Poppy

Guru

Joined: 25/07/2019
Location: Germany
Posts: 486
Posted: 05:01am 29 Aug 2019
Copy link to clipboard 
Print this post

Actually PEEK and POKE would be a great general topic.

Is there any overview available of "where and what for" for the PIC32 and MMBASIC?

OR could everybody individually show what has already been found out and well-tried yet?!
(Not spoiling this thread, then opening a new one)


Andre ... such a GURU?
 
PicFan
Senior Member

Joined: 18/03/2014
Location: Austria
Posts: 133
Posted: 08:26am 29 Aug 2019
Copy link to clipboard 
Print this post

Maybe a solution ?



OPEN "COM1:9600" as #1

ON ERROR SKIP
PRINT #1, "TEST"
IF (MM.ERRNO <> 0) THEN
 PRINT "COM IS CLOSE, RE OPEN !"
 OPEN "COM1:9600" AS #1
ELSE
 ON ERROR ABORT
 PRINT "COM IS OPEN !"
ENDIF



 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2171
Posted: 08:42am 29 Aug 2019
Copy link to clipboard 
Print this post

requests for useful addresses have been made and answered on and off over the years - I think we all like the idea from our 8bit origins (RAND USR 16514 anyone?) Geoff did post a list of some useful ones but is wasn't extensive.

I too would like a big list but unless jumpblocks (which delay things) are used internal to the compiled code the addresses will likely move about depending on the version/platform in use so really we shouldn't get into the habit of using memory manipulation if we want our code to be largely platform independent - Jumpblocks made the CPC range of 8 bitters really good like this and code was very compatible unless you used the plethora of direct ROM calls to speed things up or add features... I discovered the error trap in the rom but it was different in the 6128 because of language changes... shame that wasn't "JBed". Better to find ways to do the clever management within the bounds of the provided language and it contains some useful tricks to help.

@Grogs; I tend to open a port and leave it open - we are not multi-tasking so who cares if I hog the port. I agree the "port not open" error is a bit of an odd one... if the port wasn't open then it is closed and the attempt was to close it anyway so job done - however in the interests of control I can see why things work the way they do.... and as I don't tend to close ports much I rarely bump into such things. When I do need a test I like to use code to force an error condition and then trap it this method is still the same tho' better mechanisms in modern methods with TRY, THROW and CATCH etc but I think industrial scale error trapping is not such a big issue in the lonely world of microcontroller code

OK, enough waffling, here's a couple of MMBasic fixes for the two you mention above


' defeat error on CLOSE when closed
On Error Skip 1
Close 1



'test port open
Function POpen(Port As Integer) As Integer
Local Integer x
POpen=0
On Error Skip 2
x=Lof(Port)
POpen=1
'here POpen=0 for closed or 1 for open
End Function


does this help a bit?
Edited 2019-08-29 19:02 by CaptainBoing
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 11:54am 29 Aug 2019
Copy link to clipboard 
Print this post

This was Geoff's list of PEEKable items he posted back in March 2017. The first thread on it is shown at the top of the list. There's also one at the bottom given a year or so later by Peter Mather re USB connections - that one might or might not help you Grogs. I kept these but don't have any more info since then.

Greg


1st thread on this - http://www.thebackshed.com/forum/forum_posts.asp?TID=8575&PN=15
--------------------------------------------------------
Is AUTORUN on?  Returns 1 if yes or 0 if no
peek(byte peek(word &H9D000090))

The current display type
peek(byte peek(word &H9D000090) + 20)
where:
   No Display  =    0
   SSD1963_4   =    1
   SSD1963_5   =    2
   SSD1963_5A  =    3
   SSD1963_7   =    4
   SSD1963_7A  =    5
   SSD1963_8   =    6
   ILI9341     =    7
   ILI9163     =    8
   ST7735      =    9

The display orientation (1 = landscape, 2 = portrait, 3 = RevL, 4 = RevP)
peek(byte peek(word &H9D000090) + 21)

The I/O pin used for touch CS (zero means that touch is not configured)
peek(byte peek(word &H9D000090) + 22)

The I/O pin used for touch INT (handy if you want to set an interrupt on touch)
peek(byte peek(word &H9D000090) + 23)

Is the touch calibrated?  Zero means no, non zero yes.
peek(word peek(word &H9D000090) + 28)

The I/O pin used for the LCD CS (zero means that the LCD is not configured)
peek(byte peek(word &H9D000090) + 45)

The I/O pin used for the LCD CD
peek(byte peek(word &H9D000090) + 44)

The I/O pin used for the LCD reset
peek(byte peek(word &H9D000090) + 46)

The I/O pin used for the SD card CS (zero means that the SD card is not configured)
peek(byte peek(word &H9D000090) + 48)

What MMBasic thinks is the width of the console in characters
peek(byte peek(word &H9D000090) + 5)

What MMBasic thinks is the height of the console in lines
peek(byte peek(word &H9D000090) + 4)
----------------------------------------------------------
These also PEEKable - ex Peter Mather
--------------------------------

is it possible to have a variable MM.USB=1 that indicates a USB console connection?

This will tell you if the USB is plugged in:

? peek(word &HBF885060) and 1
1=yes
0=no
---------------------------------
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9755
Posted: 12:40am 30 Aug 2019
Copy link to clipboard 
Print this post

Thanks chums.
I had forgotten about the ON ERROR SKIP command, which will fix that issue for me, if I use it correctly, in other words:

ON ERROR SKIP
OPEN "COM1:9600" as #1


...will get around the 'COM port not open' one, and...

ON ERROR SKIP
CLOSE #1


...will get me around the other one.  Should have thought of that.  

So many things to remember with MMBASIC and what it can do these days.
It's a beast!  
Smoke makes things work. When the smoke gets out, it stops!
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2171
Posted: 07:07am 30 Aug 2019
Copy link to clipboard 
Print this post

yep.. agree with all of those sentiments  

one tiny point. I think the On Error Skip with no argument is deprecated i.e.

instead of
On Error Skip


one should use
On Error Skip <arg>


small point... think it came in on 5.4 ish and approaches On Error Goto which is a lot more difficult to do than you'd think - (Geoff's comment about half way down)https://www.thebackshed.com/forum/ViewTopic.php?TID=9842&PID=108713#108713
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 08:39pm 30 Aug 2019
Copy link to clipboard 
Print this post

I generally set my own flag when opening a port and reset the flag when closing the port....what am I missing?  
 
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