Page 1 of 1

Harman Kardon

Posted: Fri Jun 05, 2015 6:26 am
by kgschlosser
So I have a very old school AVR745 (one of the best pieces of modern AV electronics made). unfortunately the older it gets the less is available. as there is a plugin for eventghost it is pretty much a for not, doesn't run properly and isn't complete.

what i need is... I would like to know if newer harmans have serial control at all??? and if so does anyone have knowledge if their RS232 protocol has changed??

i do have the protocol information from the older ones 5+ years ago could be older, don't remember. I used to work for harman and I have cut apart the existing script and made it work properly, no more errors and messages about unreadable lines and stopped it from posting all the time and added globals for alot of functions and it gives events for mute on .... and OFF as well as power on and OFF it is built to suit my application tho, i wanted to know if there is a call for me to finish it for ease of use?

what needs to be done....

put in an actual event list.
add settings menu options for the the TCP event sender intergration. (higher end models have Abus and multiroom. pretty useless now because you can'y buy the Abus
components for it any more.
I have the Arduino scripts for ps3 BT remote to Eventghost to the HK to actually get the multiroom functionality back.
as well as a dual eventghost for server and HTPC OSD revival (HDMI is old on mine 1.2 i think 1080i) with media portal HDMI direct from pc to TV
finish adding events for everything
make a 100% OSD duplicate of the original for EG

I have still to resolve the 50ms timing thing tho. HK specifications are 50ms between commands. i am at about 150 and i don't get any responses at that speed. have to slow it down to 500ms for the volume bar to operate smooth. I think it's because both portions of the script can't be run in that close a proximity of each other don't know tho. haven't wanted to port the script over to an Arduino tho (better control over the timings than on a PC. and best I can get from the PS3 to Arduino shoot the command over wired network to EG is 65ms

if i cut the script for the Arduino down to just vol up and down i have gotten about 20ms, but the code on the Arduino is quite large because of what i needed to do (stupid proof the remote for the wife).

if anyone is interested let me know.

and let me have a general idea of what features are important and as well as ones i may have forgotten about.

i also made that -80 to +10 volume response to a normal 0 - 100 with a global for both

Re: Harman Kardon

Posted: Tue Jun 09, 2015 12:54 am
by kgschlosser
update, i have been messin around a little more with that old HK plugin, there isn't much of the original left i don't think. I retooled the receiving end almost in a whole thank god to only seeing responses and not errors and incomplete lines. i was still getting them every now and again. but it appears that they are almost gone now. I haven't decided if i want to do a cross reference table for nice Names instead of the Partial ones the actual receiver one generates.

recoded the the power and mute portion, also added an "init" feature so that if the HK is on and the computer reboots or EG shuts down for some reason, it will automatically sync with the state of the AVR. Had to put some thought into it. receiver spits out blank lines if the state is off, that would have been to easy. so the mute on the display blinks. well it does over the serial as well. and having EG fire up if the thing is muted i didn't want it to think the power was off.

you should be able to tell i am very new to programming. 2 months to be exact :/
this is fun tho.

if anyone could tell me how and give examples of how to have the script to auto generate the macros and how to easily access another class in the plugin. would be a help. need code examples. that's how i learn by seeing examples.

I don't have all of the vocabulary well not even a small portion of it.

i need to be able to access other classes inside the script sending data back and forth between each one of them

eg:

transmitting class needs to be able to send to the volume class and the volume to send to the OSD class
receiving class needs to be able to send to the volume as well and the volume to the OSD and they also need to be able to access the self.TriggerEvent for the Plugin

that last piece is the one i am really hung up on and how exactly variables are shared without making them global. i just started to touch base on it and haven't spent a lot of time researching.

I still haven't figgured out why it takes so long for the HK to respond. data sheet says 50ms between commands, i am at over 400 and it's still dropping gonna have to get a serial port monitor on it and see what's going on, don't know if the checksum portion is 100% i tried using the CRC16 on the receiving end and i'll be damned if i can get that working. I know the thing is right but it only gets 1 of the 2 bytes correct..

if someone has an idea as to what i should be using. i will give a code example. i don't have it saved but i'll give a general idea, so don't take the puncuation and thing literally. I could be making a mistake...



ok so this is the section of the script that is the serial port read it is going to look familiar to those who have written these plugins, i have found the identical thing in more than one script already.

Code: Select all


         else:
                    #self.PrintError("error")
                    raise

            rc = MsgWaitForMultipleObjects(
                (hEvent, stopEvent),
                0, 
                1000, 
                QS_ALLINPUT
            )
            if rc == WAIT_OBJECT_0:
                n = GetOverlappedResult(hComPort, overlapped, 1)
                if n:
   
                    self.HandleChar(str(buf))
                #else:
                #    print "WAIT_OBJECT_0", n, str(buf[:n])
                waitingOnRead = False
that is what it was.

now this is what i did.

Code: Select all

while continueLoop:
            if not waitingOnRead:
                ResetEvent(hEvent)
                hr, _ = ReadFile(hComPort, buf, overlapped)
                if hr == 997:
                    waitingOnRead = True
                elif hr == 0:
                    pass
                else:
                    raise

            rc = MsgWaitForMultipleObjects((hEvent, stopEvent), 0, 1000, QS_ALLINPUT)
            if rc == WAIT_OBJECT_0:
                n = GetOverlappedResult(hComPort, overlapped, 1)
                if n:
                    if hkadv < 0:
                        hkbuffer=""
                        top = ""
                        bottom = ""
                    hkadv = hkadv + 1
                    hkbuffer += str(buf)
                    if 'MPS' != hkbuffer and hkadv == 2:
                        hkadv = -1
                        if hkadv > 7 and hkadv < 59:
                            if ord(hkbuffer[8]) != 240 or ord(hkbuffer[24]) != 241:
                                hkadv = -1
                                continue
                            if hkadv %2 == 0:
                                checksumEven ^= ord(hkBuffer[hkadv])
                            else: 
                                checksumOdd ^= ord(hkBuffer[hkadv])
                            if hkadv == 57 or hkadv == 58:
                            if ord(hkbuffer[57]) != checksumEven or ord(hkbuffer[58]) != checksumOdd:
                                hkadv = -1
                                continue
                            if (hkadv > 8 and hkadv < 23) or (hkadv > 24 and hkadv < 39):
                                if ord(hkbuffer[hkadv]) < 128:
                                    if hkadv > 8 and hkadv < 23:
                                        top += hkbuffer[hkadv]
                                    if hkadv > 24 and hkadv < 39 :
                                        bottom += hkbuffer[hkadv]
                                else:
                                    hkadv = -1
                                    continue
                                if hkadv == 38:
                                    top = top.strip()
                                    bottom = bottom.strip()
                                    hkadv = -1
                                    if self.hkinit:
                                        self.HarmanInit(top, bottom)
                                    if not self.hkinit:
                                        self.HandleChar(top, bottom)
                #else:
                #    print "WAIT_OBJECT_0", n, str(buf[:n])
                waitingOnRead = False
            elif rc == WAIT_OBJECT_0+1:
                continueLoop = False
            elif rc == WAIT_TIMEOUT:
                pass
            else:
                pass
now i know there is probably typos and what not. i just now rekeyed it from memory, but is was that idea, and it would only generate the even checksum properly.
not sure why, but i also seperated the buffer manually and then used the same thing to make sure it was grabbing the right bytes, and i still couldn't get it right


it's the xor sum of the even and xor sum of the odd 2 byte CRC16

now i saw a notation that looked odd in the documentation and wasn't sure what it meant

Check sum is calculated by splitting the data into even bytes and odd bytes and calculating
two checksum bytes using them. Check sum high byte is calculated by Xor sum of even
bytes while check sum low byte is calculated by Xor sum of odd bytes.
Data[0]^Data[2]^..Data[2n]= Check Sum[0] high byte
Data[1]^Data[3]^..Data[2n-1]= Check Sum[1] low byte

the data[2n] part don't know what the n is but that is all the information i have on the checksum calculation

thanks again

Re: Harman Kardon

Posted: Tue Jun 09, 2015 2:17 am
by jonib
You should really put your code in "Code" tags, as many will just ignore unformatted code as it's much harder to read and understand.

jonib

Re: Harman Kardon

Posted: Tue Jun 09, 2015 2:27 am
by kgschlosser
jonib wrote:You should really put your code in "Code" tags, as many will just ignore unformatted code as it's much harder to read and understand.

jonib

yeah i saw that it didn't format the code just now, don't know if i can fix it. i'll see what i can do.never posted code into a forum before

Re: Harman Kardon

Posted: Sun Jun 14, 2015 2:14 am
by kgschlosser
Well i don't believe anyone is following this, but it is a good place to post and get some feedback i guess.

I have sorted i think 100% of the receive problems.
added a separate volume event
added separate mute event
and as an added bonus. :/ was a real pain actually the HK serial port is EXACTLY what the display is on the AVR
so the Mute blinks. yeah. only other state that shows nothing is power off.
that became interesting. so there si a seperate event for the mute blinking on and off (good for OSD)
added the option to have the information sent through network to another EG
added OSD for everything except the harman's native OSD i am working on that one.

having alot of problems getting the config menu to work properly well at all for that matter. i can get it to display and you can select make all the adjustments. but then it will fail when it goes to load the config. saying there are exactly 12 configurable items or what not and my config is 12 items and there are 13 items including self in the __start__ . now here is where i am lost tho

if i remove an item it will skip a number and then state i don't have enough. idk

the TCP stuff work great. for those of you that may want to use this antique as a whole home solution again.

i got the serial response down to something like 400 milliseconds off of the 1+ second response times that it was before. and the actual serial read loop for a line is down to 12 milliseconds with no errors. i think the 400 is as best as it is going to get as far as the response to a command i reread the HK docs and i misunderstood the 50 ms thing. if there is a delay in the command sequence by 50ms the harman will split it in 2 thinking it is 2 separate commands. funny tho the native OSD and display are not 400 ms. sometimes it will respond a lot faster.

Re: Harman Kardon

Posted: Sat Jun 20, 2015 9:18 pm
by kgschlosser
OK this is where I am at, I have spent some time making this plugin operate properly without throwing python errors.

It does work great. I have added all kinds of features to it that I needed and those work great also.

I was going to make it easily user configurable, but I am most likely not going to. for 1 I have not had any responses about it except one person mentioning that i didn't use code/code.for 2 I have asked for some coding assistance and I have not received any. I am stuck on a couple of things that an answer or a solution would be a lot simpler then having to try and figure it out. 3 i read somewhere on the forum that the use of globals by a plugin is not liked, but that is the solution i have come up with and thus brings us back to #2. I do have a lot of things using Event Ghost but I have just about completed the code for those things. I have no need to have them user configurable. but I was going to do that for learning and sharing. but the lack of an answer kinda made up my mind on that one. I have a lot of other things that need my attention and I don't want to consume it with trying to make something work that i don't need.

"time spent > need"

I do appoligize if there is any one that was interested but you should have said something. I do enjoy the doing this stuff and learning but in some cases a teacher is needed. as i have mentioned in earlier posts I am new to programming and i do learn very well by reading and examples. but sometimes there are things you just can't find information on or would be easier learned if someone else explained it. and that is where I am at right now.

if there is someone that shares the same passion for home automation/electronics/home theatre what I have made can be altered to fit their environment. and I may be willing to do so. but I do not think posting an incomplete script by definition would be proper. so send me a message through the forum and if i see it I will help.

thanks again

Re: Harman Kardon

Posted: Sun Jun 21, 2015 5:15 am
by krambriw
I feel sorry you feel like that but there are normally help to get. You have had around 150 views on your topic so there has been at laest some users looking into it.

I think the main reason for low interest are mainly 2

1) "I have a very old school AVR745"
Basically this is the major filter. You are alone having this product, therefore not much response and most important, anybody helping out cannot verify & test any improvements by themselves

