Results 1 to 6 of 6

Thread: Transaction Object Question

  1. #1
    Join Date
    May 2004
    Location
    Dallas, TX
    Posts
    1,125

    Default Transaction Object Question

    Ron,

    I have taken the code below from the Globalcache plugin and modified to suit my needs. I am attempting the get a block of code to run in the RequestOutputStatus transaction object, however the returned data is processed by the listenForStateChange method. Am I misunderstanding something?

    Code:
    function listenForStateChange ( self  )
    	
    	if not self.connection then
    		return false
    	end
    	
    	local tx = self.connection:newTransaction( 
    		function()
    		end, 
    		function( data )
    
    			local _, _, length, msgType, content, checksum = string.find(data, '(..)(..)(.-)(..)$')
            	local crc = self:ZeroPad(self:calculateChecksum(msgType..content), 2)
    
                if math.hextodecimal(length) == string.len(string.sub(data, 3, -1)) then
                    if crc == checksum then
                        local handler = self.CommandProcessors[msgType]
                        if handler then
                            --print ('Handling Message',msgType)
                            local status, error = pcall(handler, self, data)
                            if error then
                                print(4, 'HandleResponse(): '..error..', for command '..msgType)
                            end
                        else
                            print(3, 'HandleResponse(): No handler for command '..msgType)
                        end
    
        				self.publisher:publish(msgType, content)
        				return Promixis.Transport.ITransactionCallback.Results.TX_KEEP
        			else
        				return Promixis.Transport.ITransactionCallback.Results.TX_CONTINUE
        			end
        		end
    
    		end,
    		function ()
    		end
    	)
    
    	tx:persistent(true)	
    	self.connection:send(tx, true)
    	
    end
    
    local RequestOutputStatus = function(self)
    
    	if not self.connection then
    		return false
    	end
    	
    	local tx = self.connection:newTransaction( 
    		function()
    		end,
    		function( data )
                print (1, 'ReplyOutputStatus(): data => '..data)
    
    			return Promixis.Transport.ITransactionCallback.Results.TX_REMOVE
    		end,
    		function ()
    		end
    	)
    
    	tx:timeout(2000)
    	tx:data(self:GenerateString("cs00"))
    	tx:persistent(false)
    	self.connection:send(tx, true)
    
    end
    
    local connectionCallback = function(self, event, reason, callback )
    
    
    	if event == Promixis.Transport.IConnectionCallback.Status.CONNECTION_ESTABLISHED then
    	   print ('Connected to Elk!!!')
    	   listenForStateChange(self)
    	   --sendcmd(self, "06as0066")
    	   RequestOutputStatus(self)
    	end
    
    	if event == Promixis.Transport.IConnectionCallback.Status.CONNECTION_CLOSED then
    
    		if self.timer then
    			self.timer:deinit()
    			self.timer = nil;
    		end
    		
    		if not self.closing then		
    			delay.run(5000, function() 
    				self.connection:reconnect() 
    			end)					
    		end
    		
    		if callback then
    			callback(false)
    		end
    		
    	end
    
    	if event == Promixis.Transport.IConnectionCallback.Status.CONNECTION_FAILED then
    		print ('Elk driver failed to connect!')
    		if not self.closing then
    			delay.run(5000, function()
    				self.connection:reconnect()
    			end)
    		end
    	end
    	
    end
    Rick

    Girder 6.0 - Elk M1 Gold - JRMC 11.1 w/ M-Audio Delta 410 - NetRemote - BlueIris DVR
    Girder 6 Plugins - Elk M1/EZ8, Pushover Connector and more on the way.


    Visit My Showcase

  2. #2
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,550

    Default

    Persistent transactions will "eat" the data if they do not return TX_CONTINUE as a flag. Can you verify that the data that is coming into the persistent transaction is handled with TX_CONTINUE?
    Ron
    No support through PM

  3. #3
    Join Date
    May 2004
    Location
    Dallas, TX
    Posts
    1,125

    Default

    Shuffled the return flags a bit and now working as expected. Can you provide descriptions for the return flags?
    Rick

    Girder 6.0 - Elk M1 Gold - JRMC 11.1 w/ M-Audio Delta 410 - NetRemote - BlueIris DVR
    Girder 6 Plugins - Elk M1/EZ8, Pushover Connector and more on the way.


    Visit My Showcase

  4. #4
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,550

    Default

    I believe it's in the manual. Have a look... If you can't find it let me know.
    Ron
    No support through PM

  5. #5
    Join Date
    May 2004
    Location
    Dallas, TX
    Posts
    1,125

    Default

    Will this code snippet work, cause any problems, just flat out wrong? I am calling RequestASCIIDescription () from within the Transaction Object created by RequestASCIIDescription().

    Code:
    RequestASCIIDescription = function (self, device, address)
    	local tx = self.connection:newTransaction(
    		function()
    		end,
    		function( data )
                print (1, 'RequestASCIIDescription(): data => '..data)
                
                address == address + 1
                self:RequestASCIIDescription(device, address)
    
    			return Promixis.Transport.ITransactionCallback.Results.TX_REMOVE
    		end,
    		function ()
    		end
    	)
    
    	tx:timeout(2000)
    	tx:data(self:GenerateString('sd'..device..address..'00'))
    	tx:persistent(false)
    	self.connection:send(tx, true)
    end
    Rick

    Girder 6.0 - Elk M1 Gold - JRMC 11.1 w/ M-Audio Delta 410 - NetRemote - BlueIris DVR
    Girder 6 Plugins - Elk M1/EZ8, Pushover Connector and more on the way.


    Visit My Showcase

  6. #6
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,550

    Default

    I think it should work with one exception. It looks like it will go forever, should there be a check for the maximum address you are requesting?
    Ron
    No support through PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •