PDA

View Full Version : Simple transport plugin - Import from WEB - only 2 devices



MarBe
November 18th, 2015, 11:53 AM
Hi, I found on Simple Transport Plugin only 2 devices, I hope, there should be much more. Can you help me?

Ron
November 18th, 2015, 12:02 PM
This plugin is very new, so not much has been contributed. What are you trying to control?

MarBe
November 18th, 2015, 02:02 PM
I need to control Harman Kardon AVR via RS232, and LG TV via RS232, I have all specification for it. But Im beginner to write my own plugin.

Ron
November 18th, 2015, 02:03 PM
Sure let's work on the TV first. Can you link the specs?

MarBe
November 18th, 2015, 03:56 PM
yes, thats wonderful, thank you!

Ron
November 18th, 2015, 04:11 PM
Ok let's start with power on / off and mute on / off. Please import the attached .tcf, set the correct comport and then use the actions via the "Simple Transport/Send Predefined Action".

MarBe
November 18th, 2015, 05:26 PM
yes, it works, thank you. Is possible to write it via code?

Ron
November 18th, 2015, 06:10 PM
Certainly. You'll need to transport ID, on my machine it's "{29810f4c-f89c-4183-a2a8-5f8d0c042624}" and if you open the predefined commands in the transport edit dialog you'll find the ID for the action. Power On is "{89a2fd0c-aadb-40c6-b815-5fd26a40956b}"



simpleTransport.sendPredefined("{29810f4c-f89c-4183-a2a8-5f8d0c042624}","{89a2fd0c-aadb-40c6-b815-5fd26a40956b}")


or if you want to work without predefined actions



simpleTransport.sendData("{29810f4c-f89c-4183-a2a8-5f8d0c042624}","ka 00 01\n")

MarBe
November 19th, 2015, 04:48 AM
yes, that I can understand. Next step, how can I:
- check acknowledgement after sending command? After command I need to wait to acknowledgement, on correct do nothing, on timeout and error generate message and event?
- generate text events parsed to receive data?
- set variable with status of device?
-is possible to receive data not with fixed lenght or terminator, but with timeout?
thank you very much
Martin

Ron
November 19th, 2015, 08:15 AM
Well that is going beyond the Simple transport :) You'll need a full lua object. All those things are possible.

MarBe
November 19th, 2015, 10:58 AM
OK. And what is possible to make at Data Parser?

Ron
November 19th, 2015, 11:11 AM
This allows you to parse the incoming data and do anything you like with it. However your requirements fall outside of the scope of the simple transport. I don't have time at the moment to write up a full component but if you are so inclined there are a few examples in the Lua directory.

MarBe
November 20th, 2015, 07:56 AM
Hi Ron, I made new tcf with dataparser, and it work perfect.
Can you help me with other one for AVR?
- set variable with status of device?
-is possible to receive data not with fixed lenght or terminator, but with timeout?

I try to find some examples, but no success, if you can send me some other examples for lua script, plugins?
Thank you

Ron
November 20th, 2015, 08:06 AM
Currently ontimeout does not return the data that has arrived. Looking at the AVR protocol I can add a parser for their structure. I'll put something together here today. Which version of Girder 6 are you running? (Linux, RPI, Win32, Win64)?

MarBe
November 20th, 2015, 09:24 AM
Now Im running on WIN10 64, but on the end I will run on Raspberry Linux or WIN IoT, if possible.

Ron
November 20th, 2015, 09:26 AM
Looking even closer it appears the AVR only sends back data with 48 bytes in the information field, that means we can use the fixed parser for receiving data! Which also means we can get away with the simple transport.

I've tried to implement the Mute function, can you give that a try

MarBe
November 20th, 2015, 09:58 AM
Yes, thats right on most response, but some responses have variable lenght.

Ron
November 20th, 2015, 10:13 AM
Can you show me the protocol document you are looking at? The one I found specifically says 48 bytes for all AVR-PC communications.

MarBe
November 20th, 2015, 11:32 AM
e.g. Return Voume Value

Ron
November 20th, 2015, 12:18 PM
Hmm looks different from:

