debugging nightmare!

This is the place for queries that don't fit in any of the other categories.

debugging nightmare!

Postby youngskywalker » Tue Jan 07, 2014 9:26 pm

Hi guys.
first off i'll introduce myself as i'm new here :)
i'm a 17 year old fire alarm engineer living in manchester, uk.
i do VJing and various electronic/engineering projects in my spare time.
i've been into electronics for as long as i can remember, but have only recently started getting into the programming side of things.

i have a VAMS 0808 a/v matrix switcher which has 8 audio/video inputs, and 8 outputs which can be patched to eachother. i use this to link the sound systems in all the rooms in my house together. so i can listen to room 1 from room 2, etc.

the matrix can be controlled via RS-232 which i am doing. i've written a python program (my first ever program!) which runs on a PI and controls it.
the source code can be found here.

the program works, but is bulky, not programmed very well, and is a bit tedious to use. so i went about writing V1.0...

it should work! but... the switcher does nothing when the script sends the commands.
i assumed i was sending something wrong, but when i connected the rs-232 from the pi into the serial port of my laptop... its sending exactly what it should!
here is a screenshot from my serial monitor:

Image

the top line is from the V0.2 program, which the matrix responds to, and the bottom line is from the V1.0 program, which the matrix does not respond to...

here is the source code for the V1.0 which isn't working.

this is really confusing me, i've checked and changed everything i can think of, but it just won't work!
any ideas?

thanks in advance!
-Luke
Last edited by Mekire on Wed Jan 08, 2014 10:19 am, edited 2 times in total.
Reason: First post lock. Fixed links.
youngskywalker
 
Posts: 3
Joined: Tue Jan 07, 2014 8:41 pm

Re: debugging nightmare!

Postby stranac » Tue Jan 07, 2014 9:40 pm

Getting unknown paste id.
Even if that was not the case, you should be posting your code in code tags, rather than links to a pastebin.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1144
Joined: Thu Feb 07, 2013 3:42 pm

Re: debugging nightmare!

Postby micseydel » Tue Jan 07, 2014 10:01 pm

Both the pastebin links are invalid. Give this a read, especially the part about code tags.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1369
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: debugging nightmare!

Postby youngskywalker » Wed Jan 08, 2014 9:30 am

Sorry about that. Post now ammended, links should now work (my fault for doing the bb code incorrectly)
The code in code tags follows.
First:
Code: Select all
import serial

port = serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=3.0)

#serial strings
#select audio
a = "0ACS\r\n"
#select video
v = "0VCS\r\n"
#select both
av = "0AVS\r\n"

#outs
o1 = "0CO1\r\n"
o2 = "0CO2\r\n"
o3 = "0CO3\r\n"
o4 = "0CO4\r\n"
o5 = "0CO5\r\n"
o6 = "0CO6\r\n"
o7 = "0CO7\r\n"
o8 = "0CO8\r\n"
oa = "0ALL\r\n"

#ins
i1 = "0CI1\r\n"
i2 = "0CI2\r\n"
i3 = "0CI3\r\n"
i4 = "0CI4\r\n"
i5 = "0CI5\r\n"
i6 = "0CI6\r\n"
i7 = "0CI7\r\n"
i8 = "0CI8\r\n"
i0 = "0OFF\r\n"

print "VAMS 0808 ssh interface V0.2 created by luke :)"
print "for a list of commands, type '?'"
while True:
    command = raw_input ("enter command: ")
    if command == "a":
        port.write(a)
        print "audio selected"
    elif command == "v":
        port.write(v)
        print "video selected"
    elif command == "av":
        port.write(av)
        print "audio & video selected"
    elif command == "o":
        while True:
            out = raw_input ("select output channel: ")
            if out == "1":
                port.write(o1)
                print "output 1 selected"
                break
            if out == "2":
                port.write(o2)
                print "output 2 selected"
                break
            if out == "3":
                port.write(o3)
                print "output 3 selected"
                break
            if out == "4":
                port.write(o4)
                print "output 4 selected"
                break
            if out == "5":
                port.write(o5)
                print "output 5 selected"
                break
            if out == "6":
                port.write(o6)
                print "output 6 selected"
                break
            if out == "7":
                port.write(o7)
                print "output 7 selected"
                break
            if out == "8":
                port.write(o8)
                print "output 8 selected"
                break
            if out == "a":
                port.write(oa)
                print "all outputs selected"
                break
            else:
                print "you've entered an invalid command."
                print "please select an output channel between 1-8 or a for all"
    elif command == "i":
        while True:
            inp = raw_input ("select input channel: ")
            if inp == "1":
                port.write(i1)
                print "input 1 selected"
                break
            if inp == "2":
                port.write(i2)
                print "input 2 selected"
                break
            if inp == "3":
                port.write(i3)
                print "input 3 selected"
                break
            if inp == "4":
                port.write(i4)
                print "input 4 selected"
                break
            if inp == "5":
                port.write(i5)
                print "input 5 selected"
                break
            if inp == "6":
                port.write(i6)
                print "input 6 selected"
                break
            if inp == "7":
                port.write(i7)
                print "input 7 selected"
                break
            if inp == "8":
                port.write(i8)
                print "input 8 selected"
                break
            if out == "0":
                port.write(i0)
                print "output switched off"
                break
            else:
                print "you've entered an invalid command."
                print "please select an input channel between 1-8 or 0 for off"
    elif command == "?":
        print "here are a list of commands:"
        print "a = select audio"
        print "v = select video"
        print "av = select audio and video"
        print "o = output"
        print "i = input"
    else:
        print "you've entered an invalid command."
        print "for a list of usable commands, type '?'"

