Added first draft of API. not very stable, and limited device suport.

This commit is contained in:
Chris Esposito 2018-01-11 12:20:16 +11:00
parent a3aa5adacc
commit 8ebd95e928
33 changed files with 10006 additions and 0 deletions

View File

@ -0,0 +1,80 @@
#define COMPILING_WITH_OCTAVE
//MATLAB INCLUDES
#ifndef COMPILING_WITH_OCTAVE
#include <matrix.h>
#endif
#include <mex.h>
//LIBUSB INCLUDES
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "libusb.h"
//MISC INCLUDES
#include <math.h>
#include <string.h>
#define INPUT_BUFFER_SIZE 256
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
//Raw Inputs
char *HANDLE_CHAR_RAW_IN;
char *CTX_CHAR_RAW_IN;
char *REQUEST_TYPE_RAW_IN;
char *REQUEST_RAW_IN;
char *VALUE_RAW_IN;
char *INDEX_RAW_IN;
char *LENGTH_RAW_IN;
//Processed inputs
libusb_context *ctx;
libusb_device_handle *handle;
uint8_t RequestType;
uint8_t Request;
uint16_t Value;
uint16_t Index;
uint16_t Length;
unsigned char *LDATA;
//Interals
unsigned char *controlBuffer;
//To export:
unsigned char inBuffer[INPUT_BUFFER_SIZE];
//Parse Inputs
HANDLE_CHAR_RAW_IN = mxArrayToString(prhs[0]);
sscanf(HANDLE_CHAR_RAW_IN, "%016x", &ctx);
CTX_CHAR_RAW_IN = mxArrayToString(prhs[1]);
sscanf(CTX_CHAR_RAW_IN, "%016x", &handle);
REQUEST_TYPE_RAW_IN = mxArrayToString(prhs[2]);
sscanf(REQUEST_TYPE_RAW_IN, "%2x", &RequestType);
REQUEST_RAW_IN = mxArrayToString(prhs[3]);
sscanf(REQUEST_RAW_IN, "%2x", &Request);
VALUE_RAW_IN = mxArrayToString(prhs[4]);
sscanf(VALUE_RAW_IN, "%4x", &Value);
INDEX_RAW_IN = mxArrayToString(prhs[5]);
sscanf(INDEX_RAW_IN, "%4x", &Index);
LENGTH_RAW_IN = mxArrayToString(prhs[6]);
sscanf(LENGTH_RAW_IN, "%4x", &Length);
controlBuffer = mxGetData(prhs[7]);
//Send the packet
int error;
error = libusb_control_transfer(handle, RequestType, Request, Value, Index, controlBuffer, Length, 4000);
if(error<0){
mexPrintf("Error number: %d\n", error);
mexPrintf("libusb_control_transfer FAILED with error %s", libusb_error_name(error));
}
return;
}

View File

@ -0,0 +1,55 @@
#define COMPILING_WITH_OCTAVE
//MATLAB INCLUDES
#ifndef COMPILING_WITH_OCTAVE
#include <matrix.h>
#endif
#include <mex.h>
//LIBUSB INCLUDES
#include <stdio.h>
#include <stdlib.h>
#include "libusb.h"
//MISC INCLUDES
#include <math.h>
#include <string.h>
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
//Raw Inputs
char *HANDLE_CHAR_RAW_IN, *CTX_CHAR_RAW_IN;
//Processed inputs
libusb_context *ctx;
libusb_device_handle *handle;
//Interals
//To export:
//Parse Inputs
HANDLE_CHAR_RAW_IN = mxArrayToString(prhs[0]);
CTX_CHAR_RAW_IN = mxArrayToString(prhs[1]);
sscanf(HANDLE_CHAR_RAW_IN, "%016x", &ctx);
sscanf(CTX_CHAR_RAW_IN, "%016x", &handle);
//Delete the handle and the CTX
mexPrintf("\nFreeing the following Libusb structures:\n");
mexPrintf("Interface: Handle 0x%016x, Interface 0\n", handle);
mexPrintf("Handle: 0x%016x\n", handle);
mexPrintf("Context: 0x%016x\n", ctx);
libusb_release_interface(handle, 0);
mexPrintf("Interface released\n");
libusb_close(handle);
mexPrintf("Device Closed\n");
//Early return here, seems to prevent Octave from crashing (or normal exit, Ubuntu isn't complaining???)
mexPrintf("To prevent a crash in Octave, the Libusb Context was not exited completely.\nThe device handles should all be free, however.\n");
return;
libusb_exit(ctx);
mexPrintf("Libusb exited\n");
return;
}