https://github.com/jherland/hifictl/blob/master/HK%20AVR%20RS232%20Protocol.txt

Anyway I've added a PARSER_VARIABLE_LENGTH to the transport classes. It's documented in the manual. The parameters are:

1. Offset = 7
2. Bytes = 1
3. lengthAdjust = 9
4. littleEndian = false

This is not currently exposed in the simple transport plugin so you'd have to read the manual a bit and copy for example the pio/init.lua class. Note that the timeout callback has a new parameter called data which will contain all the data received up to then. Also this has not been tested much, so beware. I don't have time to write a class for you but taking pio-1/init.lua and using the following functions as guides you should get somewhere.



function sendSomething( self, callback )

if not self.connection then
return false
end

if not callback then
callback = function( ) end
end


local tx = self.connection:newTransaction(
function()
-- sent
end,
function( data )
-- data
-- parse data as needed.
callback(data)
end,
function (data)
-- timeout
-- parse data as needed
callback( data )
return TXR.TX_REMOVE
end,
function()
-- cancel cb
if cb then
cb(false)
end
end
)

tx:timeout(200)
tx:data("PCSENDXXXXXXX\n") -- adjust to your needs.
tx:persistent(false)
self.connection:send(tx, true)
end




function connect( self, callback )

if self.connection then
disconnect(self)
end

self.connection = transport.new ( Promixis.Transport.Connection.Type.CON_SERIAL, "COM1", function ( event, reason )
connectionCallback(self, event,reason, callback)
end)

self.connection:parser( Promixis.Transport.IParser.Type.PARSER_VARIABLE_LE NGTH, 7,9,1,false, "\r\n" )
self.connection:connect()

end


The new parser is available in 6.0.13.3
http://www.promixis.com/g6/GirderSetup_x64_6.0.13.3.exe

MarBe
November 21st, 2015, 05:13 AM
Hi, sorry, this information I cannot to use. I cannot to find it at documentation at web on pdf or html version. On best send me link or file to it.
Its very important for me to have succesful comunication on RS232 for devices and function read data from serial port, now with device Harman, I need.
I need timeout operation on receive data, on best on simple trasport plugin.
Thank you very much
Martin

Ron
November 22nd, 2015, 02:22 PM
The information is in the manual included with Girder. I understand it's important that's why I have been trying to help you out, even preparing a new build for you specially. I'll get back to this on Monday.

MarBe
November 23rd, 2015, 03:06 PM
Ok, thank you

Ron
November 23rd, 2015, 03:41 PM
OK I've put together 2 scripts that should get us going. The first part is the driver (avrtest.lua), it for now goes into the lua\examples directory. The second part is a GML you open that via import. Inside that file you'll find a scripting action, open it up and adjust the comport to what you need it to be. Currently it's set to COM7. Hit apply and right click the scripting node and select "run". Have a look at the output of the lua console. Copy and paste it all here.

MarBe
November 23rd, 2015, 04:58 PM
Hi, I made it as you described:
- I cannot to set the com baudrate and other settings, it should be 57600, 8, N parity, 1 stopbit.
- I can run the script only once, on the end of the script I must to reset scripts, it hang up
the result

po lis 23 22:53:31 2015 Connected sending command
po lis 23 22:53:31 2015 DATA SENT 504353454E4402048070C13E414E
po lis 23 22:53:32 2015 TIMEOUT OCCURED WITHOUT DATA
po lis 23 22:53:32 2015 DATA SENT 504353454E4402048070C13E414E
po lis 23 22:53:32 2015 TIMEOUT OCCURED WITHOUT DATA
po lis 23 22:53:32 2015 DATA SENT 504353454E4402048070C13E414E
po lis 23 22:53:32 2015 TIMEOUT OCCURED WITHOUT DATA
po lis 23 22:53:32 2015 DATA SENT 504353454E4402048070C13E414E
po lis 23 22:53:32 2015 TIMEOUT OCCURED WITHOUT DATA
po lis 23 22:53:32 2015 DATA SENT 504353454E4402048070C13E414E
po lis 23 22:53:32 2015 TIMEOUT OCCURED WITHOUT DATA
po lis 23 22:53:32 2015 sendCommand result: false

