ascominitiative / alpycadevice Goto Github PK
View Code? Open in Web Editor NEWSee the README
License: MIT License
See the README
License: MIT License
See this post in ASCOM Developer by @John Hawkes. What about the Common class? How to get it to respond for the appropriate hosted cevice? Also, there is but one DeviceMetadata, however there needs to be one for each hosted ASCOM device. Refactor so that there is a metadata for each ASCOM device.
See this Developer List thread by James Hannon. Templates contain duplicate on_put() blocks! The second one can just be deleted, you'll see it's a partial.
It looks like a line of code is missing in the new focuser.py class connected at line 88
# --------------------------------
### CONNECT/DISCONNECT()PARAM) ###
# --------------------------------
resp.text = MethodResponse(req).json
except Exception as ex:
DriverException(0x500, 'Focuser.{Memname} failed', ex)).json
I think it should be:
# --------------------------------
### CONNECT/DISCONNECT()PARAM) ###
# --------------------------------
resp.text = MethodResponse(req).json
except Exception as ex:
resp.text = MethodResponse(None, req,
DriverException(0x500, 'Focuser.{Memname} failed', ex)).json
Also there is an extra right parentheses at the end of line 79.
See this Dev Forum message and subsequent ones. Omit the Value
field in JSON unless it is real. If the caller of PropertyResponse()
specifies None
for its value
parameter, omit Value
in JSON. If called with err=
other than Success()
, also omit Value
in JSON since it is meaningless.
Bob, thanks for releasing this. I've used it to make a Raspberry Pi Camera driver which you can find here. https://github.com/IanCassTwo/rpicam-ascom-alpaca.
On the whole, it was quite easy to do but there was a few oddities and things that I struggled with.
The camera template has some duplicate on_put methods with the same signature in some classes. I couldn't see why they were there so I deleted them
Some property responses want more fields other than just "Value" so I ended up subclassing the Property Response class under a new name to suit. Not sure if there's a better way to do it
The biggest thing I struggled with was getting the ImageArray in the correct format. I got there eventually but documentation regarding this is terrible on the ASCOM site.
I am a novice programmer and believe based on your videos that the goal is to make this package a very skinny and simple template for someone to get started writing an Alpaca Driver. I really appreciate this package!! I looked all over for days on how to get started writing my own ASCOM COM or Alpaca driver when I could not find something existing to do what I needed. So I am not sure if this is an Issue or intentional. So please forgive me if it was intentional and feel free to ignore this post if it was.
In the original example, there is a "connected" class in the rotator.py example (with both on_get and on_put). From what I understand, all these classes in the .py (rotator.py for example) are used to generate the URI's (ASCOM Alpaca Methods) for each device. From reading the documentation and the ASCOM API website, this "method" appears to be required of all devices (https://ascom-standards.org/api/#/ASCOM%20Methods%20Common%20To%20All%20Devices). The example compiles and passes the ConformU tests. It appears that all the common and device specific methods except "connected" are in the templates.
But when trying to follow the directions for building your own driver using the templates, after trying to run ConformU, I kept getting "404 (NotFound)" errors on all "GET Connected" tests. It took me a lot of time to finally figure out there is no "class connected" in the template I was using (and appears all). Unless I missed it, the documentation did not mention this missing "class connected" in the template. Without the "class connected", it fails conformity testing at the most basic level (404 errors).
So I added back a generic version of the rotator.py example "class connected:" as follows:
@before(PreProcessRequest(maxdev))
class connected:
"""Retrieves or sets the connected state of the device
* Set True to connect to the device hardware. Set False to disconnect
from the device hardware. Client can also read the property to check
whether it is connected. This reports the current hardware state.
* Multiple calls setting Connected to true or false must not cause
an error.
"""
def on_get(self, req: Request, resp: Response, devnum: int):
resp.text = PropertyResponse(True, req).json
def on_put(self, req: Request, resp: Response, devnum: int):
try:
resp.text = MethodResponse(req).json
except Exception as ex:
resp.text = MethodResponse(req, # Put is actually like a method :-(
DriverException(0x500, f'{self.__class__.__name__} failed', ex)).json
It still does not pass the ConformU due to some tests of "bad parameters" being passed (Empty string, Number, Meaningless string), but all of the 404 errors went away.
I know this needs to actually test the connection status (on_get) and connect/disconnect (on_put) and to test the passed values are in range, but it gets rid of the 404 errors and let's me know I need to deal with this method. I would recommend that either the a "class connected" be included with each template or the documentation notes the need for this class to be added to every template.
Should maybe include an ImageBytes encoding function, as well as a pointer to the Alpaca API Reference.
When using the code as described in the documentation to create a different device, for example ObservingConditions, the log file that is generated is "rotatorXXX.log" instead of say "observingconditionsXXX.log". In the log.py file, line 74 appears to have the name of the log file hard coded to "rotator.log". Might want to add this to your changes in the documentation to modify this line in log.py or add it as a config.toml setting.
When trying to use the observingconditions.py template as described in the documentation, when I try to run the code, I get the following error:
I am not a well versed programmer and brand new to Python, but I dropped "to_int" (and later "to_float" when that produced a similar error) and that seems to work. I am not sure if it can't find those to import, does not need them, or were not defined for some reason.
The routing for device-specific setup captures the device number with the wrong name. It is devno
yet all of the responders expect devnum
. This causes the device-specific setup endpoint to fail with a 500 error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.