添加了位置定标程序 及位置移动相关程序源码

This commit is contained in:
2022-01-12 14:30:11 +08:00
parent 5b44f94a64
commit f0ecbb8710
446 changed files with 34544 additions and 0 deletions

View File

@ -0,0 +1,226 @@
/***************************************************//**
* @file NativeUSB.h
* @date October 31, 2007
* @author Ocean Optics, Inc.
*
* This provides a relatively simple interface for
* opening, closing, writing to, and reading from Ocean
* Optics USB Devices. It has been extended to provide
* more complete USB functionality at least for Linux,
* and equivalent functionality should be brought back
* in for Windows and MacOSX.
*
* LICENSE:
*
* SeaBreeze Copyright (C) 2014, Ocean Optics Inc
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************/
#ifndef NATIVEUSB_H
#define NATIVEUSB_H
#ifdef __cplusplus
extern "C" {
#endif /* cplusplus */
#define OPEN_OK 0
#define NO_DEVICE_FOUND -1
#define NO_DEVICE_MATCH -2
#define CLAIM_INTERFACE_FAILED -3
#define CLOSE_OK 0
#define CLOSE_ERROR -1
#define WRITE_FAILED -1
#define READ_FAILED -1
#define ABORT_OK 0
#define ABORT_FAILED -1
#define RESET_OK 0
#define RESET_FAILED -1
struct USBConfigurationDescriptor {
unsigned char bLength;
unsigned char bDescriptorType;
unsigned short wTotalLength;
unsigned char bNumInterfaces;
unsigned char bConfigurationValue;
unsigned char iConfiguration;
unsigned char bmAttributes;
unsigned char MaxPower;
};
struct USBDeviceDescriptor {
unsigned char bLength;
unsigned char bDescriptorType;
unsigned short bcdUSB;
unsigned char bDeviceClass;
unsigned char bDeviceSubClass;
unsigned char bDeviceProtocol;
unsigned char bMaxPacketSize0;
unsigned short idVendor;
unsigned short idProduct;
unsigned short bcdDevice;
unsigned char iManufacturer;
unsigned char iProduct;
unsigned char iSerialNumber;
unsigned char bNumConfigurations;
};
struct USBInterfaceDescriptor {
unsigned char bLength;
unsigned char bDescriptorType;
unsigned char bInterfaceNumber;
unsigned char bAlternateSetting;
unsigned char bNumEndpoints;
unsigned char bInterfaceClass;
unsigned char bInterfaceSubClass;
unsigned char bInterfaceProtocol;
unsigned char iInterface;
};
struct USBEndpointDescriptor {
unsigned char bLength;
unsigned char bDescriptorType;
unsigned char bEndpointAddress;
unsigned char bmAttributes;
unsigned short wMaxPacketSize;
unsigned char bInterval;
};
//------------------------------------------------------------------------------
// This function attempts to discover all devices with the given product
// and vendor IDs. Descriptors for each found device will be placed in the
// provided long buffer.
//
// PARAMETERS:
// vendorID: The vendor ID to match with devices on the bus
// productID: The product ID to match with devices on the bus
// output: A buffer of longs that will be populated with unique IDs for each
// device found that matches the VID and PID
// max_devices: A limit on how many IDs can be put into the output buffer
//
// RETURN VALUE:
// The number of devices successfully found, or -1 if there was an error.
int
USBProbeDevices(int vendorID, int productID, unsigned long *output,
int max_devices);
//------------------------------------------------------------------------------
// This function attempts to open a device with the given product and vendor
// ID's at the specified index.
//
// PARAMETERS:
// deviceID: The ID of a device that has been provided by probeDevices().
// errorCode: A pointer to an integer that will be set to an error code of
// either NO_DEVICE_FOUND or NO_DEVICE_MATCH if an error occured
// while trying to open the device or OPEN_OK if the device was
// found and opened.
//
// RETURN VALUE:
// Returns a void pointer which equals a handle to the device if the device was
// found and opened successfully, or NULL if the device was not opened
// successfully. The value of the 'errorCode' parameter should be checked
// against the following before using the handle:
// - NO_DEVICE_FOUND signifying that no device was found with the specified ID
// or that the device with the specified ID could not be opened
//------------------------------------------------------------------------------
void *
USBOpen(unsigned long deviceID, int *errorCode);
//------------------------------------------------------------------------------
// This function attempts to close the device attached to the given handle.
//
// PARAMETERS:
// handle: The device handle obtained via the open() function.
//
// RETURN VALUE:
// Returns an integer which will be equal to either:
// - CLOSE_OK if the device was closed successfully
// - CLOSE_ERROR if some error occured
//------------------------------------------------------------------------------
int
USBClose(void *handle);
//------------------------------------------------------------------------------
// This function writes the given data to the device attached to the given
// handle.
//
// PARAMETERS:
// handle: The device handle obtained via the open() function.
// endpoint: The endpoint on the device to write the data to.
// data: A pointer to the dynamically allocated byte array of data to be written
// size: The number of bytes to be written
//
// RETURN VALUE:
// Returns an integer which will be equal to either:
// - The number of bytes written to the endpoint if the write was successful
// - WRITE_FAILED if the data was not written to the device
//------------------------------------------------------------------------------
int
USBWrite(void *handle, unsigned char endpoint, char * data, int numberOfBytes);
//------------------------------------------------------------------------------
// This function reads data from the device attached to the given handle into
// the specified byte array.
//
// PARAMETERS:
// handle: The device handle obtained via the open() function.
// endpoint: The endpoint on the device to read the data from.
// data: A pointer to the dynamically allocated byte array to store the data.
// size: The number of bytes to be read.
//
// RETURN VALUE:
// Returns an integer which will be equal to either:
// - The number of bytes read from the endpoint if the read was successful
// - READ_FAILED if the data was not successfully read from the device
//------------------------------------------------------------------------------
int
USBRead(void *handle, unsigned char endpoint, char * data, int numberOfBytes);
//------------------------------------------------------------------------------
// This function attempts to clear any stall on the given endpoint.
//
// PARAMETERS:
// handle: The device handle obtained via the open() function.
// endpoint: The endpoint on the device to clear a stall condition on.
//
// RETURN VALUE:
// No value is returned (void).
//------------------------------------------------------------------------------
void
USBClearStall(void *handle, unsigned char endpoint);
int
USBGetDeviceDescriptor(void *handle, struct USBDeviceDescriptor *desc);
int
USBGetInterfaceDescriptor(void *handle, struct USBInterfaceDescriptor *desc);
int
USBGetEndpointDescriptor(void *handle, int endpoint_index, struct USBEndpointDescriptor *desc);
int
USBGetStringDescriptor(void *handle, unsigned int string_index, char *buffer, int maxLength);
#ifdef __cplusplus
}
#endif /* _cplusplus */
#endif /* NATIVEUSB_H */

