Hi Ken, Hi Jared,
I am playing with an ASCOM focuser driver I wrote, as the “official” one I am using right now is not very stable (it freezes every now and then, sometimes for some seconds, sometimes forever). When testing, I found out that my driver has the same problems and I could trace this to the fact that SGP is querying the driver from different threads, without syncing the queries.
To better see what is happening I logged the entry and the returning points on the interface (only for those properties or methods which needs access to the hardware over the serial port), like this:
…
Public ReadOnly Property MaxStep() As Integer Implements IFocuserV2.MaxStep
Get
TL.LogMessage("MaxStep Get", myMaxPosition.ToString())
Return myMaxPosition ' Maximum extent of the focuser, a constant.
End Get
End Property
Public Sub Move(Position As Integer) Implements IFocuserV2.Move
TL.LogMessage("Move", "Entered. Target Position: " + Position.ToString())
MoveTo(Position)
TL.LogMessage("Move", "Returning")
End Sub
Public ReadOnly Property Position() As Integer Implements IFocuserV2.Position
Get
TL.LogMessage("Position Get", "Entering")
GetPosition()
TL.LogMessage("Position Get", "Returning: " + myPosition.ToString())
Return myPosition ' Return the focuser position
End Get
End Property
…
And this is a fragment of the ASCOM conversation:
…
15:03:50.335 Connected Get True
.
15:03:50.335 Link Get True
.
15:03:50.367 Connected Get True
.
15:03:50.367 Absolute Get True
.
15:03:50.368 Halt Entered
15:03:50.378 Halt Returning
.
15:03:50.379 Temperature Get Entering
15:03:50.395 Temperature Get Returning: 2,38
.
15:03:50.395 Absolute Get True
.
15:03:50.395 MaxStep Get 50000
.
15:03:50.396 MaxIncrement Get 25000
.
**15:03:50.506 Temperature Get Entering**
**15:03:50.512 Position Get Entering**
**15:03:50.555 Temperature Get Returning: 2,38**
**15:03:50.555 Position Get Returning: 25800**
.
…
.
15:04:07.235 Position Get Entering
15:04:07.254 Position Get Returning: 25800
.
**15:04:07.556 IsMoving Get Entered**
**15:04:07.560 Position Get Entering**
**15:04:07.573 IsMoving Get Returning: False**
**15:04:07.573 Position Get Entering**
**15:04:07.589 Position Get Returning: 25800**
**15:04:07.606 Position Get Returning: 25800**
.
15:04:07.606 MaxStep Get 50000
.
15:04:07.612 IsMoving Get Entered
15:04:07.636 IsMoving Get Returning: False
.
15:04:07.638 Move Entered. Target Position: 26100
15:04:07.670 Move Returning
.
15:04:07.672 Position Get Entering
15:04:07.700 Position Get Returning: 25804
.
15:04:07.794 Position Get Entering
15:04:07.813 Position Get Returning: 25816
.
15:04:07.814 MaxStep Get 50000
…
As you can see, there are interleaved accesses (like at 15:03:50.506 or at 15:04:07.556) , where SGP does not wait for the current request to get answered. This creates problems at the serial interface to the focuser hardware, as the very simple protocol is by no means thread safe.
For this play-driver I could easily solve all problems by putting a sync-lock around the Com-Port access procedure. But, as far as I understood, there is no requirement in ASCOM that a driver should be thread-safe. And I think most of them are not.
Shouldn’t SGP take care of this? I have the feeling that this question should be extended also to the other, non-ASCOM drivers.
Kind regards,
Horia