PDA

View Full Version : Serial device development; getting 'self' in a callback



Tieske8
March 23rd, 2010, 04:01 AM
Currently developing a serial driver using the queued serial object.

The callback methods for receiving data, do not include the 'self' parameter. Now if I want to set some values on the object, based upon the received answer, I need access to 'self' (not?).

How to go about getting a reference to 'self' in this case? or is there another (preferred) way of achieving this?

any help is greatly appreciated

Rob H
March 23rd, 2010, 11:11 AM
You shouldn't be using callbacks, that will interfere with the normal operation of the serial device.

Just override the ReceiveResponse method but be sure to call the inherited method from within it.

Having said all that the serial classes are really deprecated these days in Girder 5, it's generally better to implement your device using the transport classes if you can. If you're using Girder 4 then you're stuck with the serial classes though.

Tieske8
March 23rd, 2010, 02:35 PM
Hi Rob,

thx for the feedback. I've searched the help files on the transport stuff but couldn't find anything (as opposed to the serial stuff). Seems to me the documentation is really outdated? (has it even changed since Girder 4?)

any way; can you point me to some documentation or examples on creating drivers for a serial connected device using the transport stuff?

thx!

Tieske8
March 25th, 2010, 03:20 AM
Just found the documentation, after checking the site, the manual was an updated one. I was still running one of the early Girder 5 versions. Installed the newer version and all docs are there.

Tieske8
March 25th, 2010, 06:54 PM
You shouldn't be using callbacks, that will interfere with the normal operation of the serial device.

Just override the ReceiveResponse method but be sure to call the inherited method from within it.

I'm sticking to the serial device for now, using the queued object. Checked the help files on this;

Queued Sending
If the device driver object is based on serial.Classes.Queued rather than serial.Classes.Simple, then a more advanced version of SendCommand is available. This stores messages and response functions on a queue. Behind the scenes, the command is sent and when a response arrives the response function is called. Then the next command is sent and so on. It is not necessary to provide a ReceiveResponse replacement.
It explicitly states that no override of "ReceiveResponse" is required, as opposed to your statement. What's the caveat?

The original question stays; how to get a reference to 'self' inside the callback method provided to the 'SendCommand'?

Rob H
April 9th, 2010, 04:35 PM
ReceiveResponse override isn't required, but it is still the recommended way of handling responses.

As I said, do not use callbacks with the serial classes, it will break the operation of the serial device.