MarBe
November 23rd, 2015, 05:42 PM
I found, that the script send really data on 9600 baudrate. First printscreen is command Mute on 57600 Bd with my device, and second is with your script, and the analyzer say 9600 Bd.
I tried add some lines, but no success

self.connection:baud(57600)
self.connection:flow( Promixis.Transport.SerialConnection.FlowControl.FL OW_NONE )
self.connection:stopBits( Promixis.Transport.SerialConnection.StopBits.STOP_ ONE )
self.connection:characterSize(8)
self.connection:parity( Promixis.Transport.SerialConnection.Parity.PARITY_ NONE )

Ron
November 23rd, 2015, 07:52 PM
OK not sure what is going on, but it appears the baud rate is indeed wrong. Try the attached .lua file

MarBe
November 24th, 2015, 12:14 PM
Yes, now it works! I get correct ack codes, thank you.
But I must to edit avrtest.lua, at attachment.
The script still hang up on the end, I cannot to run it twice, before second run I must to reset the script engine.
Thanks

út lis 24 18:00:07 2015 shutdown running...
út lis 24 18:00:07 2015 rootStartup running...
út lis 24 18:00:07 2015 startup running...
út lis 24 18:00:16 2015 Connected sending command
út lis 24 18:00:16 2015 TRYING VERSION 0.2
út lis 24 18:00:16 2015 DATA SENT 504353454E4402048070C13E414E
út lis 24 18:00:16 2015 TIMEOUT OCCURED: 41565241434B020301FA
út lis 24 18:00:16 2015 sendCommand result: true 41565241434B020301FA
út lis 24 18:04:27 2015 shutdown running...
út lis 24 18:04:27 2015 rootStartup running...
út lis 24 18:04:27 2015 startup running...
út lis 24 18:04:29 2015 Connected sending command
út lis 24 18:04:29 2015 TRYING VERSION 0.2
út lis 24 18:04:29 2015 DATA SENT 504353454E4402048070C13E414E
út lis 24 18:04:29 2015 TIMEOUT OCCURED: 41565241434B020300FB
út lis 24 18:04:29 2015 sendCommand result: true 41565241434B020300FB
6947694869496950

Ron
November 24th, 2015, 12:54 PM
Great!! The reason you can't run that script twice is because the first instance still has the comport open, and thus the second time you run the script it can't open it again. To fix that either close the port (not recommended really) or create 2 scripting action on the Girder tree. The first opens the com port and the second is responsible for sending the data.


local AVRTest = require('examples.avrtest')

if avrtest then
avrtest:deinit()
avrtest = nil
end

avrtest = AVRTest.new("COM7")

avrtest:connect( function( connected )

if connected then

print("AVR Test / Connected.")

else
print("AVR Test / Disconnected.")
end

end)

and


if not avrtest then
print("AVR Test not yet open.")
return
end

-- This is where the script is actually sending the
-- command, in this case the mute command.
avrtest:sendCommand( "PCSEND" .. math.hextobyte( "02048070c13e414e"), 200, function( status, data)

if status and data then
print("sendCommand result: ", status, math.binarytohex(data))
else
print("sendCommand result: ", status)
end

end )

I've fixed a small mistake in deinit (it was calling a non-existant function).

MarBe
November 24th, 2015, 04:43 PM
yes, I can now open port on first step, then send data on second, but stil only once, running the Send Data script on second time print only TRYING VERSION 0.2.
Will be possible with this script read the response everytime from AVR and parse it with and generate event?

