I've now had chance to do some more investigation and research since my last posting and found the following. The reason that saving files in Web2py causes RTS to be asserted and makes my application work is that my file 'control.py', which contains all my serial functions, includes the lines:
import serial ser=serial.Serial('/dev/ttyUSB0', 57600, timeout=1, xonxoff=0, rtscts=0) If I remove/comment out the line 'ser=serial.Serial... ' then the file save has no effect. Presumably Wb2py must be executing this line somehow as part of it's parsing process, and saving my other file 'utilities.py' has the same effect because it contains 'import * from control.py'. I have also been playing with the Pyserial functions ser.setRTS() and ser.rts, which should force the state of RTS. I have been running these from Python scripts in my user account and found that if reboot the Pi, save one of the files in Web2py to force RTS low, then execute ser.rts or ser.setRTS using my scripts, I can set RTS high or low and that state persists. However, if I reboot the Pi and run my script *without* saving the files in Web2py then run my scripts it only cause RTS to pulse low momentarily, presumably while the script is running. I've tried including a similar script within the Web2py 'modules' area, I've tried including the set.rts commands within my serial functions, I've tried a separate function just to include that command but nothing has done anything other than pulse RTS until the script/function ends. I haven't tried running a routine once at startup yet, but I'm not sure how this will be different from running scripts 'by hand', except as far as I am aware I cannot run scripts as the 'www-data' user as there is no login/password for that account, and I have a strange feeling that there must be some sort of ownership issue here. I have written/hacked scripts to run at startup to start the Web2py Scheduler and GPIOSever but this is all a bit close to the limits of my knowledge and ability! In summary, I am further forward in the sense that I understand why, if not how, Web2py file saves make my application work, although not why RTS gets set permanently low by this mechanism and not when the serial port is opened at any other time, and more information on what is happening here would be useful. I also know that there is a mechanism for changing the state of RTS, which it must be possible to do somehow, but have no real idea how to do it. I also now believe that keeping the port permanently open is not necessary, provided RTS can be forced low. So, any clues as to how I might be able to set RTS at startup will be gratefully received! Richard Richard On Friday, November 25, 2016 at 11:10:26 PM UTC, Dave S wrote: > > > On Friday, November 25, 2016 at 4:50:34 AM UTC-8, Richard Brown wrote: >> >> An update to this - I have done some more investigation and discovered >> that in the 'Not Working' scenario the RTS output is mostly high but goes >> low whilst the port is open, and in the 'Working' scenario the RTS output >> has somehow been forced low and so stays low when the port is opened. >> The Dongle gets reset by a high-to-low transition of RTS, so no falling >> edge, no Reset and everything works. For reference my Dongle uses an FTDI >> device (FT230X) and hence the FTDI driver supplied with the latest Raspbian >> (Jessie) release. >> >> The question now, therefore, is how Web2py forces RTS low - either by the >> saving of a file or when I access the index page of my Site, and How I can >> replicate this in the Scheduler code! Using 'touch' to update the file does >> not work, it has to be saved from within Web2py. >> >> Richard >> > > I can't imagine how saving the file causes RTS to go low. Web2py should > not have any reason to do anything to the serial port on its own, and > probably doesn't even know the serial port exists (it's only concerned with > the console). (I haven't done any serial port handling under Ubuntu, nor on > the RaspberryPi, so I can't tell you about any special tricks such ports > need.) > > You may want to investigate having a separate program that gets started on > system startup, runs forever, and holds the serial port open all the time. > It can check for a file existing, write the current value to the file, and > snooze again. Your scheduled task would the create the file, wait briefly, > and then read the file to get the current value. > > I do know someone with a RaspberryPi, and he's a bit of hacker, but it > will be next week before I see him again. > > /dps > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.