|
Post by Rod on Nov 3, 2021 9:06:08 GMT -5
The sleep function allows other threads to continue. A processor can manage many threads sequentially, other programs and Windows activity. Sleep gives up it’s threads time slot for the desired duration. A while wend loop does not and hogs the processor cycles
However the Liberty thread is stalled during sleep so again your program can’t do anything else during the delay.
With a timer delay you can do other things within your Liberty program. Like draw the screen or handle a mouse click to change color. To do this your code needs to be in blocks that handle an event then wait for the next interrupt or user event.
The length of the delay will have an impact on how best to code it. A longish delay suits a timer. A short delay, shorter than 16ms , would actually suit a while wend counter loop but these are not often needed.
The ultimate in my view is to have no delay at all and just have the program sit and wait for the next interrupt handling it immediately.
|
|
|
Post by tenochtitlanuk on Nov 3, 2021 10:18:37 GMT -5
Just adding to Rod's post. Try the code below on your machine. Results will vary with your processor and clock speed. I graph machine processor usage in Linux System Monitor. I gave each 'notice' 5 seconds before responding. to separate the times. print "Starting a long empty loop" for i =1 to 1000000 ' next i notice "OK"
print "Pausing 5 seconds" call pause 5000
print "Sleeping 5 seconds" call sleep 5000 notice "OK"
print "Starting 5 sec timer" timer 5000, [on] wait [on] timer 0 notice "OK"
print "Starting a long empty loop" for i =1 to 1000000 ' next i notice "OK"
print "Done"
end
sub pause mil t =time$( "ms") +mil while time$( "ms") <t scan wend end sub
sub sleep ms calldll #kernel32, "Sleep",_ ms as ulong,_ ret as void end sub
|
|
|
Post by xxgeek on Nov 3, 2021 13:50:07 GMT -5
Greatstuff!. I get it. Thanks for all the effort Rod and tenochtitlanuk
Off to find how to use that dll in Just Basic(along with other dlls), cause there is no calldll in the JB commands list, but dll is in the reserved words list in JB I recall reading about using dlls in JB somewhere. If any of you know offhand where the info is could you let me know. I'm pretty sure I read it in code posted by someone.
|
|
|
Post by Chris Iverson on Nov 3, 2021 14:59:46 GMT -5
CallDLL is an LB exclusive feature, DLLs can't be used from JB.
I suspect DLL by itself remains a reserved word purely as a vestigial feature; it's used as the mode specifier for the OPEN command if you're opening a custom DLL. (Kind of like PASSWORD being a reserved word; it's something only used internally by LB now.)
I'm not even sure you could properly open a DLL in JB(not sure offhand if OPEN X FOR DLL even works), and even if you can, it's pointless, because you can't invoke any functions from the DLL
|
|
|
Post by xxgeek on Nov 3, 2021 15:29:24 GMT -5
CallDLL is an LB exclusive feature, DLLs can't be used from JB. I suspect DLL by itself remains a reserved word purely as a vestigial feature; it's used as the mode specifier for the OPEN command if you're opening a custom DLL. (Kind of like PASSWORD being a reserved word; it's something only used internally by LB now.) I'm not even sure you could properly open a DLL in JB(not sure offhand if OPEN X FOR DLL even works), and even if you can, it's pointless, because you can't invoke any functions from the DLL The following code works in JB. It opens my default browser to the google home page. b$ = "www.google.com" RUN "rundll32.exe url.dll,FileProtocolHandler ";b$ If that code can work with a dll, then I would assume there are other things I could do with that dll as well edit - This page winaero.com/windows-10-rundll32-command-list/has a list of commands that seem to work as well.... Though I only tired a couple to see if any worked at all. Still investigating.... edit - Oh yeah, there is tons you can do with that dll, and other dlls. Found a new toy
|
|
|
Post by Chris Iverson on Nov 3, 2021 16:32:16 GMT -5
RunDLL32 should only be used to call functions that are designed to do so, as doing otherwise can have other side effects such as hanging your system. See docs.microsoft.com/en-US/windows-server/administration/windows-commands/rundll32, this answer here: stackoverflow.com/a/3207411, and Raymond Chen's advice on using RunDLL32: "don't": devblogs.microsoft.com/oldnewthing/20130104-00/?p=5643, as well as some more details about things often gotten wrong here, including rundll32 stuff: devblogs.microsoft.com/oldnewthing/20040115-00/?p=41043The only reason you can sometimes get away with it calling other functions is because Microsoft has put a ton of extra code into RunDLL32 to prevent it from crashing, specifically because they know people abuse it. That shouldn't be taken as permission to keep doing it. See here, Raymond Chen's advice about "throwing garbage on the sidewalk": devblogs.microsoft.com/oldnewthing/20110909-00/?p=9683Also, please note that if you're doing this from JB specifically to be able to call general DLLs, and not for a specific use case that RunDLL32 is designed for(such as opening a specific special Windows dialog for the user), you are explicitly sidestepping a designed feature limitation that Carl has chosen to implement in JB, and will receive no help in doing so here. While we obviously can't stop you from doing so on your own(and I personally certainly don't want to discourage you from experimenting with things on your own, since that's how I've learned everything I know, it's a lot of fun!), we won't help you work around Carl's licensing choices, for what should be obvious reasons.
|
|
|
Post by Carl Gundel on Nov 3, 2021 17:23:07 GMT -5
Greatstuff!. I get it. Thanks for all the effort Rod and tenochtitlanuk Off to find how to use that dll in Just Basic(along with other dlls), cause there is no calldll in the JB commands list, but dll is in the reserved words list in JB I recall reading about using dlls in JB somewhere. If any of you know offhand where the info is could you let me know. I'm pretty sure I read it in code posted by someone. But, this is the Liberty BASIC forum. Why not just use Liberty BASIC? I'll send you discount link if you send me an email asking for one. -Carl
|
|
|
Post by xxgeek on Nov 3, 2021 21:12:12 GMT -5
In due time Carl. Message sent.
@ Chris - I am not the boogey man Chris. And will bow to Carl's instructions. I am merely trying to understand what I, at present, don't(and or didn't) Thanks for all you do here helping people learn.
edit - Apology accepted Chris, but wasn't necessary. I understand.
Your a good man Chris, I can tell by your past posts. (and I've read many of them.) Editted here to keep the thread clean. Sending Chris a message.
|
|
|
Post by Chris Iverson on Nov 3, 2021 21:19:57 GMT -5
My apologies, I didn't mean to come across too harshly.
As I said, I don't mean to crush any curiosity, experimentation, or fun.
Getting your hands in it is the best way to learn, after all! (At least, in my experience. I'd have nowhere near the knowledge I do now without having experimented and broken stuff!)
If there's anything you're curious about, wondering how or why something works or behaves the way it does, I'd be one among many here that'd be happy and excited to explain and demonstrate it. Please don't hesitate to ask!
The only reason I went strict on that particular boundary is because it's something we've dealt with before, with someone who wasn't as curious as you, and was explicitly trying to work around licensing restrictions.
My apologies again for letting that bleed through to you.
|
|
konijn
Junior Member
Posts: 96
|
Post by konijn on Nov 4, 2021 10:19:51 GMT -5
But when I use the sleep function is it possible to scan for an file if it is excisting? in the given time for sleeping? I config the code, tonight the main test
|
|
|
Post by Walt Decker on Nov 4, 2021 10:49:47 GMT -5
Not while the sleep is in effect. If you want to scan, use TIMER instead of sleep.
In effect, sleep suspends all operations of you code and allows other applications to have your application time; in other words, while sleep is in effect, your application does not exist.
|
|
|
Post by Rod on Nov 4, 2021 11:33:11 GMT -5
We need to take a wider view, you can sleep and THEN test for file existence. That might still suit your code.
So your code sleeps for 100ms then tests for file existence. That works. The pc gets on with serial comms and and file handling and other stuff while your program sleeps, then you check if the comms is complete or the file is available and move on.
If you code a while wend loop there is a danger that your pc cannot handle the comms or file handling while it is processing the loop.
Multi processor multithreaded activity confuse the issue. I think single threaded sequential and so far it has always worked.
|
|
konijn
Junior Member
Posts: 96
|
Post by konijn on Mar 1, 2022 14:01:43 GMT -5
I am still testing on this project. Its not so simpel as I tought ! I have to send data over internet to an other location. I thought it was CAN Bus and there are special aplications for to send over and receive. But it was no CAN bus, but differential manchester encoding. So I have to try to find out the code and then try it to send over internet. I am not sure if that wil gonna work?
The problem what appaer now is with the "if file excist" function.
I use the function to see if the file excist and then to delete that specific file. Give it some delay. What sometimes happend is that the file is proccesed by an other aplication (who write the file). Sometimes it is written in a minute and sometimes it takes 10 minutes. Dont ask me why? But LB sees the file excist and want to delete it but that gives error when it is in use by an other program. I hope there is a solution for?
Thanks!!
|
|