Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 02:41 08 Jul 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 : Coms Open/Close

Author Message
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 01:50am 26 Jul 2016
Copy link to clipboard 
Print this post

Just wondering what's best practice?

Open Com1 before the main loop & leave it open till whenever?

Or, should it be opened & closed within this Sub?

[Code]
Sub SendData
Local Null$=INPUT$(LOC(#1),#1) 'then suck everything in the buffer out and stick it in Null. Just for now. Will Check the call ID it later...

'Add Jim's CRC Check in Later.


Print #1,"Air Temp=";Str$(TmpHpAir,3,2);"#"
Print #1,"EvapTemp=";Str$(TmpHpEva,3,2);"#"
Print #1,"CompTemp=";Str$(TmpHpCmp,3,2);"#"
Print #1,"Inp Temp=";Str$(TmpHpInp,3,2);"#"
Print #1,"Out Temp=";Str$(TmpHpOut,3,2);"#"
Print #1,"Loop Num=";LoopCount

End Sub
[/code]

Thanks

Phil
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9590
Posted: 07:14pm 26 Jul 2016
Copy link to clipboard 
Print this post

I always open the COM port and leave it open forever.
That is just me though.
There is no law that says you should close it.
The serial-port buffers will look after any data for you.

It does very-much depend on what you are doing.

Does LOCAL work like that?
I know you can use it to define local variables, but can you use it to define a local-only variable AND assign it data at the same time?
In any event, it will only EVER check the serial-port and suck the data out of it, when it runs that LOCAL command, which it only ever does once, so I would still prefer to put the Null$=Input$ elsewhere.

Again - just my 2c.
Others here will say if it is OK to use LOCAL like that, and if it is, then I have learned something new myself.
Smoke makes things work. When the smoke gets out, it stops!
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10222
Posted: 08:18pm 26 Jul 2016
Copy link to clipboard 
Print this post

  Quote  Others here will say if it is OK to use LOCAL like that, and if it is, then I have learned something new myself


It is absolutely OK to use LOCAL like that. The statement is run each and every time the subroutine is called. LOCAL variables only exist when the subroutine is running. Any memory used is returned to the pool when the subroutine exits.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9590
Posted: 02:35am 27 Jul 2016
Copy link to clipboard 
Print this post

Okey dokey, thanks for that - I have updated my memory.
Smoke makes things work. When the smoke gets out, it stops!
 
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