def SetCurve(session, curve): """Send the curve to the camera Arguments: session -- The PtpSession.""" ptp_request = PtpSession.PtpRequest(PtpValues.NikonOperations.SET_CURVE, session.sessionid, session.NewTransaction()) (ptp_response, rx) = session.transport.ptp_simple_transaction(ptp_request, tx_data=curve.pack()) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpSession.PtpException(ptp_response.respcode)
def AutoFocus(session): """Automatically focus the device. Arguments: session -- The PtpSession.""" ptp_request = PtpSession.PtpRequest(PtpValues.NikonOperations.AUTO_FOCUS, session.sessionid, session.NewTransaction()) (ptp_response, rx) = session.transport.ptp_simple_transaction(ptp_request, receiving=False) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpSession.PtpException(ptp_response.respcode)
def DisableBodyControls(session, body_control): """Disable/enable camera body controls Arguments: session -- The PtpSession control_mode -- The camera control mode to set.""" ptp_request = PtpSession.PtpRequest( PtpValues.NikonOperations.DISABLE_BODY_CONTROLS, session.sessionid, session.NewTransaction(), (body_control, )) (ptp_response, rx) = session.transport.ptp_simple_transaction(ptp_request, receiving=False) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpSession.PtpException(ptp_response.respcode)
def GetThumbMedium(session, objectHandle, stream=None): """Get a medium sized thumbnail. Arguments: session -- The PtpSession. objectid -- The objectid concerned.""" ptp_request = PtpSession.PtpRequest( PtpValues.NikonOperations.GET_THUMB_MEDIUM, session.sessionid, session.NewTransaction(), (objectHandle, )) session.transport.send_ptp_request(ptp_request) rx_data = session.transport.get_ptp_data(ptp_request, stream) ptp_response = session.transport.get_ptp_response(ptp_request) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpSession.PtpException(ptp_response.respcode) return rx_data
def GetCurve(session): """Retrieve the curve from the camera Arguments: session -- The PtpSession.""" ptp_request = PtpSession.PtpRequest(PtpValues.NikonOperations.GET_CURVE, session.sessionid, session.NewTransaction()) (ptp_response, rx) = session.transport.ptp_simple_transaction(ptp_request, receiving=True) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpSession.PtpException(ptp_response.respcode) return NikonCurveInfo(rx[1])
def RamCapture(session): """Capture a picture and leave it in the camera's RAM. Does not autofocus. Arguments: session -- The PtpSession.""" # The meaning of the parameter is unknown: 0xffffffff captures into RAM. 0 captures, but doesn't appear to actually save the image ptp_request = PtpSession.PtpRequest(PtpValues.NikonOperations.RAM_CAPTURE, session.sessionid, session.NewTransaction(), (0xffffffff, )) (ptp_response, rx) = session.transport.ptp_simple_transaction(ptp_request, receiving=False) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpSession.PtpException(ptp_response.respcode)
def CheckEvents(session): """Check events on the camera -- e.g. Nikon doesn't appear to report property change events over the standard IRQ pipe.""" ptp_request = PtpSession.PtpRequest(PtpValues.NikonOperations.CHECK_EVENTS, session.sessionid, session.NewTransaction()) (ptp_response, rx) = session.transport.ptp_simple_transaction(ptp_request, receiving=True) if ptp_response.respcode != PtpValues.StandardResponses.OK: raise PtpSession.PtpException(ptp_response.respcode) unpacker = PtpSession.PtpUnpacker(rx[1]) events = () for i in xrange(0, unpacker.unpack("<H")[0]): (code, param) = unpacker.unpack("<HI") events += (PtpAbstractTransport.PtpEvent(code, 0xffffffff, 0xffffffff, (param, )), ) return events
def __init__(self, raw): unpacker = PtpSession.PtpUnpacker(raw) (data_length, unknown, self.xaxis_start, self.xaxis_end, self.yaxis_start, self.yaxis_end, self.midpoint_integer, self.midpoint_decimal, coordcount) = unpacker.unpack("<IHBBBBBBB") self.coordinates = () while coordcount: self.coordinates += (unpacker.unpack("<BB"), ) coordcount -= 1
def pack(self): packer = PtpSession.PtpPacker() packer.pack("<IHBBBBBBB", 2116, 24393, self.xaxis_start, self.xaxis_end, self.yaxis_start, self.yaxis_end, self.midpoint_integer, self.midpoint_decimal, len(self.coordinates)) for c in self.coordinates: packer.pack("<BB", c[0], c[1]) # FIXME: The rest of the file is unknown return packer.raw
def PollStatus(session): """Poll the status of the device (e.g. for monitoring ASYNC operations such as autofocus or capture). Arguments: session -- The PtpSession.""" ptp_request = PtpSession.PtpRequest(PtpValues.NikonOperations.POLL_STATUS, session.sessionid, session.NewTransaction()) (ptp_response, rx) = session.transport.ptp_simple_transaction(ptp_request, receiving=False) return ptp_response.respcode