PDA

View Full Version : Transaction Responses and Lua Patterns



dmurphy
July 26th, 2010, 10:32 AM
I've modified tutorial2.lua to work with my device, but I have a question about handling responses.

When I send the command 'cc' to my device, it will respond with 'ch' followed by a number. I assume I need to use LUA patterns, but can't seem to figure out what the right syntax should be.

Here's what it looks like now:


local GetPreview = EventixTransaction:Subclass ( {

Send = {
Command = "cc",
},

Response = {
Command = 'ch',
},
})

What do I need to replace Command = 'ch' with?

Thanks!

Ron
July 26th, 2010, 01:05 PM
You'll need to add a bit of code to extract that.



local GetPreview = EventixTransaction:Subclass ( {

Send = {
Command = "cc",
},

Response = {
Command = 'ch',
Params = {
[1] = {
Parse = function(self, parameter) return tonumber(parameter) end,
},
}
},

AnalyseResponse = function(self, data, obj)
local _, _, value = string.find(data, 'ch(%d+)')
return 'ch', {value}
end,

})


This is code adapted from the transaction based example in the transport tutorial.

dmurphy
July 26th, 2010, 04:15 PM
That worked perfect. For some reason it hadn't clicked that I could override that function.

Here's a similar question:

I need to be able to a send parameter followed by the command. For example: 1CN switches to input 1. What function do I need to override in order to define how the command is put together?