Second:
Code: Select all
import serial

port = serial.Serial("/dev/ttyAMA0", baudrate=9600, timeout=3.0)

#serial strings
#select audio
a = "0ACS\r\n"
#select video
v = "0VCS\r\n"
#select both
av = "0AVS\r\n"


# define output variable
def outputSelect(command):
    command = "0CO" + command + "\r\n"
    port.write(command)
#    print command
   
# define input variable
def inputSelect(command):
    command = "0CI" + command + "\r\n"
    port.write(command)
#    print command

print "VAMS 0808 ssh interface V1.0 created by luke and matt :)"
print "for a list of commands, type '?'"
while True:
    command = raw_input ("select output channel: ")
    if command == "a":
        port.write(a)
        print "audio selected"
    elif command == "v":
        port.write(v)
        print "video selected"
    elif command == "av":
        port.write(av)
        print "audio & video selected"
#select output channel
    elif int(command) >0 and int(command) <9:
        outputSelect(command)
#        print "output win"
#select input channel
        inp = raw_input ("now select input channel: ")
        if int(inp) >0 and int(inp) <9:
            inputSelect(inp)
#            print "input win"
    elif command == "?":
        print "here are a list of commands:"
        print "a = select audio"
        print "v = select video"
        print "av = select audio and video"
        print "o = output"
        print "i = input"
    else:
        print "you've entered an invalid command."
        print "for a list of commands, type '?'"


Thanks in advance..!
Last edited by Yoriz on Wed Jan 08, 2014 1:09 pm, edited 2 times in total.
Reason: Links fixed in OP. Quote removed, Code added.
youngskywalker
 
Posts: 3
Joined: Tue Jan 07, 2014 8:41 pm

Re: debugging nightmare!

Postby Kebap » Wed Jan 08, 2014 10:17 am

Hey Luke, welcome to the forums, to python and programming in general. :mrgreen:

edit: Nevermind, in your second post, the links are working. I guess you weren't able to edit your first post anymore.

edit: Nevermind, your code is now in your second post

Now, I can't run and test your code, as I don't have your hardware here. From looking at the code, it seems quite similar. I wonder why it won't run. I see the only difference is how you handle the user interaction covering input and output selection.

Earlier you had all strings prepared like i1 = "0CI1\r\n", and used a long if/else to select the correct string. Now you just check if the user input is an integer in the expected range, then call a function with the command number, and create the string dynamically like command = "0CI" + command + "\r\n"

While I would recommend against naming both these different things (command number and resulting command string) with the same variable name for clarity's sake, it should not affect the code working. I have now answer for you, yet. Maybe somebody else can continue from my findings though.
Last edited by Yoriz on Wed Jan 08, 2014 1:12 pm, edited 2 times in total.
Reason: Removed code which is now in o/p second post
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 396
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: debugging nightmare!

Postby Mekire » Wed Jan 08, 2014 10:22 am

Fixed the links in the OP.

-Mek
Last edited by Yoriz on Wed Jan 08, 2014 1:13 pm, edited 1 time in total.
Reason: Removed code which is now in o/p second post
User avatar
Mekire
 
Posts: 988
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: debugging nightmare!

Postby Kebap » Wed Jan 08, 2014 10:31 am

OK I think I found something:

Code: Select all
>>> number = int(2)
>>> command = "0CI" + number + "\r\n"
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects


Try changing your line in inputSelect and outputSelect to the following:

Code: Select all
command = "0CI" + str(command) + "\r\n"


There may be a problem trying to attach strings and numbers like you do. There are other solutions, too, but this should be easy enough to see and understand.
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 396
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: debugging nightmare!

Postby youngskywalker » Sun Jan 12, 2014 1:43 pm

thanks for the warm welcome :)

kebap, i've done what you suggest but it still doesn't work. :(

the bit that's really confusing is the fact that the pi is outputting the correct data through the serial port by the looks of it! :/

i'm going to try playing with the baud rate now, as that's the only thing left i can think of and see what happens.,
youngskywalker
 
Posts: 3
Joined: Tue Jan 07, 2014 8:41 pm


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 4 guests

cron