Note that there are some explanatory texts on larger screens.

plurals
  1. POSerialTimeoutException crashes script
    primarykey
    data
    text
    <p>This script crashes due to a serial timout exception after an extended period of time. It's been making it to 5000 loops or so before it has the following error: </p> <pre><code>Traceback (most recent call last): File "C:\Users\3d Exposure\Desktop\venderFix.py", line 69, in &lt;module&gt; A.setHigh(12) File "C:\Python27\lib\arduino\arduino.py", line 30, in setHigh self.__sendData('1') File "C:\Python27\lib\arduino\arduino.py", line 58, in __sendData self.serial.write(str(serial_data)) File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 270, in write raise writeTimeoutError SerialTimeoutException: Write timeout </code></pre> <p>Why would it time out after working perfectly for so long? How do I stop it doing so?</p> <pre><code>import json import urllib from pprint import pprint import time from arduino import Arduino ############################################################## #Change to suit the Mars Bars, currently at 0.2 of a second # vendtime = 0.2 # # #Delay Time Between each Search (never below 15 seconds) # delayTime = 15 # #This is the search term for the URL. (%23 = #) # searchTerm = '%23happy' # # A = Arduino('COM3') # A.output([13]) #Output on pin 12 # ############################################################## #to collect the first tweet without vending countTweet = 0 #To test Twitter for consistancy tweet= 0 noTweet= 0 #the infinate loop while True: #j contains the JSON we load from the URL j =json.loads(urllib.urlopen('http://search.twitter.com/search.json?q='+searchTerm+'&amp;result_type=recent&amp;rpp=1&amp;filter:retweets').read()) #Debug JSON from twitter (for faults on the Twitter end or possible GET limit id below 15 seconds per request) #pprint(j) #needed for debugging only #find the text and the tweet id if 'results' in j and j['results']: text = j['results'][0]['text'] id = j['results'][0]['id'] #how many times the Json is complete tweet+= 1 else: #How many times the Json is incomplete (sometimes twitter malfunctions. About 0.1 in 100 are broken) noTweet += 1 #print the text and id to the screen pprint(text) #needed for debugging only pprint(id) #needed for debugging only #to get the existing tweet from before we power on, if the first ID has been stored already (count == 1) if countTweet != 0: #if countTweet is not equal to 0 then it's not the first tweet #pprint ("new loop") #needed for debugging only #if lastID is not equal to ID if lastID != id: #Tell Arduino to Vend #pin 12 HIGH A.setHigh(13) #Sleep for the time specified in vendtime time.sleep(vendtime) #pin 12 LOW A.setLow(13) #Display the tweet that triggered the vend #pprint(text) #needed for debugging only #pprint(id) #needed for debugging only #Make lastID equal to ID so that next time we can compare it lastID = id #pprint ('lastID updated') #needed for debugging only #if no new tweets, print else: #needed for debugging only pprint ('no new tweets') #needed for debugging only #If it's the first loop, confirm by printing to the screen else: pprint("First loop complete") pprint(text) pprint(id) lastID = id pprint(lastID) countTweet += 1 #Add 1 to countTweet pprint ('Number of Tweets') pprint (countTweet) pprint('Working JSON') pprint(tweet) pprint('Broken JSON') pprint(noTweet) pprint('waiting') time.sleep(delayTime) </code></pre> <p>For communication with the Arduino I am using the Python Arduino Prototyping API v2. It works well, this is the first and only issue in serial I have had with this script. I imagine I need to set a timeout myself although I am not 100% sure how to ensure this would not have the same or a similar problem.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload