Home  |  Contents 
Microcontroller and PC projects
  Forum Index : Microcontroller and PC projects         Section
Subject Topic: Newie got a few questions Post ReplyPost New Topic
<< Prev Page of 33 Next >>
Author
Message << Prev Topic | Next Topic >>
CaptainBoing
Guru
Guru
Avatar

Joined: 07 September 2016
Location: United Kingdom
Online Status: Offline
Posts: 363
Posted: 05 December 2017 at 5:05am | IP Logged Quote CaptainBoing

What are you feeding the output sound into? does that work with another sound source?

What are the filenames you used? It wants names following a specific format - start with "T" then have two digits following.

so "T00FRED.wav" is OK, but "FRED.wav" is not

the xx is the associated pin number.

Also if the files are .ogg, you need at least 200mS low on the pin (not 125ms)

Edited by CaptainBoing on 05 December 2017 at 5:12am



Back to Top View CaptainBoing's Profile Search for other posts by CaptainBoing
 
lew247
Guru
Guru
Avatar

Joined: 23 December 2015
Location: United Kingdom
Online Status: Offline
Posts: 790
Posted: 05 December 2017 at 5:23am | IP Logged Quote lew247

T01.wav, T02.wav and so on
I even downloaded their example sound file to double check and use that to test


Edited by lew247 on 05 December 2017 at 5:24am
Back to Top View lew247's Profile Search for other posts by lew247
 
lew247
Guru
Guru
Avatar

Joined: 23 December 2015
Location: United Kingdom
Online Status: Offline
Posts: 790
Posted: 05 December 2017 at 7:38am | IP Logged Quote lew247

I've ordered a new module, seems like the one I have is faulty

ON a different subject
[240] FieldArray$(Count) = ""
Error: Index out of bounds
>


Would a watchdog timer restart that?
Or is there any way to automatically run the program again if it stops like that?
Back to Top View lew247's Profile Search for other posts by lew247
 
Azure
Regular Member
Regular Member
Avatar

Joined: 09 November 2017
Location: Australia
Online Status: Offline
Posts: 73
Posted: 05 December 2017 at 10:11am | IP Logged Quote Azure

You cannot run the module if the USB port is connected to a computer. The unit must be powered from a power module only or via the power pins to be in GPIO mode (run using the play inputs).
Back to Top View Azure's Profile Search for other posts by Azure
 
Azure
Regular Member
Regular Member
Avatar

Joined: 09 November 2017
Location: Australia
Online Status: Offline
Posts: 73
Posted: 05 December 2017 at 10:34am | IP Logged Quote Azure

[240] FieldArray$(Count) = ""
Error: Index out of bounds

Index out of bounds in that case usually means your count variable used to index into your array is larger than the size of the array.
If you are accessing it in a for next loop you need to adjust the "to" count.
Otherwise you might need to do bounds checking before referencing the array if you do not know (within the code segment you are writing) your source of the index will always be within range.
Create a constant which is used to define the size of the array.
Before you access the array make sure the index (count) is less than the size constant.
Back to Top View Azure's Profile Search for other posts by Azure
 
panky
Guru
Guru
Avatar

Joined: 02 October 2012
Location: Australia
Online Status: Offline
Posts: 411
Posted: 05 December 2017 at 1:45pm | IP Logged Quote panky

@lew247

Quote:
ON a different subject
[240] FieldArray$(Count) = ""
Error: Index out of bounds
>


Would a watchdog timer restart that?
Or is there any way to automatically run the program again if it stops like that?


Lew,

Re WATCHDOG timer, it will just restart MMBasic at the timeout, regardless of what it is doing at the time so, no, WATCHDOG won't get you around your problem.

With a combination of ON ERROR SKIP, and RUN, you could restart your program BUT YOU WOULDN'T WANT TO as the error message is telling you you have done something wrong programatically and the data you expected to go into the array did not because the pointer, COUNT, is pointing beyond the size of your array.

Azure, above, has pointed out this problem and possible ways to detect this condition.

panky.