View File

@ -0,0 +1,85 @@
#define COMPILING_WITH_OCTAVE
//MATLAB INCLUDES
#ifndef COMPILING_WITH_OCTAVE
#include <matrix.h>
#endif
#include <mex.h>
//LIBUSB INCLUDES
#include <stdio.h>
#include <stdlib.h>
#include "libusb.h"
//MISC INCLUDES
#include <math.h>
#include <string.h>
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
//Raw Inputs
char *VID_CHAR_RAW_IN, *PID_CHAR_RAW_IN;
//Processed inputs
unsigned int VID, PID;
//Interals
libusb_context *ctx;
libusb_device_handle *handle;
//To export:
char handle_string[17]; //128 bits allocated, including char.
char ctx_string[17];
//Parse Inputs
VID_CHAR_RAW_IN = mxArrayToString(prhs[0]);
PID_CHAR_RAW_IN = mxArrayToString(prhs[1]);
printf("VID=%s\n", VID_CHAR_RAW_IN);
printf("PID=%s\n", PID_CHAR_RAW_IN);
sscanf(VID_CHAR_RAW_IN, "%4x", &VID);
sscanf(PID_CHAR_RAW_IN, "%04x", &PID);
//Initialise the Library
int error;
error = libusb_init(&ctx);
if(error){
mexPrintf("libusb_init FAILED\n");
return;
} else mexPrintf("Libusb context initialised\n");
libusb_set_debug(ctx, 3);
//Get a handle on the Labrador device
handle = libusb_open_device_with_vid_pid(ctx, VID, PID);
if(handle==NULL){
mexPrintf("DEVICE NOT FOUND\n");
return;
}
mexPrintf("Device found!!\n");
//Claim the interface
error = libusb_claim_interface(handle, 0);
if(error){
mexPrintf("libusb_claim_interface FAILED\n");
return;
} else mexPrintf("Interface claimed!\n");
mexPrintf("Handle is %d bytes long\n", sizeof(handle));
mexPrintf("Handle data is 0x%016x\n", handle);
mexPrintf("Context is %d bytes long\n", sizeof(ctx));
mexPrintf("Context data is 0x%016x\n", ctx);
sprintf(handle_string, "%016x", handle);
sprintf(ctx_string, "%016x", ctx);
mexPrintf("\nConverting values... Ensure they're unchanged!\n");
mexPrintf("Handle: %s\n",handle_string);
mexPrintf("Context: %s\n", ctx_string);
plhs[0] = mxCreateString(handle_string);
plhs[1] = mxCreateString(ctx_string);
return;
}

View File

@ -0,0 +1,6 @@
#ifndef LIBDFUPROG_H
#define LIBDFUPROG_H
int dfuprog_virtual_cmd(char* commandLine);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
#ifndef PLATFORMSPECIFIC_H
#define PLATFORMSPECIFIC_H
#include "unixusbdriver.h"
#define PLATFORM_LINUX
#define _PLATFORM_DEPENDENT_USB_OBJECT unixUsbDriver
#define _PLATFORM_DEPENDENT_FOLDER_ACTION
#endif // PLATFORMSPECIFIC_H

View File

