-
June 29th, 2006, 06:50 PM
#1
Syntax for sending serial commands in lua
Want to send command in lua to my Theta what is the best way to do this? is it
function Select_input3 = self.SendCommand([04050300]) end
function Select_input6 = self.SendCommand([04050600]) end
Then in future I can just call function .....yes and what is syntax for that? And how can I make it so I can call these functions from any lua script in Girder?
Thanks
Last edited by rickd; June 29th, 2006 at 07:33 PM.
Rickd
-
June 29th, 2006, 09:22 PM
#2
Rick if you add the commands as part of the serial theta object it would be diff. vs. just calling the commands from lua script elsewhere...
note: you can send serial stuff from the action tree. do you need to do this from lua?
-
June 29th, 2006, 10:07 PM
#3
Not necessarily but all my serial commands in the girder tree did not come across so I was thinking of just putting them into the theta definition file if I can call them from any lua script in the tree...either that or enter them in the tree as send serial commands that I trigger on conditions....what do you recommend? Either way I have to re-enter them....
My preference is to put them in theta cass definition file as long as I can call them from other lua scripts which are triggered by the event we setup in that file.
Last edited by rickd; June 29th, 2006 at 10:13 PM.
Rickd
-
June 29th, 2006, 11:03 PM
#4
ok, in the body of the class add
MyFunction = function (self)
local bytes = math.hextobyte ('AABBCCDD')
self:SendCommand (bytes)
end,
-
June 29th, 2006, 11:10 PM
#5
Ok so I can do this for all serial functions I want to send
Example two cammands
Input3 = function (self)
local input3bytes = math.hextobyte ('AABBCCDD')
self:SendCommand (input3bytes)
end,
Input6 = function (self)
local input6bytes = math.hextobyte ('AABBCCDD')
self:SendCommand (input6bytes)
end,
So to call that in lua elsewhere in the tree do I
go Casablanca.Input3 ????? what is syntax to execute that elsewhere
Sorry in body of class means what part of script?
I am very new to this and no programmer
Last edited by rickd; June 29th, 2006 at 11:19 PM.
Rickd
-
June 30th, 2006, 03:28 PM
#6
rick
see the below with the function added as it should be
you call using
Casablanca:Input3 ()
note the ':' and not '.'
--[[
Theta Digital
Casablanca III
(c) Promixis
--]]
local Params = {
'Input',
'Audio_Jack',
'Video_Jack',
'Volume',
'Mode',
'Standby',
'Lock',
'Sample_rate',
'Mute',
'Display',
'Analog_level',
'Remotepower',
'Menu_no',
'Tape_follow_input',
'Balance_clear',
'Balance_analog_input_level',
'Tapeout',
'Unused18',
'Level_master_initial',
'Phase',
'Balance_eq',
'Main_time',
'Cursor_vfd',
'Sys_frcen_frsub',
'Main1_type',
'Sys_bal3_sub4_sub5',
'Volume_fast',
'Main2_type',
'Level_max',
'Tape_digital_source',
'Remote_pulse_duration',
'Tapedigital',
'Tapevideo',
'Mute_level',
'Mute_trigger',
'RS232_baud',
'Unused37',
'RS232_echo_status',
'Unused39',
'Unused40',
'Volume_slow',
'Unused42',
'Unused43',
'Unused44',
'Unused45',
'Main_off_sequence',
'Remote_type',
'Main3_type',
'Balance_l_r',
'Balance_f_r',
'Balance_ctr',
'Balance_subs',
'Analog_tapeout',
'Analoglevel_1',
'Analoglevel_2',
'Analoglevel_3',
'Analoglevel_4',
'Analoglevel_5',
'Analoglevel_6',
'Unused60',
'Unused61',
'Unused62',
'Unused63',
'Msg_mode',
}
local device = serial.Classes.Queued:New({
Name = "Casablanca III",
Description = "Theta Digital Casablanca III Rev B Version 3.xx" ,
BaudRate = 19200,
Parity = 0,
StopBits = 0,
DataBits = 8,
FlowControl = 'N',
CallbackType = serial.CB_FIXEDLENGTH,
ReceiveFixedLength = 64,
IncompleteResponseTimeout = 40,
NoResponseTimeout = 1000,
SendStartByte = string.char (254,236),
GlobalName = 'Casablanca',
LogLevel = 0,
Initialize = function (self)
self.Status = 'Port Opened'
-- setup settings table
self.Settings = {}
for _,param in ipairs (Params) do
self.Settings [param] = false
end
return serial.Classes.Queued.Initialize (self)
end,
ReceiveResponse = function ( self, data, code )
if code == 1 then
local oldsettings = table.copy (self.Settings)
for i,param in ipairs (Params) do
self.Settings [param] = string.byte (data,i)
if self.Settings [param] ~= oldsettings [param] then
gir.TriggerEvent (self.GlobalName..': 'param,18,self.Settings [param])
end
end
end
if math.band (code,serial.INCOMPLETERESPONSETIMEOUT) > 0 then
gir.TriggerEvent (self.GlobalName..':ThetaCommand Failed',18)
-- not enough bytes received response
--check what command was sent then retry
end
if math.band (code,serial.NORESPONSETIMEOUT) > 0 then
gir.TriggerEvent (self.GlobalName..':ThetaCommand Noresponse',18)
-- no response, request status
end
serial.Classes.Queued.ReceiveResponse (self,data,code)
end,
Input3 = function (self)
local input3bytes = math.hextobyte ('AABBCCDD')
self:SendCommand (input3bytes)
end,
end,
}
)
serial.AddDevice (device)
-
July 3rd, 2006, 11:15 PM
#7
Mike one question if I want to call one of these functions to send a serial command under
if math.band (code,serial.INCOMPLETERESPONSETIMEOUT) > 0 then
Casablanca:Request_state
where this is the function defined below and Request State is a serial command requesting the 64 bytes again
would that work given the definition of that serial send would be after this?
Rickd
-
July 4th, 2006, 02:13 AM
#8
You'd use self:RequestState() rather than Casablanca:RequestState()
--Rob
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules