PDA

View Full Version : Tutorial Example 2 questions



vitello
January 2nd, 2010, 06:01 PM
Ron,

I have been playing with Tutorial Example 2 and I have a couple of
questions. After adding GC Tutorial 2 using the Transport Manager tab I use a script action
to access it, for example

local c = ComponentManager:GetComponentUsingName("Transport Manager")
local d = c:GetInstance( { Name = "My GC Tutorial 2" } )
print(d)
d:_GetVersion()

This returns on the Lua console the expected response

table: 2043B670
SEND 76 65 72 73 69 6F 6E 0D
RECEIVE 76 65 72 73 69 6F 6E 2C 30 2C 33 2E 30 2D 30 36 version,0,3.0-06
Complete function: 119C38D8
My GC Tutorial 2 version 0 3.0-06

When I do the command d:_GetDevices() the response is

table: 2043B670
SEND 67 65 74 64 65 76 69 63 65 73 0D
RECEIVE 64 65 76 69 63 65 2C 31 2C 31 20 53 45 52 49 41 4C device,1,1 SERIAL
Incomplete function: 0F767448
RECEIVE 64 65 76 69 63 65 2C 32 2C 33 20 49 52 device,2,3 IR
Incomplete function: 0F767640
RECEIVE 65 6E 64 6C 69 73 74 64 65 76 69 63 65 73 endlistdevices
Complete function: 1FAFE148

What is the significance of the Complete and Incomplete function statements?

Thanks to the help,

Peter

Rob H
January 3rd, 2010, 07:54 AM
Those are the addresses of the functions that are called when you receive a complete response and an incomplete response to a command. The complete response function is called when the termination conditions are satisfied, e.g. you've received a certain number of characters, or you've received the terminator. The incomplete response function is called if there's a timeout before the termination conditions are satisfied.

I hope that helps.

vitello
January 5th, 2010, 09:27 PM
Rob,

Yes that helps. I traced down the print statement in the TransactionManager.

My next question concerns _GetDevices. This command does not seem to lead
to SetResults getting called. In tutorial 2, SetResults for GetDevices is

SetResults = function(self, obj, a,b)
print(obj.Name .. " found device: ", a,b)
obj:_GetModuleVersion(tonumber(a))
end,

and there should be printed output. What I see is

table: 0DB58840
SEND 67 65 74 64 65 76 69 63 65 73 0D
RECEIVE 64 65 76 69 63 65 2C 31 2C 31 20 53 45 52 49 41 4C device,1,1 SERIAL
Incomplete function: 1B5135B8
RECEIVE 64 65 76 69 63 65 2C 32 2C 33 20 49 52 device,2,3 IR
Incomplete function: 1B513698
RECEIVE 65 6E 64 6C 69 73 74 64 65 76 69 63 65 73 endlistdevices
Complete function: 1B505030

I was also playing with tutorial3, where GetDevices should call AddDevice in its SetResults.
SetResults doesn't get called here either for GetDevices, which is probably why no
devices seem to get created for tutorial3. (By the way, my source for tutorial3 was
missing the coding for GetModuleVersion. I copied the coding from tutorial2).

So, any idea why SetResults doesn't seem to get called by GetDevices? It is
called for GetModuleVersion and GetVersion in tutorial2. Is it possible that this
has to do with GetDevices having an EndResponse command which the other
transactions don't?

Thanks for any help,

Peter

vitello
January 6th, 2010, 02:07 AM
I may be wrong about this, but I think I see why GetDevices in tutorial 2 and 3 doesn't
call SetResults. I've been playing around with the lua debugger and this is what I found.

In the Girder5\luascript\tansport\TransactionManager.lua file the function
_ProcessResponse gets a responsecode and handler from command:ProcessResponse.
If the responsecode is Transaction.Response.Complete, which is what is returned for
transactions without a EndResponse, then the handler (SetResults) gets called. If the
responsecode is Transaction.Response.Incomplete, the handler (again SetResults) doesn't
get called. For this case _ProcessResponse returns with a Wait setting. The Wait
setting leads to ArmNoResponseTimer being armed, but it looks like the event isn't
followed after that.

As I said, I may be wrong about the logic here, but the debugger is taking me though
this coding.

Peter

vitello
January 8th, 2010, 02:32 AM
I modified Girder5\luascript\tansport\TransactionManager.lua and tutorial2 and 3 now
seem to be working for GetDevices and the other commands. I changed _ProcessResponse
from

elseif responsecode == Transaction.ResponseCodes.Incomplete then
return self.Transport.Transport.ResponseCodes.Wait
end

to

elseif responsecode == Transaction.ResponseCodes.Incomplete then
handler (self.Transport)
return self.Transport.Transport.ResponseCodes.Wait
end

The tutorial3 example now generates devices under the devicemanager.

Does this look like a fix or are there some bad side effects that could come from this?

Peter

Rob H
January 8th, 2010, 06:59 AM
I really wouldn't recommend that, it could easily break some devices.

Has your GlobalCaché had modifications to its firmware? It sounds as though it's not sending an 'endlistdevices' response after sending the device details.

I don't have a GlobalCaché here to test unfortunately.

Ron
January 8th, 2010, 10:38 AM
It's been a while since I wrote those tutorials. But looking at it I never intended for Tutorial2 to use the device manager. Only tutorial3 should do that. I am sure you saw the accompanying documentation in the manual.

Ron
January 8th, 2010, 11:09 AM
w.r.t. TransactionManager.lua I think you are right, the handler should be called both on incomplete and complete. However I am very hesitant to change that now. As Rob said that might cause something else to break. However looking at what we'd have to do to tutorial 3 isn't very pleasant either and it leaves us with a bug in the transport classes.

I went back in the source code history and looks like I moved the handler inside the if,.. whereas that is not quite right. I suggest we change the code as you have above.



if responsecode == Transaction.ResponseCodes.Complete then

handler (self.Transport)

if not command:IsPersistent() then
self:_RemoveFromQueue(index)
return self.Transport.Transport.ResponseCodes.Ok
end
elseif responsecode == Transaction.ResponseCodes.Incomplete then

handler (self.Transport)

return self.Transport.Transport.ResponseCodes.Wait
end
end


Good spotting!

vitello
January 8th, 2010, 09:12 PM
Ron/Rob,

Thanks for the quick replies. Your are right, tutorial2 doesn't call the device manager, but
I noticed for both tutorial2 and tutorial3 that GetDevices wasn't responding properly.

I got some good use out of the lua debugger. It would be nice to be able to view inside
of table variables to keep track of data.

I'm planning on doing a detailed Panasonic TV serial port setup so I'm sure I'll have
more questions.

Peter

dmurphy
July 26th, 2010, 12:31 PM
I'm glad this was spotted.

Is there a reason this change hasn't been pushed into the latest Girder release?