PDA

View Full Version : Delay command in Serial Plugin



johnp
June 4th, 2009, 03:10 PM
Hi I need to ensure that there is a delay between each command sent to a serial device

I tried the below command based on Girder4 post:


IntraCommandDelay = 1000,


but it does not seem to work. I see from the log that commands are going out as fast as they can be processeed. I would like them to queue up and be sent at 1 second intervals

Thanks

johnp
June 5th, 2009, 08:00 PM
I know someone out there in Girderland knows how to do this. I am actually surprised is is not out of the box functionality since the 3.2 plugin had this feature. There is a lot of equipment that has limits on how often you can send commands. Some implemet it with a response mechanism, whuile others need you to hold back on the throttle manually. My device is like this.

So, can anyone give me a clue on how to implement this?

Thank you in advance.

Ron
June 8th, 2009, 11:21 AM
This is currently not supported. I'll see if I can add this functionality.

johnp
June 8th, 2009, 11:28 AM
Thanks Ron.

Ron
June 8th, 2009, 12:55 PM
Try the attached core.lua. This assumes a three things.

1. You are using the transport classes (which any new development should)
2. You placed the core.lua file in the luascript\transport folder.
3. You have set the InterCommandDelay as follows:




local DefaultSettings = prepare(
-- first base settigs.
{
Transport = {
Post = {
NoResponseTimeout = 2000,
},
},
Parser = {
Type = constants.parser.TERMINATED,
Terminator = '\r\n',
Timeout = 1000,
},
ConnectionMonitor = {
Interval = 20000,
RetryInterval = 10000,
},
MaxQueuedItems = 20,
InterCommandDelay = 1000,
}
)

johnp
June 8th, 2009, 01:05 PM
This is my initialization script... I am using serial.Classes.Queued. Is that what you mean by using the transport classes?

Thanks!




--[[

Nexus C6 Class for the Generic Serial Plugin
Copyright 2009 (c) Music Mountain Systems

--]]



local super = serial.Classes.Queued