View File

@ -0,0 +1,84 @@
/***************************************************//**
* @file USB.h
* @date February 2009
* @author Ocean Optics, Inc.
*
* LICENSE:
*
* SeaBreeze Copyright (C) 2014, Ocean Optics Inc
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*******************************************************/
#ifndef SEABREEZE_USB_H
#define SEABREEZE_USB_H
#include "native/usb/USBDiscovery.h"
#include "native/usb/NativeUSB.h"
#include <string>
namespace seabreeze {
/* Empty declaration of USBDiscovery to deal with cross-includes */
class USBDiscovery;
class USB {
public:
virtual ~USB();
bool open();
bool close();
int write(int endpoint, void *data, unsigned int length_bytes);
int read(int endpoint, void *data, unsigned int length_bytes);
void clearStall(int endpoint);
static void setVerbose(bool v);
int getDeviceDescriptor(struct USBDeviceDescriptor *desc);
int getInterfaceDescriptor(struct USBInterfaceDescriptor *desc);
/* Get the endpoint descriptor where index is the endpoint index. */
int getEndpointDescriptor(int index, struct USBEndpointDescriptor *epDesc);
std::string *getStringDescriptor(int index);
int getMaxPacketSize();
bool isOpened();
/* This allows the USBDiscovery class to access the protected
* constructor and act as a factory for USB instances.
*/
friend class USBDiscovery;
protected:
/* These methods are primarily for debugging. */
void usbHexDump(void *x, int length, int endpoint);
void hexDump(void *x, int length);
void describeTransfer(const char *label, int length, void* data, int endpoint, bool hexdump);
USB(unsigned long deviceID);
void *descriptor;
bool opened;
static bool verbose;
unsigned long deviceID;
};
}
#endif

View File

@ -0,0 +1,64 @@
/***************************************************//**
* @file USBDiscovery.h
* @date February 2012
* @author Ocean Optics, Inc.
*
* LICENSE:
*
* SeaBreeze Copyright (C) 2014, Ocean Optics Inc
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*******************************************************/
#ifndef USBDISCOVERY_H
#define USBDISCOVERY_H
#include "native/usb/USB.h"
#include <vector>
namespace seabreeze {
/* Empty declaration of USB to deal with cross-includes */
class USB;
class USBDiscovery {
public:
USBDiscovery();
~USBDiscovery();
/**
* Probes the bus for devices of the given VID and PID and returns
* a vector of identifiers. Note that these IDs are implementation-
* specific and are not necessarily portable between platforms. They
* are not guaranteed to be constant from one program execution to the
* next, though they should remain constant from one invocation of this
* method to the next within one execution if no devices change status.
*/
std::vector<unsigned long> *probeDevices(int vendorID, int productID);
/**
* Given an identifier from probeDevices(), create a USB interface to
* the device that can be used to open/write/read/close the device.
*/
USB *createUSBInterface(unsigned long deviceID);
};
}
#endif /* USBDISCOVERY_H */

View File

@ -0,0 +1,47 @@
/***************************************************//**
* @file WindowsGUID.h
* @date June 2009
* @author Ocean Optics, Inc.
*
* This provides GUID definitions for supported devices.
* These must match what appears in the .inf file for the
* devices to be found properly through the WinUSB API.
*
* LICENSE:
*
* SeaBreeze Copyright (C) 2014, Ocean Optics Inc
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*******************************************************/
#pragma once
#ifndef SEABREEZE_WINDOWS_GUID_H
#define SEABREEZE_WINDOWS_GUID_H
// {BAD36DAB-A3D2-4a0e-8B2E-DA36202187D4}
DEFINE_GUID(GUID_DEVCLASS_OCEANOPTICS_USB,
0xbad36dab, 0xa3d2, 0x4a0e, 0x8b, 0x2e, 0xda, 0x36, 0x20, 0x21, 0x87, 0xd4);
// {DBBAD306-1786-4f2e-A8AB-340D45F0653F}
DEFINE_GUID(GUID_DEVINTERFACE_OCEANOPTICS_USB,
0xdbbad306, 0x1786, 0x4f2e, 0xa8, 0xab, 0x34, 0xd, 0x45, 0xf0, 0x65, 0x3f);
#endif