2) You are not publishing your complete script or plugin, just some selected parts of your code, makes it impossible to suggest overall recommendations

If it now works for you that's fine. I would do the same as you, consider this a private thing and not really a huge public need. Otherwise you would have received a lot of feedbacks (compare the plugin interest for a more modern equipment like Sonos)

Best regards
Walter

Re: Harman Kardon

Posted: Sun Jun 28, 2015 5:00 am
by kgschlosser
I know i am only posting partial code. and I am not sure even if HK still has RS232 ports on their new equipment. I do know that they have lost traction in the home audio. ya don't seem them in stores that much. I am posting bits of code because it is not 100% functional and I don't want to get hammered with questions as to how to make it work properly. there is no setup menu for it. and no command list (as far as ability to easily choose what command to send) it work for me because the hex codes are more or less hard coded. I can't seem to get the checksum portion to function properly. don't know as to why or if it is normal for this thing but there is data corruption across the serial. not that often but it does happen usually when hammering it with commands like volume for instance. i would imagine it would function better if i could get the checksum to work properly. but for the moment i have it logging every display sequence to a text file and I have been building a list of correct communication to have it reference so it doesn't throw jibberish into EG.

that is what the original script used to do, that and all kinds of python errors. i think i have just about 100% of that gone. i get the missed letters but this thing sends exactly what is displayed on the screen in ascii. so i can read the lines but with no checksum to verify making a cross reference list was the next solution for me. as i am sure it slows down the whole process. kinda stinks. i have gotten the response down to 12ms. but there are so many errors or misalignment I think caused by EOT and other bytes that are transmitted that is not handled 100% properly. and I am not sure if the piece of equipment is bidirectional (just thought of that) i do know when i am sending nothing comes in. but not sure if that is the script or the equipment, I'll have to get a serial monitor on it.

