Exemple #1
0
        //---#+************************************************************************
        //---NOTATION:
        //-  bool writeData(char[] cDataToWrite)
        //-
        //--- DESCRIPTION:
        //--  writes data to the device and returns true if no error occured
        //                                                             Autor:      F.L.
        //-*************************************************************************+#*
        /// <summary>
        /// Writes the data.
        /// </summary>
        /// <param name="bDataToWrite">The b data to write.</param>
        /// <returns></returns>
        public bool writeData(byte[] bDataToWrite)
        {
            bool success = false;

            if (getConnectionState())
            {
                try
                {
                    //get output report length
                    int myPtrToPreparsedData = -1;

                    // myUSB.CT_HidD_GetPreparsedData(myUSB.HidHandle, ref myPtrToPreparsedData);
                    // int code = myUSB.CT_HidP_GetCaps(myPtrToPreparsedData);

                    int outputReportByteLength = 65;

                    int bytesSend = 0;

                    //if bWriteData is bigger then one report diveide into sevral reports
                    while (bytesSend < bDataToWrite.Length)
                    {
                        // Set the size of the Output report buffer.
                        // byte[] OutputReportBuffer = new byte[myUSB.myHIDP_CAPS.OutputReportByteLength - 1 + 1];
                        byte[] OutputReportBuffer = new byte[outputReportByteLength - 1 + 1];

                        // Store the report ID in the first byte of the buffer:
                        OutputReportBuffer[0] = 0;

                        // Store the report data following the report ID.
                        for (int i = 1; i < OutputReportBuffer.Length; i++)
                        {
                            if (bytesSend < bDataToWrite.Length)
                            {
                                OutputReportBuffer[i] = bDataToWrite[bytesSend];
                                bytesSend++;
                            }
                            else
                            {
                                OutputReportBuffer[i] = 0;
                            }
                        }

                        OutputReport myOutputReport = new OutputReport();
                        success = myOutputReport.Write(OutputReportBuffer, myUSB.HidHandle);
                    }
                }
                catch (AccessViolationException)
                {
                    success = false;
                }
            }
            else
            {
                success = false;
            }
            return(success);
        }
Exemple #2
0
        public bool writeDataSimple(byte[] bDataToWrite)
        {
            var success = false;

            if (getConnectionState())
            {
                try
                {
                    var myOutputReport = new OutputReport();
                    success = myOutputReport.Write(bDataToWrite, myUSB.HidHandle);
                }
                catch (AccessViolationException ex)
                {
                    success = false;
                }
            }
            return(success);
        }
Exemple #3
0
        /// <summary>
        /// Writes data.
        /// </summary>
        /// <param name="data">The data to write.</param>
        /// <returns></returns>
        internal bool WriteData(byte[] data)
        {
            bool bSuccess = false;

            if (IsConnected)
            {
                // Set the size of the Output report buffer.
                byte[] outputReportBuffer = new byte[HIDReportLength];
                Array.Clear(outputReportBuffer, 0, outputReportBuffer.Length);

                // Store the report data following the report ID.
                Array.ConstrainedCopy(data, 0, outputReportBuffer, 1, outputReportBuffer.Length);

                OutputReport report = new OutputReport();
                bSuccess = report.Write(outputReportBuffer, _core._hHid);
            }
            else
            {
                bSuccess = false;
            }
            return(bSuccess);
        }
        //---#+************************************************************************
        //---NOTATION:
        //-  bool writeData(char[] cDataToWrite)
        //-
        //--- DESCRIPTION:
        //--  writes data to the device and returns true if no error occured
        //                                                             Autor:      F.L.
        //-*************************************************************************+#*
        /// <summary>
        /// Writes the data.
        /// </summary>
        /// <param name="bDataToWrite">The b data to write.</param>
        /// <returns></returns>
        public bool writeData(byte[] bDataToWrite)
        {
            bool success = false;
            if (getConnectionState())
            {
                try
                {
                    //get output report length
                    //int myPtrToPreparsedData = -1;
                    // myUSB.CT_HidD_GetPreparsedData(myUSB.HidHandle, ref myPtrToPreparsedData);
                    // int code = myUSB.CT_HidP_GetCaps(myPtrToPreparsedData);

                    int outputReportByteLength = 65;

                    int bytesSend = 0;
                    //if bWriteData is bigger then one report diveide into sevral reports
                    while (bytesSend < bDataToWrite.Length)
                    {

                        // Set the size of the Output report buffer.
                        // byte[] OutputReportBuffer = new byte[myUSB.myHIDP_CAPS.OutputReportByteLength - 1 + 1];
                        byte[] OutputReportBuffer = new byte[outputReportByteLength - 1 + 1];
                        // Store the report ID in the first byte of the buffer:
                        OutputReportBuffer[0] = 0;

                        // Store the report data following the report ID.
                        for (int i = 1; i < OutputReportBuffer.Length; i++)
                        {
                            if (bytesSend < bDataToWrite.Length)
                            {
                                OutputReportBuffer[i] = bDataToWrite[bytesSend];
                                bytesSend++;
                            }
                            else
                            {
                                OutputReportBuffer[i] = 0;
                            }
                        }

                        OutputReport myOutputReport = new OutputReport();
                        success = myOutputReport.Write(OutputReportBuffer, myUSB.HidHandle);
                    }
                }
                //catch (System.AccessViolationException ex)
                catch
                {
                    success = false;
                }
            }
            else
            {
                success = false;
            }
            return success;
        }
Exemple #5
0
 public bool writeDataSimple(byte[] bDataToWrite)
 {
     var success = false;
     if (getConnectionState())
     {
         try
         {
             var myOutputReport = new OutputReport();
             success = myOutputReport.Write(bDataToWrite, myUSB.HidHandle);
         }
         catch (AccessViolationException ex)
         {
             success = false;
         }
     }
     return success;
 }
        /// <summary>
        /// Writes data.
        /// </summary>
        /// <param name="data">The data to write.</param>
        /// <returns></returns>
        internal bool WriteData(byte[] data)
        {
            bool bSuccess = false;

             if (IsConnected)
             {
            // Set the size of the Output report buffer.
            byte[] outputReportBuffer = new byte[HIDReportLength];
            Array.Clear(outputReportBuffer, 0, outputReportBuffer.Length);

            // Store the report data following the report ID.
            Array.ConstrainedCopy(data, 0, outputReportBuffer, 1, outputReportBuffer.Length);

            OutputReport report = new OutputReport();
            bSuccess = report.Write(outputReportBuffer, _core._hHid);
             }
             else
             {
            bSuccess = false;
             }
             return bSuccess;
        }