PDA

View Full Version : Need help writting plugin!!



opusnut
March 4th, 2006, 03:59 AM
Hello, I am trying to write a plugin to control my Directv box thorugh a USB serial adapter. I have all the commands i need for the directv box, i just need to know how to reference my dll through Girder.

I tried to use the generic serial plugin, but i ccant seem to get my device to show up in the list. It is a USB serial adapter.

Any help would be GREAT!

thanx

birty
March 4th, 2006, 04:38 AM
there is a manual in the girder\manual directory

danward79
March 4th, 2006, 04:54 AM
I use several serial adapters with out issues, are you sure it is installed ok?

opusnut
March 4th, 2006, 05:39 AM
I will check out the manual..

My adapter is setup and working fine. Although, when i go to edit the serial event in grider, the dropdown box for devices is empty and no com port is listed. Am i missing a setup step somewhere?

danward79
March 4th, 2006, 05:42 AM
If the com port shows in you system devices, then when you start g4 it should appear

opusnut
March 4th, 2006, 01:44 PM
Well it doesnt. The list always shows empty while the device is working properly. I wrote a plugin for Mediaportal to use it and it works fine.

Rob H
March 4th, 2006, 03:01 PM
Are you talking Girder 3.3 here? It doesn't really sound like Girder 4

opusnut
March 4th, 2006, 11:53 PM
Nope, it is girder 4.

danward79
March 5th, 2006, 12:59 AM
Looks like one for Ron or Mike.

It is not by anychance over com 19 is it?

Rob H
March 5th, 2006, 03:57 AM
Can you post a screenshot of the serial plugin settings page please? I don't think I quite understand what you're describing.

opusnut
March 8th, 2006, 11:31 PM
Here's the screen cap of the serial settings page. My device is a Prolific USB-Serial Adapter running on comport 2. Ive also tried it on port 5, but there is no difference. Nothing shows up in the list of devices on the settings screen in girder. Please help!

thanx

[/img]

Rob H
March 9th, 2006, 03:51 AM
Well, a couple of things

1) That isn't the settings page - File|Settings|Plugins - then select the serial tab.

2) The Prolific USB to serial adapter isn't exactly what I would call a serial device, it's a serial port. The device you'll have it connected to is the DirecTV box.

You need to write a serial device for it - this is a .lua file that's stored in the plugins\serial directory.

If you have the protocol document for the DirecTV box then either Mike or I will get you started

opusnut
March 9th, 2006, 08:56 PM
Ahhhhh... that makes perfect sense!

Here is what i need to send to change channels. If you can get me started with this, i can figure out the rest of the commands myself.

Baud 9600
startbit 1
databit 8
stopbit 1
no parity
no handshaking

COMMAND

FA (command prefix) A6 (set channel command) 00 53 (channel number 83) FF FF (2 Resets) 0D (STB Device Type)

So complete string : FA A6 00 53 FF FF 0D

I really appreciate the help!

thanx!

Rob H
March 10th, 2006, 05:03 AM
This should work, but I did find a web page that said that you had to send the command, wait for an 0xF0 response then send the data. I think that might only apply to the older version of the protocol though.



--[[

RCA DirecTV Satellite Receivers

(c) Copyright Promixis

--]]


local device = serial.Classes.Queued:New({

Name = "DirecTV",
Description = "RCA DirecTV STB",

BaudRate = 9600,
Parity = 0,
StopBits = 0, -- 0 = 1 stopbit.
DataBits = 8,
FlowControl = 'N',
IntraCharacterDelay = 0,
GlobalName = 'DirecTV',
CallbackType = serial.CB_TERMINATED,
SendTerminator = serial.hextobyte ("0D")..serial.hextobyte ("0A"),
ReceiveTerminator = serial.hextobyte ("0D")..serial.hextobyte ("0A"),
IncompleteResponseTimeout = 100,
NoResponseTimeout = 1000,
LogLevel = 0,
CommandPrefix = serial.hextobyte("FA"),
NullChar = serial.hextobyte('00'),
FFChar = serial.hextobyte('FF'),

Initialize = function (self)

self.Serial:RxClear()

gir.LogMessage(self.Name, 'Communications OK',3)
self.Status = "Communication OK"

return serial.Classes.Queued.Initialize (self)

end,


SendCommand = function (self,command,callback)

serial.Classes.Queued.SendCommand (self,command,callback)

end,

Command = function(self, RCAHex, data)
self:SendCommand(CommandPrefix..RCAHex..data)
end,

LeftPadToLength = function(self, aString, length, padWith)
local len = string.len(aString)
if len < length then
return string.rep&#40;padWith, length - len&#41;..aString
else
return aString
end
end,

NullPad = function&#40;self, value, padLength&#41;
return self&#58;LeftPadToLength&#40;value, padLength or 2, self.NullChar&#41;
end,

ChangeChannel = function&#40;self, channelNumber&#41;
self&#58;Command&#40;serial.hextobyte&#40;'A6'&#41;, NullPad&#40;channelNumber&#41;..self.FFChar..self.FFChar&#41;
end,
&#125;
&#41;

serial.AddDevice &#40;device&#41;



Don't forget, this code is untested

opusnut
March 10th, 2006, 08:56 PM
Thanx for the help. This will be a good head start since i am new to lua. I took the code you posted and put in in a lua file just to test it right out of the gate and it loads ok and allows me to add the device, but it keeps listing "cant open port" in the settings no matter what port settings i set it up with.???

opusnut
March 10th, 2006, 08:57 PM
Thanx for the help. This will be a good head start since i am new to lua. I took the code you posted and put in in a lua file just to test it right out of the gate and it loads ok and allows me to add the device, but it keeps listing "cant open port" in the settings no matter what port settings i set it up with.???

opusnut
March 10th, 2006, 09:42 PM
i dont think that girder recognizes my Prolific USB-Serial adapter. It might just be easier to write a specific plugin for my directv box. Can i write a plugin in C#?

opusnut
March 10th, 2006, 09:44 PM
Or is there a way to make calls to a dll from a lua script?

birty
March 11th, 2006, 03:20 AM
yep see http://www.lua.org/manual/5.0/manual.html#3

Promixis
March 11th, 2006, 07:42 AM
i dont think that girder recognizes my Prolific USB-Serial adapter. It might just be easier to write a specific plugin for my directv box. Can i write a plugin in C#?

Plugins are in C/C++ or Delphi.

We are considering some .NET options for lua but they are not availble right now.

However, all this should work just fine via the Prolific adapter. I even think I am using one of those myself. The serial plugin/lua combo is the best way to go.

birty
March 11th, 2006, 08:01 AM
cant you write a lua library dll in C#? you could just load it with require without having to make a girder plugin:
http://luaforge.net/projects/luainterface/

Rob H
March 11th, 2006, 09:27 AM
Thanx for the help. This will be a good head start since i am new to lua. I took the code you posted and put in in a lua file just to test it right out of the gate and it loads ok and allows me to add the device, but it keeps listing "cant open port" in the settings no matter what port settings i set it up with.???

Just to check, you did put this .lua file in the plugins\serial folder?

The Prolific USB to serial adaptor should be supported - I have a couple myself.

What COM port number is the adaptor on?

opusnut
March 11th, 2006, 11:24 AM
Ok so seems after running a few tests that i was having conflict problems and girder couldnt reference that comport. So... Success!! now i just have to play with the lua script a bit to get the functions running ok through scripting.

Thanx alot...

Rob H
March 11th, 2006, 02:40 PM
Phew! :)