Пример #1
0
        public void ServoSweepParams(int servoNumber, double sweepMin, double sweepMax, double sweepStartPos, double sweepStep, bool initialDirectionUp, double sweepRate)
        {
            try
            {
                Tracer.Trace("PM Command::ServoSweepParams(" + servoNumber + "," + sweepMin + "," + sweepMax + "," + sweepStep + "," + sweepRate + ")");

                sweepMin = ProximityBoard.toWithinServoRangeMks(sweepMin);        // cut it to the allowed limits
                sweepMax = ProximityBoard.toWithinServoRangeMks(sweepMax);

                if (!myDeviceDetected)
                {
                    myDeviceDetected = FindTheHid(vendorId, productId);
                }

                if (myDeviceDetected)
                {
                    //  Set the size of the Output report buffer.

                    byte[] outputReportBuffer = new byte[MyHid.Capabilities.OutputReportByteLength];

                    //  Store the report ID (command) in the first byte of the buffer:

                    outputReportBuffer[0] = OUTPUT_REPORT_ID;                             // will turn out on the board as Output Report ID

                    outputReportBuffer[1] = (byte)ProximityBoardCommand.ServoSweepParams; // will be analyzed in a switch

                    outputReportBuffer[2] = (byte)servoNumber;                            // which servo

                    int iSweepMin   = ProximityBoard.mksToServoTarget(sweepMin);
                    int iSweepMax   = ProximityBoard.mksToServoTarget(sweepMax);
                    int iSweepStart = ProximityBoard.mksToServoTarget(sweepStartPos);
                    int iSweepStep  = (int)sweepStep;
                    int iSweepRate  = (int)sweepRate;

                    intToBuffer(outputReportBuffer, 3, (UInt16)iSweepMin);
                    intToBuffer(outputReportBuffer, 5, (UInt16)iSweepMax);
                    intToBuffer(outputReportBuffer, 7, (UInt16)iSweepStart);
                    intToBuffer(outputReportBuffer, 9, (UInt16)iSweepStep);
                    intToBuffer(outputReportBuffer, 11, (UInt16)iSweepRate);
                    outputReportBuffer[13] = (byte)(initialDirectionUp ? 1 : -1);

                    ReadAndWriteToDevice(outputReportBuffer, INPUT_REPORT_ID);
                    //WriteToDevice(outputReportBuffer);
                }
                else
                {
                    Tracer.Error("FindTheHid() unsuccessful, skipped the ServoSweepParams command");
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex);
                throw;
            }
        }
Пример #2
0
        public void ServoPositionSet(int servoNumber, double dPosMks)
        {
            try
            {
                Tracer.Trace("PM Command::ServoPositionSet(" + servoNumber + "," + dPosMks + ")");

                dPosMks = ProximityBoard.toWithinServoRangeMks(dPosMks);        // cut it to the allowed limits

                if (!myDeviceDetected)
                {
                    myDeviceDetected = FindTheHid(vendorId, productId);
                }

                if (myDeviceDetected)
                {
                    //  Set the size of the Output report buffer.

                    byte[] outputReportBuffer = new byte[MyHid.Capabilities.OutputReportByteLength];

                    //  Store the report ID (command) in the first byte of the buffer:

                    outputReportBuffer[0] = OUTPUT_REPORT_ID;                             // will turn out on the board as Output Report ID

                    outputReportBuffer[1] = (byte)ProximityBoardCommand.ServoPositionSet; // will be analyzed in a switch

                    outputReportBuffer[2] = (byte)servoNumber;                            // which servo

                    int servotarget = ProximityBoard.mksToServoTarget(dPosMks);

                    // data bytes 0 and 1 of the Output Report - hid_report_out[]:
                    intToBuffer(outputReportBuffer, 3, (UInt16)servotarget);

                    ReadAndWriteToDevice(outputReportBuffer, INPUT_REPORT_ID);
                    //WriteToDevice(outputReportBuffer);
                }
                else
                {
                    Tracer.Error("FindTheHid() unsuccessful, skipped the ServoPositionSet command");
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex);
                throw;
            }
        }