@ -0,0 +1,6 @@
#ifndef LIBDFUPROG_H
#define LIBDFUPROG_H
int dfuprog_virtual_cmd(char* commandLine);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
#ifndef PLATFORMSPECIFIC_H
#define PLATFORMSPECIFIC_H
#include "unixusbdriver.h"
#define PLATFORM_MAC
#define _PLATFORM_DEPENDENT_USB_OBJECT unixUsbDriver
#define _PLATFORM_DEPENDENT_FOLDER_ACTION
#endif // PLATFORMSPECIFIC_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,309 @@
/*! \file lusbk_shared.h
* \brief Types and defines shared with the driver.
*/
#ifndef __LUSBK_SHARED_H_
#define __LUSBK_SHARED_H_
#ifndef __USB_H__
//! Values used in the \c bmAttributes field of a \ref USB_ENDPOINT_DESCRIPTOR
typedef enum _USBD_PIPE_TYPE
{
//! Indicates a control endpoint
UsbdPipeTypeControl,
//! Indicates an isochronous endpoint
UsbdPipeTypeIsochronous,
//! Indicates a bulk endpoint
UsbdPipeTypeBulk,
//! Indicates an interrupt endpoint
UsbdPipeTypeInterrupt,
} USBD_PIPE_TYPE;
#endif
#if !defined(__WINUSB_COMPAT_IO_H__) && !defined(__WUSBIO_H__)
// pipe policy types ///////////////
#define SHORT_PACKET_TERMINATE 0x01
#define AUTO_CLEAR_STALL 0x02
#define PIPE_TRANSFER_TIMEOUT 0x03
#define IGNORE_SHORT_PACKETS 0x04
#define ALLOW_PARTIAL_READS 0x05
#define AUTO_FLUSH 0x06
#define RAW_IO 0x07
#define MAXIMUM_TRANSFER_SIZE 0x08
#define RESET_PIPE_ON_RESUME 0x09
// libusbK ISO pipe policy types ///
#define ISO_START_LATENCY 0x20
#define ISO_ALWAYS_START_ASAP 0x21
#define ISO_NUM_FIXED_PACKETS 0x22
// http://msdn.microsoft.com/en-us/library/windows/hardware/ff552359%28v=vs.85%29.aspx
// Settings.Parallel.NumberOfPresentedRequests
// Maximum number of transfers that can be asynchronously delivered at a
// time. Available in version 1.9 and later versions of KMDF.
#define SIMUL_PARALLEL_REQUESTS 0x30
// Power policy types //////////////
#define AUTO_SUSPEND 0x81
#define SUSPEND_DELAY 0x83
// Device Information types ////////
#define DEVICE_SPEED 0x01
// Device Speeds
#define LowSpeed 0x01
#define FullSpeed 0x02
#define HighSpeed 0x03
//! The \c WINUSB_PIPE_INFORMATION structure contains pipe information that the \ref UsbK_QueryPipe routine retrieves.
typedef struct _WINUSB_PIPE_INFORMATION
{
//! A \c USBD_PIPE_TYPE enumeration value that specifies the pipe type
USBD_PIPE_TYPE PipeType;
//! The pipe identifier (ID)
UCHAR PipeId;
//! The maximum size, in bytes, of the packets that are transmitted on the pipe
USHORT MaximumPacketSize;
//! The pipe interval
UCHAR Interval;
} WINUSB_PIPE_INFORMATION;
//! Pointer to a \ref WINUSB_PIPE_INFORMATION structure
typedef WINUSB_PIPE_INFORMATION* PWINUSB_PIPE_INFORMATION;
C_ASSERT(sizeof(WINUSB_PIPE_INFORMATION) == 12);
#include <pshpack1.h>
//! The \c WINUSB_SETUP_PACKET structure describes a USB setup packet.
/*!
* It is often more convient to use this structure in combination with a \ref KUSB_SETUP_PACKET.
* For example:
* \code
* \endcode
*/
typedef struct _WINUSB_SETUP_PACKET
{
//! The request type. The values that are assigned to this member are defined in Table 9.2 of section 9.3 of the Universal Serial Bus (USB) specification (www.usb.org).
UCHAR RequestType;
//! The device request. The values that are assigned to this member are defined in Table 9.3 of section 9.4 of the Universal Serial Bus (USB) specification.
UCHAR Request;
//! The meaning of this member varies according to the request. For an explanation of this member, see the Universal Serial Bus (USB) specification.
USHORT Value;
//! The meaning of this member varies according to the request. For an explanation of this member, see the Universal Serial Bus (USB) specification.
USHORT Index;
//! The number of bytes to transfer. (not including the \c WINUSB_SETUP_PACKET itself)
USHORT Length;
} WINUSB_SETUP_PACKET;
//! pointer to a \c WINUSB_SETUP_PACKET structure
typedef WINUSB_SETUP_PACKET* PWINUSB_SETUP_PACKET;
C_ASSERT(sizeof(WINUSB_SETUP_PACKET) == 8);
#include <poppack.h>
#endif // __WUSBIO_H__ __WINUSB_COMPAT_IO_H__
#include <pshpack1.h>
/*! \addtogroup isok
* @{
*/
//! Structure describing an isochronous transfer packet.
typedef struct _KISO_PACKET
{
//! Specifies the offset, in bytes, of the buffer for this packet from the beginning of the entire isochronous transfer data buffer.
/*!
* \c Offset represents an absolute data offset from the start of the \c Buffer parameter \ref UsbK_IsoReadPipe or \ref UsbK_IsoWritePipe.
*
* \note This field is assigned by the user application only and used by the driver upon transfer submission and completion.
*/
UINT Offset;
//! Set by the host controller to indicate the actual number of bytes received by the device for isochronous IN transfers. Length not used for isochronous OUT transfers.
/*!
* \note This field is is not user assignable and is updated by the driver upon transfer completion.
*/
USHORT Length;
//! Contains the 16 least significant USBD status bits, on return from the host controller driver, of this transfer packet.
/*!
* See MSDN for USBD status codes: <A href="http://msdn.microsoft.com/en-us/library/ff539136%28VS.85%29.aspx">USBD status code reference</A>
*
* \note This field is is not user assignable and is updated by the driver upon transfer completion.
*/
USHORT Status;
} KISO_PACKET;
//! pointer to a \c KISO_PACKET structure
typedef KISO_PACKET* PKISO_PACKET;
#pragma warning(disable:4200)
//! Additional ISO transfer flags.
typedef enum _KISO_FLAG
{
KISO_FLAG_NONE = 0,
//! Do not start the transfer immediately, instead use \ref KISO_CONTEXT::StartFrame.
/*!
* By default, isochronous transfers start on the next frame and \ref KISO_CONTEXT::StartFrame is
* ignored. If this flag is specified, the transfer is postponed until the current usb frame number
* equals that specified by \ref KISO_CONTEXT::StartFrame.
*
* Under certain circumstances, the driver can specify 0 for \ref KISO_CONTEXT::StartFrame, and the bus
* driver will begin the transaction in the next available frame.
*
* Specifing \b 0 for \ref KISO_CONTEXT::StartFrame (start transfer ASAP) is restricted to the first
* transaction on a newly opened or reset pipe. Furthermore, the USB stack contains a bug in Microsoft
* Windows Server 2003 and Windows XP that limits the use of this to an isochronous context with 255 or fewer
* packets.
*
* For more information about resetting pipes, see \ref UsbK_ResetPipe.
*/
KISO_FLAG_SET_START_FRAME = 0x00000001,
} KISO_FLAG;
//! Structure describing a user defined isochronous transfer.
/*!
*
* \fixedstruct{16}
*
* The \ref KISO_CONTEXT::StartFrame member of the \ref KISO_CONTEXT specifies the starting USB frame number
* for the transaction. The driver can use \ref UsbK_GetCurrentFrameNumber to request the current frame
* number.
*
* In full-speed transmissions, the frame number for any particular packet will be the sum of the start frame
* number and the packet index. For instance, the fourth packet in the \ref KISO_CONTEXT has an index of 3, so
* its frame number will be StartFrame + 3. In a write transfer, the port driver loads this frame with the
* buffer data at the data buffer offset specified by IsoPacket[3].Offset.
*
* When the driver processes the \ref KISO_CONTEXT, it discards all packets in the \ref KISO_CONTEXT whose
* frame numbers are lower than the current frame number. The port driver sets the Status member of the packet
* descriptor for each discarded packet to USBD_STATUS_ISO_NA_LATE_USBPORT, USBD_STATUS_ISO_NOT_ACCESSED_BY_HW
* or USBD_STATUS_ISO_NOT_ACCESSED_LATE. Even if it discards some packets, the port driver attempts to
* transmit those packets in the \ref KISO_CONTEXT whose frame numbers are higher than the current frame
* number.
*
* The check for a valid StartFrame member is slightly more complicated in high-speed transmissions because
* the port driver loads each packet into a high-speed microframe; however, the value in StartFrame refers to
* the 1 millisecond (full-speed) frame number, not the microframe. For example, if the StartFrame value
* recorded in the \ref KISO_CONTEXT is one less than the current frame, the port driver will discard as many
* as eight packets. The exact number of packets that the port driver discards depends on the period
* associated with the isochronous pipe.
*
* High-speed isochronous pipes can have periods of 1, 2, 4, or 8. The period number specifies the frequency
* with which the port driver inserts packets into the data stream. If the period is 2, for example, the port
* driver will insert a packet into the data stream every two microframes. This means that it will only use
* four of the eight microframes available within each 1-millisecond frame for isochronous data transmission.
*
* In general, the higher the period, the fewer packets the port driver will discard when a \ref KISO_CONTEXT
* arrives late. Assume the period on an isochronous pipe is 2. With a period of 2, each 1-millisecond speed
* frame will carry four packets of isochronous data for that pipe. So, for example, if CurrentFrame -
* StartFrame = 3, the port driver will discard 3 * 4 = 12 packets. On the other hand, if the period is 4,
* each 1-millisecond frame carries only two packets of isochronous data for the pipe. Therefore, if the
* \ref KISO_CONTEXT arrives three 1-millisecond frames late, as in the previous example, the port driver will
* discard 3 * 2 = 6 packets, instead of 12 packets.
*
* For all types of isochronous pipe, the distance between the current frame and the StartFrame value
* specified in the \ref KISO_CONTEXT must be less than USBD_ISO_START_FRAME_RANGE. If StartFrame is not
* within the proper range, the driver sets the Status member of the \ref KISO_PACKET
* \c USBD_STATUS_BAD_START_FRAME and discards the entire \ref KISO_CONTEXT. The following code example shows
* the precise check that the port driver does on the \ref KISO_CONTEXT start frame:
* \code
* if (abs((CurrentFrame - StartFrame)) > USBD_ISO_START_FRAME_RANGE)
* {
* // discard the KISO_CONTEXT
* }
* \endcode
*
*/
typedef struct _KISO_CONTEXT
{
//! Additional ISO transfer flags. See \ref KISO_FLAG.
KISO_FLAG Flags;
//! Specifies the frame number that the transfer should begin on (0 for ASAP).
/*!
* This variable must be within a system-defined range of the current frame. The range is specified by the
* constant \ref USBD_ISO_START_FRAME_RANGE.
*
* If /ref KISO_FLAG_SET_START_FRAME was specified, this member contains the frame number that the transfer should begin on.
* When the request is returned by the host controller driver, this member is updated to reflect the frame number this transfer
* did begin on.
*
* \note This field may be assigned by the user application and is updated by the driver upon transfer
* completion.
*/
UINT StartFrame;
//! Contains the number of packets that completed with an error condition on return from the host controller driver.
/*!
* \note This field is is not user assignable and is updated by the driver upon transfer completion.
*/
SHORT ErrorCount;
//! Specifies the number of packets that are described by the variable-length array member \c IsoPacket.
/*
* \note This field is assigned by the user application only and used by the driver upon transfer submission
* and completion.
*/
SHORT NumberOfPackets;
//! Contains the URB Hdr.Status value on return from the host controller driver.
/*!
* \note This field is is not user assignable and is updated by the driver upon transfer completion.
*
* The USB bus driver always returns a value of USBD_STATUS_SUCCESS in
* Hdr.Status, unless every packet in the transfer generated an error or
* the request was not well-formed and could not be executed at all. The
* following table includes possible error codes returned in Hdr.Status:
* - USBD_STATUS_ISOCH_REQUEST_FAILED
* Indicates that every packet of an isochronous request was completed with
* errors.
* - USBD_STATUS_BAD_START_FRAME
* Indicates that the requested start frame is not within
* USBD_ISO_START_FRAME_RANGE of the current USB frame.
* - USBD_ISO_NOT_ACCESSED_LATE
* Indicates that every packet was submitted too late for the packet to be
* sent, based on the requested start frame.
* - USBD_STATUS_INVALID_PARAMETER
* Indicates that one of the URB parameters was incorrect.
*/
UINT UrbHdrStatus;
//! Contains a variable-length array of \c KISO_PACKET structures that describe the isochronous transfer packets to be transferred on the USB bus.
/*
* \note This field is assigned by the user application, used by the driver upon transfer submission, and
* updated by the driver upon transfer completion.
*/
KISO_PACKET IsoPackets[0];
} KISO_CONTEXT;
C_ASSERT(sizeof(KISO_CONTEXT) == 16);
//! pointer to a \c KISO_CONTEXT structure
typedef KISO_CONTEXT* PKISO_CONTEXT;
/*! @} */
#pragma warning(default:4200)
#include <poppack.h>
#endif // __LUSBK_SHARED_H_

