-
Hello... does anyone know why this made my vb6 not work? and i have to restart the computer in order for vb to work again?
Dim TimeNow As Long
Dim CurrentTime As Long
MSComm1.RTSEnable = True
TimeNow = GetTickCount
CurrentTime = TimeNow
' Busy wait here for 5 milliseconds
Do Until (CurrentTime - TimeNow > 5)
CurrentTime = GetTickCount
Loop
'Some code here
TimeNow = GetTickCount
CurrentTime = TimeNow
' Busy wait here for 15 milliseconds
Do Until (CurrentTime - TimeNow > 15)
CurrentTime = GetTickCount
Loop
MSComm1.RTSEnable = False
----- If i don't put in the 15ms busy wait and just go on.. then it will not crash... so I don't think it's the GetTickCount... any ideas would be greatly appreciated..
Thanx in advance! =)
-
Maybe I should use and declare different variables?
-
Give me your code for GetTickCount. I think it's very possible that's where the error is coming from...
Litehouse
-
Humm.. GetTickCount is only a lib or something that i call.. and the declare is below :
Private Declare Function GetTickCount Lib "kernel32" _
() As Long
-
Are you working with COM ports? If so then dont foget that COM ports operate asynchronicaly. You are using loop with out DoEvents and you perfom some codes before Waiting 15 msec. You have to be sure there are no activity on COM Port before entering waiting loop, or place Doevents inside the loop.
-
LG:
Thanx for responding.. =)
Yes.. i'm working with COM ports.
Yes.. There are events going on in the COM port while i'm waiting, actually, that's why i'm waiting.. for the event to finish before i turn off RTS
So i looked up DoEvent.. and it's functionallity is it Yields execution so that the operating system can process other events.
So i now try to change the code to this :
' Busy wait here for 15 milliseconds
Do Until (CurrentTime - TimeNow > 15)
DoEvent()
CurrentTime = GetTickCount
Loop
-- and see what happens.
-- So with events firing in the COM ports, I can't call any system calls?
-
It is not about system events, realy.
I uderstand this like:
VB doesn't have a control over COM port because COM is a sistem device, end servised by system. But VB is notified by OS about any changes in COM port status and its in and out buffers. If in any moment VB loosing tracking of changes in COM status it is a system failure for VB and it stops responding without raising runtime errors. When you make such loops you are preventing VB from recieving OS notifications about COM status and VB goes crasy.
but.... that is my point of view. I do a lot of serial communications programming and getiing problems like that time to time. And every time it happens to be something new and unique.