út lis 24 22:29:58 2015 AVR Test / Disconnected.
út lis 24 22:30:03 2015 TRYING VERSION 0.2
út lis 24 22:30:07 2015 TRYING VERSION 0.2
út lis 24 22:32:57 2015 AVR Test / Connected.
út lis 24 22:32:57 2015 DATA SENT 504353454E4402048070C13E414E
út lis 24 22:32:57 2015 TIMEOUT OCCURED: 41565241434B020301FA
út lis 24 22:32:57 2015 sendCommand result: true 41565241434B020301FA
út lis 24 22:33:09 2015 TRYING VERSION 0.2
út lis 24 22:33:26 2015 AVR Test / Disconnected.
út lis 24 22:33:28 2015 AVR Test / Connected.
út lis 24 22:33:31 2015 TRYING VERSION 0.2
út lis 24 22:33:31 2015 DATA SENT 504353454E4402048070C13E414E
út lis 24 22:33:32 2015 TIMEOUT OCCURED: 41565241434B020300FB
út lis 24 22:33:32 2015 sendCommand result: true 41565241434B020300FB
út lis 24 22:33:33 2015 TRYING VERSION 0.2
út lis 24 22:33:38 2015 TRYING VERSION 0.2
út lis 24 22:33:44 2015 TRYING VERSION 0.2
út lis 24 22:33:49 2015 AVR Test / Disconnected.
út lis 24 22:33:51 2015 AVR Test / Connected.
út lis 24 22:33:52 2015 AVR Test / Disconnected.
út lis 24 22:33:54 2015 AVR Test / Connected.
út lis 24 22:33:57 2015 TRYING VERSION 0.2
út lis 24 22:33:57 2015 DATA SENT 504353454E4402048070C13E414E
út lis 24 22:33:57 2015 TIMEOUT OCCURED: 41565241434B020301FA
út lis 24 22:33:57 2015 sendCommand result: true 41565241434B020301FA
út lis 24 22:34:01 2015 TRYING VERSION 0.2

Ron
November 25th, 2015, 08:36 AM
Looks like I was missing return TXR.TX_REMOVE on line 121. I've attached the updated lua file.

You can generate events from here sure. ( gir.triggerEvent )

MarBe
November 25th, 2015, 02:15 PM
Yes, perfect! Now can I write some commands and triggers. Would be possible at near future add this functionality to simple transport plugin? Adding timeout to receive command.
Thank you

MarBe
December 5th, 2015, 02:22 PM
Hi, I installed the new version 6.0.14.1 and the AVR test work not as expected. On one run command sends command to AVR moretimes. Is something changed from previous version?
Othervise I try it now on raspberry wheezy.
Thank you
Martin

so pro 5 20:08:48 2015 TRYING VERSION 0.2
so pro 5 20:08:48 2015 DATA SENT 504353454E4402048070C13E414E
so pro 5 20:08:48 2015 TIMEOUT OCCURED: 41565241434B0202A95341565241434B020407F34156524143 4B02040BEF41565241434B020301FA
so pro 5 20:08:48 2015 sendCommand result: true 41565241434B0202A95341565241434B020407F34156524143 4B02040BEF41565241434B020301FA
so pro 5 20:08:48 2015 TIMEOUT OCCURED WITHOUT DATA
so pro 5 20:08:48 2015 DATA SENT 504353454E4402048070C13E414E
so pro 5 20:08:48 2015 TIMEOUT OCCURED: 41565241434B020300FB
so pro 5 20:08:48 2015 sendCommand result: true 41565241434B020300FB
so pro 5 20:08:49 2015 TIMEOUT OCCURED WITHOUT DATA
so pro 5 20:08:49 2015 DATA SENT 504353454E4402048070C13E414E
so pro 5 20:08:49 2015 TIMEOUT OCCURED: 41565241434B020301FA
so pro 5 20:08:49 2015 sendCommand result: true 41565241434B020301FA
so pro 5 20:08:49 2015 TIMEOUT OCCURED WITHOUT DATA
so pro 5 20:08:49 2015 DATA SENT 504353454E4402048070C13E414E
so pro 5 20:08:49 2015 TIMEOUT OCCURED: 41565241434B020300FB
so pro 5 20:08:49 2015 sendCommand result: true 41565241434B020300FB
so pro 5 20:08:49 2015 TIMEOUT OCCURED WITHOUT DATA
so pro 5 20:08:49 2015 DATA SENT 504353454E4402048070C13E414E
so pro 5 20:08:50 2015 TIMEOUT OCCURED: 41565241434B020301FA
so pro 5 20:08:50 2015 sendCommand result: true 41565241434B020301FA
so pro 5 20:08:50 2015 TIMEOUT OCCURED WITHOUT DATA
so pro 5 20:08:50 2015 sendCommand result: false