__________________
DonTSM1,Duinomite,CGCMM1,CGCMM2,2xDimitech,3xWWuMites,MicksMuP,Grogster1A,4xPeterMuM+,Zonker DIP-600,3xCGuKits,CGuBoard2,SnadPic100,SCBP64 & Exp100,PMMZ144,PMMZ100 .. and loving it![:D
Back to Top View panky's Profile Search for other posts by panky
 
lew247
Guru
Guru
Avatar

Joined: 23 December 2015
Location: United Kingdom
Online Status: Offline
Posts: 790
Posted: 05 December 2017 at 6:23pm | IP Logged Quote lew247

Azure wrote:
[240] FieldArray$(Count) = ""
Error: Index out of bounds

Index out of bounds in that case usually means your count variable used to index into your array is larger than the size of the array.
If you are accessing it in a for next loop you need to adjust the "to" count.
Otherwise you might need to do bounds checking before referencing the array if you do not know (within the code segment you are writing) your source of the index will always be within range.
Create a constant which is used to define the size of the array.
Before you access the array make sure the index (count) is less than the size constant.

It's to count the number of fields coming into the com port an separate them.
It "normally" works perfectly, it fails when I touch the weather forecast buttons too fast and probably is in the middle of running the function when I touch the next days button so it then fails because it's expecting FieldArray$(Count) = "" to be 0 when it might have several fields.
Here's the code (including comments) kindly provided by MicroBlocks
Function GetFieldArray( Record$, Delimiter$, KeepQuotes )  
    LOCAL Index, Char, InQuote, Count 

    InQuote = 0 
    Count = 0 

    ' If no delimiter is provided use a comma 
    IF Delimiter$ = "" then Delimiter$ = "," 

    ' Loop through all the characters 
    FOR Index = 1 to LEN(Record$) 
       Char = ASC(MID$(Record$, Index, 1)) 

       IF Char = 34 THEN 
         ' Flip InQuote between 0 and 1. 
         ' A 1 will signal that the next characters 
         ' are within quotes and delimiters should be ignored 
         InQuote = NOT InQuote 
       ENDIF 

       ' Only check for delimiters when not within two quotes 
       IF NOT InQuote AND INSTR(Delimiter$, chr$(char)) >= 1  THEN 
          Count = Count + 1 
       ELSE 

         ' Only collect characters for the requested field. 
            'Add the character and only add quotes when KeepQuotes is 1 
            IF Char <> 34 OR KeepQuotes THEN 
            GetFieldArray$(Count) = GetFieldArray$(Count) + chr$(char) 
            ENDIF 
         ENDIF 
      ENDIF 
    NEXT 

    GetFieldArray = Count + 1 
End Function
Back to Top View lew247's Profile Search for other posts by lew247
 
Azure
Regular Member
Regular Member
Avatar

Joined: 09 November 2017
Location: Australia
Online Status: Offline
Posts: 73
Posted: 05 December 2017 at 11:30pm | IP Logged Quote Azure

Lewis the error is not coming from that routine.

It is coming from the line mentioned in the error handler [line 240 in your code]

I suspect whatever you are doing at that point has count outside the array size.
Back to Top View Azure's Profile Search for other posts by Azure
 
lew247
Guru
Guru
Avatar

Joined: 23 December 2015
Location: United Kingdom
Online Status: Offline
Posts: 790
Posted: 06 December 2017 at 2:03am | IP Logged Quote lew247

Line 240 is in that code, it's this section the last ENDIF
Else
If Char <> 34 Or KeepQuotes Then
FieldArray$(Count) = FieldArray$(Count) + Chr$(char)
EndIf
EndIf 'Line 240
Back to Top View lew247's Profile Search for other posts by lew247
 
Azure
Regular Member
Regular Member
Avatar

Joined: 09 November 2017
Location: Australia
Online Status: Offline
Posts: 73
Posted: 06 December 2017 at 7:42am | IP Logged Quote Azure

Add a conditional print statement within that if statement to check what is going on when it is out of bounds
If Count >= MAXFIELDS-1 Then
  Print "Count: "; Counr
  Print "Record$: :; Record$
  Print "Index: "; Index
EndIf


MAXFIELDS is whatever size you declare your FieldArray$(MAXFIELDS) to be, minus 1 since it starts at 0.
Back to Top View Azure's Profile Search for other posts by Azure
 
Azure
Regular Member
Regular Member
Avatar

Joined: 09 November 2017
Location: Australia
Online Status: Offline
Posts: 73
Posted: 06 December 2017 at 7:44am | IP Logged Quote Azure

Azure wrote:
You cannot run the module if the USB port is connected to a computer. The unit must be powered from a power module only or via the power pins to be in GPIO mode (run using the play inputs).


You have not indicated if you were running the sound module from the PC USB connection, as indicated above it won't work using GPIO pins when it is plugged into anything other than a power source.
Back to Top View Azure's Profile Search for other posts by Azure
 
panky
Guru
Guru
Avatar

Joined: 02 October 2012
Location: Australia
Online Status: Offline
Posts: 411
Posted: 06 December 2017 at 3:58pm | IP Logged Quote panky

Lewis,

Re your code example a couple of posts ago, there are a few problems there - firstly you have the function name as GetFieldArray but you also use GetFieldArray$() as the array inside the function - this is a no no and throws an error.

Also the count variable ended up outside the array bounds as you found.

I have taken the liberty of massageing your code a bit to get it working and included a bit of test code to demonstrate.


' Test program to demonstrate record splitting into a
' multi field array
  option explicit
  option base 1
  dim record$ = "Field 1,"
  record$ = record$+chr$(34)+"Field 2, in quotes and embedded delimiter"+chr$(34)+","
  record$ = record$+"Field 3"
  dim x
  dim KeepQuotes = 0
  dim Delimiter$ = ","
  dim GetFieldArray$(3)
  dim fields = 0
  ' call GFieldArray function which returns number of fields
  ' - it also fills the array GetFieldArray$()
  ' - we have KeepQotes = 0 here so no quotes in field 2
  fields = GFieldArray(Record$,Delimiter$,KeepQuotes)
  print "Field count = ",fields
  print
  Print "Pass 1 with no quotes passed to output"
  for x = 1 to fields
    print "Field ",x," = ",GetFieldArray$(x)
  next x
  print
  ' empty out array
  for x = 1 to fields
    GetFieldArray$(x) = ""
  next x
  
  ' do it again with KeepQuotes set to 1
    print "Pass 2 with quotes to be included in output"
  KeepQuotes = 1
  fields = GFieldArray(Record$,Delimiter$,KeepQuotes)
  for x = 1 to fields
    print "Field ",x," = ",GetFieldArray$(x)
  next x
end

' Subroutines
Function GFieldArray(Record$, Delimiter$, KeepQuotes)
  LOCAL Index, Char, InQuote, FieldCount
  InQuote = 0
  FieldCount = 1
  ' If no delimiter is provided use a comma
  IF Delimiter$ = "" then Delimiter$ = ","
  ' Loop through all the characters in Record$
  FOR Index = 1 to LEN(Record$)
    Char = asc(MID$(Record$, Index, 1))
    IF Char = 34 THEN 'check for quote character
      ' Flip InQuote between 0 and 1.
      if KeepQuotes = 1 then 'only add quotes when KeepQuotes is 1
        GetFieldArray$(FieldCount) = GetFieldArray$(FieldCount) + chr$(char)
      endif
      InQuote = NOT InQuote
    elseIF char = ASC(Delimiter$) then ' check for delimiter
      if InQuote then ' if in quotes, plug delimiter into array
        GetFieldArray$(FieldCount) = GetFieldArray$(FieldCount) + chr$(char)
      else ' next field
        FieldCount = FieldCount + 1
      endif
    else
      ' Only collect characters for the requested field.
      'plug in the character
      GetFieldArray$(FieldCount) = GetFieldArray$(FieldCount) + chr$(char)
    ENDIF
  NEXT
  GFieldArray = FieldCount
End Function



Hope this assists you,
Regards,
panky

__________________
DonTSM1,Duinomite,CGCMM1,CGCMM2,2xDimitech,3xWWuMites,MicksMuP,Grogster1A,4xPeterMuM+,Zonker DIP-600,3xCGuKits,CGuBoard2,SnadPic100,SCBP64 & Exp100,PMMZ144,PMMZ100 .. and loving it![:D
Back to Top View panky's Profile Search for other posts by panky
 


<< Prev Page of 33 Next >>
In the news...
 
Post ReplyPost New Topic
Printable version Printable version
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

Powered by Web Wiz Forums version 7.8
Copyright ©2001-2004 Web Wiz Guide

This page was generated in 0.1055 seconds.
Privacy Policy     Process times : 0, 0, 0, 0.11