View File

@ -0,0 +1,10 @@
#ifndef PLATFORMSPECIFIC_H
#define PLATFORMSPECIFIC_H
#include "winusbdriver.h"
#define _PLATFORM_DEPENDENT_USB_OBJECT winUsbDriver
#define PLATFORM_WINDOWS
#define _PLATFORM_DEPENDENT_FOLDER_ACTION
#endif // PLATFORMSPECIFIC_H

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,32 @@
clc
fprintf("\n\n\nCompiling USB_INIT_LIBUSB...\n\n\n");
fflush(stdout);
mex C/USB_INIT_LIBUSB.c -IC/build_linux/libusb -lusb-1.0 -Lbin\lib\x64
copyfile USB_INIT_LIBUSB.mex C/mex_outputs
copyfile USB_INIT_LIBUSB.o C/mex_outputs
delete USB_INIT_LIBUSB.mex
delete USB_INIT_LIBUSB.o
fprintf("\n\n\nCompiling USB_EXIT_LIBUSB...\n\n\n");
fflush(stdout);
mex C/USB_EXIT_LIBUSB.c -IC/build_linux/libusb -lusb-1.0 -Lbin\lib\x64
copyfile USB_EXIT_LIBUSB.mex C/mex_outputs
copyfile USB_EXIT_LIBUSB.o C/mex_outputs
delete USB_EXIT_LIBUSB.mex
delete USB_EXIT_LIBUSB.o
fprintf("\n\n\nCompiling USB_CONTROL_SEND_LIBUSB...\n\n\n");
fflush(stdout);
mex C/USB_CONTROL_SEND_LIBUSB.c -IC/build_linux/libusb -lusb-1.0 -Lbin\lib\x64
copyfile USB_CONTROL_SEND_LIBUSB.mex C/mex_outputs
copyfile USB_CONTROL_SEND_LIBUSB.o C/mex_outputs
delete USB_CONTROL_SEND_LIBUSB.mex
delete USB_CONTROL_SEND_LIBUSB.o
%mex USB_ISO_INIT.c -Iincludes -lusb-1.0
%mex USB_ISO_LOOP.c -Iincludes -lusb-1.0
%mex USB_POOL_FREE.c -Iincludes -lusb-1.0