local device = super:New({

Name = 'Nexus_C6',
Description = "Nexus C6 Ditributed Audio System Control Interface",
BaudRate = 9600,
Parity = 0,
StopBits = 0, -- 0 = 1 stopbit.
DataBits = 8,
FlowControl = 'N',
IntraCharacterDelay = 1,
-- this is the intracommand delay in ms
IntraCommandDelay = 1000,
GlobalName = 'NexusC6Serial',
CallbackType = serial.CB_TERMINATED,
ReceiveTerminator = string.char(13)..string.char(10),
SendTerminator = string.char(13),
IncompleteResponseTimeout = 100,
NoResponseTimeout = 1000,
DeviceNumber = 12002, -- Private Use Number
LogLevel = 100,

Initialize = function (self)
self:UpdateStatus ("Opening Port")
if super.Initialize (self) then
--Init Tables
NexusC6 = {
Zones = {},
Sources = {},
Volume = {}
}
NexusC6.Zones["01"] = "Room1"
NexusC6.Zones["02"] = "Room2"
NexusC6.Zones["03"] = "Room3"
NexusC6.Zones["04"] = "Room4"
NexusC6.Zones["05"] = "Room5"
NexusC6.Zones["06"] = "Room6"

NexusC6.Sources["T"] = "Tuner"
NexusC6.Sources["1"] = "Server1"
NexusC6.Sources["2"] = "Server2"
NexusC6.Sources["3"] = "Server3"
NexusC6.Sources["4"] = "Server4"
NexusC6.Sources["5"] = "unused"

NexusC6.Volume["79"] = "0"
NexusC6.Volume["78"] = "1"
NexusC6.Volume["77"] = "2"
NexusC6.Volume["76"] = "4"
NexusC6.Volume["75"] = "5"
NexusC6.Volume["74"] = "6"
NexusC6.Volume["73"] = "7"
NexusC6.Volume["72"] = "9"
NexusC6.Volume["71"] = "10"
NexusC6.Volume["70"] = "11"
NexusC6.Volume["69"] = "12"
NexusC6.Volume["68"] = "14"
NexusC6.Volume["67"] = "15"
NexusC6.Volume["66"] = "16"
NexusC6.Volume["65"] = "17"
NexusC6.Volume["64"] = "19"
NexusC6.Volume["63"] = "20"
NexusC6.Volume["62"] = "21"
NexusC6.Volume["61"] = "22"
NexusC6.Volume["60"] = "24"
NexusC6.Volume["59"] = "25"
NexusC6.Volume["58"] = "26"
NexusC6.Volume["57"] = "27"
NexusC6.Volume["56"] = "29"
NexusC6.Volume["55"] = "30"
NexusC6.Volume["54"] = "31"
NexusC6.Volume["53"] = "32"
NexusC6.Volume["52"] = "34"
NexusC6.Volume["51"] = "35"
NexusC6.Volume["50"] = "36"
NexusC6.Volume["49"] = "37"
NexusC6.Volume["48"] = "39"
NexusC6.Volume["47"] = "40"
NexusC6.Volume["46"] = "41"
NexusC6.Volume["45"] = "42"
NexusC6.Volume["44"] = "44"
NexusC6.Volume["43"] = "45"
NexusC6.Volume["42"] = "46"
NexusC6.Volume["41"] = "47"
NexusC6.Volume["40"] = "49"
NexusC6.Volume["39"] = "50"
NexusC6.Volume["38"] = "51"
NexusC6.Volume["37"] = "52"
NexusC6.Volume["36"] = "54"
NexusC6.Volume["35"] = "55"
NexusC6.Volume["34"] = "56"
NexusC6.Volume["33"] = "57"
NexusC6.Volume["32"] = "59"
NexusC6.Volume["31"] = "60"
NexusC6.Volume["30"] = "61"
NexusC6.Volume["29"] = "62"
NexusC6.Volume["28"] = "64"
NexusC6.Volume["27"] = "65"
NexusC6.Volume["26"] = "66"
NexusC6.Volume["25"] = "67"
NexusC6.Volume["24"] = "69"
NexusC6.Volume["23"] = "70"
NexusC6.Volume["22"] = "71"
NexusC6.Volume["21"] = "72"
NexusC6.Volume["20"] = "74"
NexusC6.Volume["19"] = "75"
NexusC6.Volume["18"] = "76"
NexusC6.Volume["17"] = "77"
NexusC6.Volume["16"] = "79"
NexusC6.Volume["15"] = "80"
NexusC6.Volume["14"] = "81"
NexusC6.Volume["13"] = "82"
NexusC6.Volume["12"] = "84"
NexusC6.Volume["11"] = "85"
NexusC6.Volume["10"] = "86"
NexusC6.Volume["09"] = "87"
NexusC6.Volume["08"] = "89"
NexusC6.Volume["07"] = "90"
NexusC6.Volume["06"] = "91"
NexusC6.Volume["05"] = "92"
NexusC6.Volume["04"] = "94"
NexusC6.Volume["03"] = "95"
NexusC6.Volume["02"] = "96"
NexusC6.Volume["01"] = "98"
NexusC6.Volume["00"] = "100"

self:UpdateStatus ("Initialized")
return true
end
end,



ReceiveResponse = function ( self, data, code )
if math.band (code,serial.RXCHAR) > 0 then -- normal response
gir.TriggerEvent("NexusC6Data",18, data)
end
super.ReceiveResponse (self,data,code)
end,


}
)

serial.AddDevice (device)

Ron
June 8th, 2009, 01:11 PM
no I mean the transport.ABCDE... classes. Check the manual for the tutorial under examples.

johnp
June 9th, 2009, 09:43 AM
OK I see what you mean now. This is what you were talking about before regarding using component manager. I definitely want to jump in to this model of device management. It looks pretty slick.

I did read through the whole tutorial and there does seem to be a lot of black whole stuff going on that I don't understand, but that's OK I guess. What I do need to know is how to accomplish the same things I was doing before under this new schema.

It would be helpful if you could show me using the example I posted above how to convert the old way to the new way. It is pretty typical of the way I did things using generic serial and would go a long way to making me understand how to convert the rest of my devices (and I have quite a few).

Thanks!

Ron
June 9th, 2009, 11:20 AM
Attached you'll find a template.

It goes into the luascript/transport/devices directory.

To access the all instances of this class use this code:



local c = ComponentManager:GetComponentUsingName("Transport Manager")

-- Modify this path to match the source lua file of the object you are trying to access.
local path = gir.ParseString('%GIRDER%') .. "luascript\\transport\\devices\\NexusC6.lua"


-- If there are more then one instance possible of the object use this bit of code
local RunningInstanceSettings = c.InstanceSettings:Match({ ClassFilename = path } )
for i, settings in ipairs( RunningInstanceSettings ) do

local instance = c:GetInstance( { Name = settings.Name } )
if instance then
print("Found Instance " .. instance.Name );
instance:Send("Hello",false)
end

end
If you know the name of the object you can do this




local c = ComponentManager:GetComponentUsingName("Transport Manager")
local d = c:GetInstance( { Name = "My NexusC6" } )
d:Send('hello', false) -- false here to tell Girder not to expect a response.

johnp
June 10th, 2009, 09:24 AM
Thanks Ron,

That helps a lot. I still have some transport manager questions, but I will post those in a different thread since it is a bit off the original topic.

Thanks again.