View Full Version : Serial receive help needed
bl123
November 10th, 2008, 05:39 AM
I could use a hand figuring out why I'm not receiving data from my Pioneer VSX-45TX. I know the communication path is OK - I can send commands and receive responses using "LookRS232". My lua driver seems to be working OK and Girder can send commands to the VSX just fine (using Serial Send).
I was expecting that when I send a command such as "?V<cr>" (request volume status) the function ReceiveResponse would automatically be called from an interrupt when the VSX sends its response (maybe this is the wrong assumption?). It appears ReceiveResponse is never called. Probably a simple mistake on my part but I'm stuck!
Here is my VSX45TX.lua...
--[[
VSX45TX Serial Plugin
--]]
local device = serial.Classes.Simple:New({
Name = "VSX45TX",
Description = "VSX45TX driver",
BaudRate = 9600,
Parity = 0,
StopBits = 1,
DataBits = 8,
FlowControl = 'N',
IntraCharacterDelay = 500,
Status = "Running",
GlobalName = 'VSX45TX',
LogLevel = false,
PluginID = 11111,
CallbackType = serial.CB_TERMINATED,
ReceiveTerminator = string.char(13,10),
ReceiveTerminatorLength = 2,
Initialize = function (self)
self.Serial:SetDTR(true)
self.Serial:SetRTS(true)
win.Sleep(500)
self.Serial:RxClear()
win.Sleep(500)
self:UpdateStatus ("Enabled For Me")
self.Serial:RxClear()
gir.LogMessage('VSX45TX', 'VSX45TX Enabled for you',3)
return true
end,
ReceiveResponse = function ( self, data, code )
print ('Entered ReceiveResponse Function')
if math.band (code,serial.RXCHAR) > 0 then
local c = serial.binarytohex(data)
self:UpdateStatus ("Enabled - Received: "..c)
gir.LogMessage('VSX45TX', 'VSX45TX sent a char',3)
print("VSX45TX Sent: "..c)
end
serial.Classes.Simple.ReceiveResponse(self,data,co de)
end,
}
)
Ron
November 10th, 2008, 05:44 AM
IF indeed you are only expecting <CR> as the terminator you should change these lines:
ReceiveTerminator = string.char(13,10),
ReceiveTerminatorLength = 2,
to
ReceiveTerminator = string.char(10),
ReceiveTerminatorLength = 1,
(if that doesn't work try 13 instead of 10)
bl123
November 10th, 2008, 06:00 AM
For the VSX, the terminator for sending data to the device is <CR>. For receiving data from the device the terminator is <CR><LF>. But that's not a bad idea to try a single terminator...
bl123
November 10th, 2008, 06:05 AM
still nothing with single terminator - tried <CR> and then <LF>. It doesn't even execute the print statement.
Ron
November 10th, 2008, 06:09 AM
Are you getting any errors at all in the console?
Is LookRS232 showing you any data coming back? Can you copy and paste some of that data?
bl123
November 10th, 2008, 06:23 AM
Are you getting any errors at all in the console?
Is LookRS232 showing you any data coming back? Can you copy and paste some of that data?
No errors from the console... here is LookRS232 hex dump for a "?V" (request volume) command. At the bottom you can see the ?V command I sent. The response was "VOL44<CR><LF>" (Volume = 44)
0325.891<0A |.
0325.875<0D |.
0325.859<34 |4
0325.844<34 |4
0325.812<4C |L
0325.797<4F |O
0325.781<56 |V
0325.750|Signal changed: CTS:ON
0325.750>3F 56 0D |?V.
bl123
November 10th, 2008, 06:28 AM
I shouldn't have to do anything to call the ReceiveResponse function - it should happen whenever data is received, correct?
Ron
November 10th, 2008, 06:33 AM
Yes, but you are building this on an older system, I'm putting someting together built on the new transport system...
Ron
November 10th, 2008, 06:38 AM
Save this a file called "VSX45TX .lua" in the luascript/transport/devices directory.
--[[
VSX45TX
--]]
local Super = require('transport.Base')
local prepare = require('transport.PrepareSettings')
local constants = require('transport.constants')
local table = require('table')
local print = print
local math = require('math')
module("transport.devices.VSX45TX")
local DefaultSettings = prepare(
-- first base settigs.
{
Transport = {
Post = {
NoResponseTimeout = 2000,
},
},
Parser = {
Type = constants.parser.TERMINATED,
Terminator = '\r\n',
Timeout = 1000,
},
},
-- overrides for serial transport
{
Transport = {
Post = {
Baud = 9600,
Flow = 'N',
Parity = 'N',
DataBits = 8,
StopBits = 1,
},
},
}
)
local VSX45TX = Super:Subclass ( {
Name = 'VSX45TX ',
Description = 'VSX45TX ',
Initialize = function(self )
Super.Initialize(self)
end,
GetSettings = function ( self )
return table.copy(DefaultSettings[self.TransportType])
end,
OnConnectFailed = function ( self )
print("Connect Failed")
end,
OnConnected = function ( self )
self:Send("version")
end,
OnBuildCommand = function (self, data )
return data ..'\r'
end,
OnReceiveData = function(self, Event)
print(self.Name .. " Received: " .. Event:GetData())
end,
OnDisconnected = function(self)
self:Close()
end,
} )
Name = VSX45TX.Name
Description = VSX45TX.Description
function New (self,settings)
return VSX45TX:New(settings)
end
A detailed explanation of the code above you can find in the manual under Examples\Transport Tutorial\Basic Transport Classes
bl123
November 10th, 2008, 07:06 AM
ok I guess I have more to learn... I don't mind switching over to a better method, but I'm not sure what you think the problem was with the old method??? Is that functionality no longer expected to work properly?
Switching over to the transport manager, I assume I should remove the VSX45TX lua script from \plugins\serial directory?
thanks for the help, I'll get to work on this.
Ron
November 10th, 2008, 07:48 AM
Yes remove the plugin from the serial directory.
I am not as familiar with the old system as I am with the new, they both run on the same back-end system however the old system uses some lua files that I am not familiar with. So you'll get more help if you use the new system.
bl123
November 10th, 2008, 08:13 AM
Ok that was relatively painless! The only change I had to make was to remove the OnConnected send of "version" (VSX doesn't recognize that command). Also I don't understand the following in the console, although it doesn't seem to harm anything (if you know where that is coming from please let me know so I can clean it up, but I'm sure I'll find it myself eventually)...
Welcome to Promixis Girder 5.0.6 build 540
{ -- #0
[1] = 2,
[2] = "
\
",
[3] = 1000,
[4] = function,
} -- #0
Created DenonAVR Provider
Here is a console dump of a successful send of "?V" and the correct response "VOL44":
SEND 3F 56 0D ?V
RECEIVE 56 4F 4C 34 34VOL44
My VSX45TX Received: VOL44
I really appreciate the help. Nice job on the transport interface, it looks a lot cleaner and I only wish I had asked sooner - spent many hours trying to get that serial plugin to work.
Thanks again Ron!
--Bill
Ron
November 10th, 2008, 08:27 AM
Sorry about that output to the console. That is some debug stuff that managed to creep into the distribution.
Remove:
Line 824 of transport/Core.lua
print("RECEIVE", math.BinaryToHexString(Event:GetData()) .. Event:GetData())
Line: 1435
print("SEND", math.BinaryToHexString(cmd.Command) .. "\t"..cmd.Command)
Not quite sure where the first table print is coming from.
Very glad it's working!! Also you might consider moving to the
"Transaction Based" transport system. Go to the manual I pointed out before it will detail everything you need.
bl123
November 10th, 2008, 08:38 AM
ok, thanks... in playing with it a little more there looks to be an issue with a queue not getting cleared... after sending a certain number of commands I am getting the following error message:
LOG: My VSX45TX : 4 - OnQueueFull: 1
how do I clear out this queue? Once it fills I can't send any commands.
Ron
November 10th, 2008, 08:46 AM
Can you paste your current class?
bl123
November 10th, 2008, 09:02 AM
Can you paste your current class?
Sorry... do you mean the lua code, a dump of the variables, or something else? Still learning...
Ron
November 10th, 2008, 09:03 AM
your lua code.
bl123
November 10th, 2008, 09:10 AM
here's vsx45tx.lua...
5227
Ron
November 10th, 2008, 09:13 AM
unmodified, ok Let me think for a sec ;-)
Ron
November 10th, 2008, 09:19 AM
Were there commands that did not receive a response?
bl123
November 10th, 2008, 09:24 AM
Were there commands that did not receive a response?
Yes several of the commands receive no response. Here is an example of a command with no response... (select function 5)...
SEND 30 35 46 4E 0D 05FN
LOG: My VSX45TX : 4 - No response to last send
Ron
November 10th, 2008, 09:46 AM
It appears you might have been running into a bug.
Change line 800 of transport/Core.lua from
if x < self.Settings.Transport.Post.NoResponseTimeout then
to
if x < self.Settings.Transport.Post.NoResponseTimeout * 0.9 then
Sometimes the event appears to fire a fraction of a second earlier then requested tripping up this check.
Also you should probably increase the queue to a larger size:
local DefaultSettings = prepare(
-- first base settigs.
{
Transport = {
Post = {
NoResponseTimeout = 2000,
},
},
Parser = {
Type = constants.parser.TERMINATED,
Terminator = '\r',
Timeout = 1000,
},
MaxQueuedItems = 10,
},
-- overrides for serial transport
{
Transport = {
Post = {
Baud = 9600,
Flow = 'N',
Parity = 'N',
DataBits = 8,
StopBits = 1,
},
},
}
)
bl123
November 10th, 2008, 10:17 AM
I think that fixed it. I only made the one-line timeout tweak and have not been able to get it to fail. I tried several combinations of commands (some with responses and some without) all work as expected. I'll test it more extensively tonight, and then increase the buffer size and let you know if anything else comes up.
thanks again!
Bill
Ron
November 10th, 2008, 10:19 AM
I would still advise to also increase the queue size. Glad it's working!
bl123
November 13th, 2008, 07:02 AM
Ron,
I've been trying to add my projector to the Transport Manager with no success. I simply copied VSX45TX.lua to SP7200.lua, substituted the word SP7200 for VSX45TX everywhere in SP7200.lua, changed the baud rate and the command/response delimiters (SP7200 uses "()" around each command and response). My sp7200.lua is attached.
5241
After exiting and re-starting Girder, the Transport Manager no longer has my VSX45TX available in the "add" box, and also no SP7200. Based on the Compnent Manager log file it seems to get stuck at the following point:
11/13/08 09:42:15 INFO Transport Manager Reading transport device E:\Program Files\Promixis\Girder5\luascript\transport\devices \sp7200.lua
11/13/08 09:42:16 INFO Component Event: Transport Manager 10045 Add
When I rename SP7200.lua to SP7200.xxx and restart Girder, the Component Manager log looks like this:
11/13/08 09:49:57 INFO Transport Manager Reading transport device E:\Program Files\Promixis\Girder5\luascript\transport\devices \VSX45TX.lua
11/13/08 09:49:57 INFO Component Event: Transport Manager 10045 Add
11/13/08 09:49:57 INFO Component Event: Transport Manager 10045 StartInstance
and of course it creates the VSX45TX device. Any thoughts on what is going on here???
Bill
Ron
November 13th, 2008, 07:49 AM
the modulename and filename have to be EXACTLY the same,... case and all.. It appears you filename is "sp7200.lua" and the module is called "SP7200"
Try fixing that.
bl123
November 13th, 2008, 07:58 AM
the modulename and filename have to be EXACTLY the same,... case and all.. It appears you filename is "sp7200.lua" and the module is called "SP7200"
Try fixing that.
I did notice that just before you replied... but changing the name didn't fix it. In looking at the lua log it does appear to be a naming error somewhere, but I can't seem to find it:
...mixis\Girder5\luascript\transport/devices/SP7200.lua:81: attempt to index global `SP7200' (a nil value)
stack traceback:
...mixis\Girder5\luascript\transport/devices/SP7200.lua:81: in function `init'
...ram Files\Promixis\Girder5\\luascript\compat-5.1.lua:195: in function `require'
...is\Girder5\luascript\components\TransportManage r.lua:343: in function `ReadTransportClassFile'
...is\Girder5\luascript\components\TransportManage r.lua:269: in function `LoadTransportClasses'
...is\Girder5\luascript\components\TransportManage r.lua:302: in function `LoadSerialClasses'
...is\Girder5\luascript\components\TransportManage r.lua:111: in function `LuaStateIsReady'
...iles\Promixis\Girder5\luascript\ComponentManage r.lua:670: in function `StartEnabledComponents'
...iles\Promixis\Girder5\luascript\ComponentManage r.lua:229: in function <...iles\Promixis\Girder5\luascript\ComponentManage r.lua:228>
[C]: ?
...iles\Promixis\Girder5\luascript\ComponentManage r.lua:228: in function <...iles\Promixis\Girder5\luascript\ComponentManage r.lua:227>
Ron
November 13th, 2008, 08:04 AM
on line 43 you define the object as SP and later you refer to it as SP7200.
So there are well make sure you have the same name.
local SP = Super:Subclass ( {
should be
local SP7200 = Super:Subclass ( {
bl123
November 13th, 2008, 08:07 AM
ok that was pretty dumb - sorry. I think I'm all set now.
Powered by vBulletin® Version 4.1.8 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.