import sys
import serial
from struct import *
import array


if len(sys.argv)<2:
	print "Type Python Stream.py COM1 (Or Other COM Port)"
	exit()
COM=""
COM=sys.argv[1]
print COM
	
	#626401
rs232 = serial.Serial(
    port=COM,
    baudrate=626401,
    parity=serial.PARITY_EVEN,
    stopbits=serial.STOPBITS_ONE
)

file = open('demo.txt', 'r')
music=file.read()
music_list=music.split(',')

print "Playing File"
fileindex=0
rate=5
while 1:
	rs232.readline()
	print "SENDING AT Index",fileindex
	if fileindex==0:
		rate=10
	else:
		rate=10
	for lp in range(1,rate):
		rs232.write(pack('bb', int(music_list[fileindex]),int(music_list[fileindex+1])))
		fileindex=fileindex+2
		if fileindex>len(music_list):
			break
	if fileindex>len(music_list)-1:
		print "Sound Done"
		break
	