'Serial comm example for MedeaWiz DV-68 digital video player using 'Parallax Basic Stamp model BS2 'This program allows use of 4 pushbuttons to select 1 of 4 video files to 'play and turns on 1 of 4 relays corresponding to the video file as long 'as the file is playing. Tested with 5 video files on flash card, 000.mpg '(attract loop) and 001.mpg through 004.mpg 'This program also reports back the file playin time from the DV-68 to 'the Debug screen...You could modify the program to, for example, turn 'the relay(s) on and off at specific times during the file playback '02/07/07 Team Kingsley LLC 'www.teamkingsley.com '{$STAMP BS2} ' {$PBASIC 2.5} '188 on BS2 = 4800 baud rec VAR Byte(18) 'var to hold incomming data from the DV-68 track VAR Byte 'register for current video file relay VAR Nib 'register for current relay output seconds VAR Byte 'to hold seconds count minutes VAR Byte 'to hold minutes count minuteFlag VAR Bit 'see * below index VAR Byte 'iteration register DIRA = %0000 'sets I/O 0,1,2,3 to inputs for buttons DIRC = %1111 'sets I/O 8,9,10,11 to outputs for relays OUTC = %0000 'all ouputs off PAUSE 7000 'allow DV-68 time to boot when powered on Top: IF IN0 = 0 THEN 'using I/O 0 for button 1, tied high w/ 10K R track = 1 'to play video file 001.mpg relay = 8 'I/O 8 for relay ELSEIF IN1 = 0 THEN 'using I/O 1 for button 2, tied high w/ 10K R track = 2 'to play video file 002.mpg relay = 9 'I/O 9 for relay ELSEIF IN2 = 0 THEN 'using I/O 2 for button 3, tied high w/ 10K R track = 3 'to play video file 003.mpg relay = 10 'I/O 10 for relay ELSEIF IN3 = 0 THEN 'using I/O 3 for button 4, tied high w/ 10K R track = 4 'to play video file 004.mpg relay = 11 'I/O 11 for relay ELSE GOTO top 'if button not pressed, go check again ENDIF SEROUT 15, 188, [track] 'play track [x] PAUSE 300 'pause miliseconds to allow file to start before relay on HIGH relay 'turn on (relay) SEROUT 15, 188, [232]'ask DV-68 for status on I/O 14 (returns 18 bytes) SERIN 14, 188, [STR rec\18] 'retrieve data from DV-68 on I/O 15 FOR index = 0 TO 17 DEBUG HEX? rec(index) 'show raw hex data on Debug screen NEXT track = rec(16) - $31 'track read from DV-68 minus offset 'this code only works up to track 9 since we are not checking 'the other bytes of track data DEBUG "Track ", DEC track, CR SEROUT 15, 188, [232]'ask DV-68 for status on I/O 14 (returns 18 bytes) SERIN 14, 188, [STR rec\18] 'retrieve data from DV-68 on I/O 15 FOR index = 0 TO 17 DEBUG HEX? rec(index) 'show raw hex data on Debug screen NEXT track = rec(16) - $31 'track read from DV-68 minus offset 'this code only works up to track 9 since we are not checking 'the other bytes of track data DEBUG "Track ", DEC track, CR SEROUT 15, 188, [232]'ask DV-68 for status on I/O 14 (returns 18 bytes) SERIN 14, 188, [STR rec\18] 'retrieve data from DV-68 on I/O 15 FOR index = 0 TO 17 DEBUG HEX? rec(index) 'show raw hex data on Debug screen NEXT track = rec(16) - $31 'track read from DV-68 minus offset 'this code only works up to track 9 since we are not checking 'the other bytes of track data DEBUG "Track ", DEC track, CR PAUSE 1000 'this pause is to insure the file has started playing 'and we don't read the EOF marker from previous file timeloop: 'searching for the EOF (end of file) Marker 'DV-68 sends time (1st 6) and status (2nd 6 bytes) every second SERIN 14, 188, [STR rec\12] FOR index = 0 TO 11 DEBUG HEX rec(index) 'show raw hex data on Debug screen NEXT 'See * explanation below for the following IF rec(1) = $42 AND rec(3) = $30 AND rec(4) = $30 THEN DEBUG CR ELSEIF rec(1) = $42 THEN seconds = ((rec(3)-$30)*10)+ (rec(4)- $30) ELSEIF rec(1) = $41 AND rec(4) = $31 THEN IF minuteFlag = 0 THEN minutes = ((rec(3)-$30)*10)+ (rec(4)- $30) seconds = 0 minuteFlag = 1 ENDIF ELSEIF rec(1) = $41 THEN'AND NOT rec(4) = $31 THEN minutes = ((rec(3)-$30)*10)+ (rec(4)- $30) seconds = 0 ENDIF DEBUG CR, DEC? minutes, DEC? seconds ' show time on debug screen DEBUG CR, CR 'carriage returns on debug screen 'the 4 bytes below indicate DV-68 is at the end of the video file IF rec(0) = $30 AND rec(1)= $31 AND rec(3) = $30 AND rec(4)= $31 THEN Eof GOTO timeloop 'keep receiving time code unless end of file was found Eof: DEBUG "End of file found" minuteFlag = 0 'reset flag for next file minutes = 0 'reset minutes OUTC = %0000 'all ouputs off 'turn off (relay) PAUSE 2000 'hold time before allowing another button press/ file change GOTO top 'go to top and do it all again END '* 'Decoding the time takes a little extra code due to the fact that the 'DV-68 sends some unexpected bytes just before the EOF (end of file) 'bytes are sent. If you don't care about the time at the end of the 'file, then the code below will work. 'IF rec(1) = $42 THEN ' seconds = ((rec(3)-$30)*10)+ (rec(4)- $30) 'ELSEIF rec(1) = $41 THEN ' minutes = ((rec(3)-$30)*10)+ (rec(4)- $30) ' seconds = 0 'ENDIF 'DEBUG CR, DEC? minutes, DEC? seconds 'Using this code will falsely report the final time at EOF depending on 'the length of the file played. If less than a minute, the seconds are reset 'to zero. If more than a minute, the minutes are reset to 1 minute. 'This is why we have to check some of the other bytes, set flags and direct 'the program flow accordingly to show the correct time at the EOF. 'We have not checked files longer than 50 minutes, so we are unsure at this 'time about DV-68 return codes for Hours. We could speculate that it may be '$30,$40,$20,$30,$31,$FF for the 1st hour. 'As in anytime I write code, there is usually a more efficient code to do the 'job. We are always open to suggestions and other points of view. If you have 'any, or have other code you wish to share for the DV-68, please send it to 'bill@teamkingsley.com and we will post it on the website to help others.