so where i am kinda stuck. the checksum,
building a setup menu,
i would love to build in the ability to send network events from directly in my script instead of calling another plugin. that alone ass alot of time.
same goes for OSD functions. I am learning I guess. but these things work right now but there is latency problems. like OSD volume indicator jumps instead of rolling up nice and smooth or the stations.

is there any way to have the OSD properly do multiline and have it centered in the screen. the built in OSD left justifies in the middle of the screen. can't count characters because each character occupies a different amount of space on the screen. so unless i make my own font with equally sized spacing for each letter (not gonna do that) everything is out of alignment.

i bit off alot for my first coding project. PS3 remote, arduino IR Receiver and IR transmitter, OSD for the HK, serial control of the HK, network control of the TV, OSD menu system for heating controls, media portal network control, Z-Wave Lighting Control, multiroom audio, blind control, turn on and off the fireplaces, monitor and control hot tub. I even set the thing up so that if i leave the house it will shut everything down and when i am coming home turn things on for me based on time of day and if my wife is home. all automatic using the gps off the phone to tell the system how close to home i am. PIR sensors, temp sensors, flood sensors, structure wired the house, 3 servers, 5 HTPC's diskless and fanless, central PVR, Central multi tuner cable TV, 5000+ movies stored on a server no discs, 14000+ video games. everything able to to accessed and used for any device connected to my network VPN or local. anyone know of a supplier for WS2801 or similiar addressable RGB led strings or strips. need 300 meters or so, and i am leery of buying direct from china and i think that 35-40 for a 3-5 meter run is just insanely overpriced.

and I have the arduino setup so it stupid proof the remote for my wife. so no matter what device she is on it will always operate the correct button based on what is turned on. and not the device selected on the remote.

don't know how but it all actually works. only have a couple more bits to get coded up properly for my media room. and i am at kind of a hang up. and i bought this POS controller for the lighting system that causes me alot of grief. so i can see i am going to have to get a zwave dongle and code something for that also. because just about everything made is crap that i have seen.

java, c, c++ and python and in 4 months time. so sorry if i came off wrong. my brain feels like squash. lol never programmed a thing before 4 months ago.little mIRC scripting way back i think it may have been the late 80's or early 90's.

and that is another reason i don't post whole code. I would think that people would be horribly confused as to what is going on because everything talks to one another. i ended up writing a whole means of communication between these things.

and because i am also new i am sure i have a large mess for the code that could be improved upon. and i don't want to have any focus of what my problem is being diverted to other things (that is kinda what usually happens). so if i only posted the section that is relevant to where my problem is i thought that would be enough.

thanks for reading this rant i guess if ya did.

Thanks again, and i do apologize if i came off wrong. frustration got the best of me i think. I just wanted to have someone use this disaster i made except for myself.