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.
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 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...
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 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 KingdomPosts: 10222
Posted: 08:18pm 26 Jul 2016
Copy link to clipboard
Print this post
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 ZealandPosts: 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!