View File

@ -0,0 +1,25 @@
clear all
clc
__addpaths;
[usb_handle, usb_context] = mex_usb_init("03eb", "ba94");
if(isequal(usb_handle, "0000000000000000"))
fprintf("Null USB Handle! Cancelling...\n");
return;
end
fprintf("\nTurning on the digital outputs...\n");
fflush(stdout);
labrador_set_digital_outputs(usb_handle, usb_context, 1,1,1,1);
pause(2)
fprintf("\nTurning off the digital outputs...\n");
fflush(stdout);
labrador_set_digital_outputs(usb_handle, usb_context, 0,0,0,0);
fprintf("\nExiting Libusb...\n");
fflush(stdout);
mex_usb_exit(usb_handle, usb_context);

View File

@ -0,0 +1,4 @@
addpath C
addpath C/mex_outputs
addpath mex_wrappers
addpath abstract_commands

View File

@ -0,0 +1,10 @@
function [] = labrador_set_digital_outputs(usb_handle, usb_context, port0, port1, port2, port3);
%labrador_set_digital_outputs(usb_handle, usb_context, 1,1,1,1);
digital_state = uint16(0);
if(port0 ~= 0) digital_state = digital_state + 1; end
if(port1 ~= 0) digital_state = digital_state + 2; end
if(port2 ~= 0) digital_state = digital_state + 4; end
if(port3 ~= 0) digital_state = digital_state + 8; end
mex_usb_send_control(usb_handle, usb_context, '40', 'a6', dec2hex(digital_state), '0', '0', []);

View File

@ -0,0 +1,3 @@
function [] = mex_usb_exit(handle, context)
USB_EXIT_LIBUSB(handle, context);

View File

@ -0,0 +1,3 @@
function [usb_context, usb_handle] = mex_usb_init(VID, PID)
[usb_handle, usb_context] = USB_INIT_LIBUSB(VID, PID);

View File

@ -0,0 +1,3 @@
function [USB_Control_IN_data] = mex_usb_send_control(usb_handle, usb_context, RequestType, Request, Value, Index, Length, LDATA)
[USB_Control_IN_data] = USB_CONTROL_SEND_LIBUSB(usb_handle, usb_context, RequestType, Request, Value, Index, Length, LDATA);

Binary file not shown.