コード例 #1
0
        private bool WriteCommandToOutputBuffer(OutCmd command)
        {
            byte[] outputBuffer = new byte[MyHid.Capabilities.OutputReportByteLength];

            outputBuffer[0] = 0;
            outputBuffer[1] = Convert.ToByte(command);
            outputBuffer[2] = 0;
            Write(ref outputBuffer);

            Hid.OutputReportViaInterruptTransfer outputReport = new Hid.OutputReportViaInterruptTransfer();
            return(outputReport.Write(outputBuffer, writeHandle));
        }
コード例 #2
0
        private void SendCommand(OutCmd command)
        {
            byte[] outputBuffer = new byte[MyHid.Capabilities.OutputReportByteLength];

            outputBuffer[0] = 0;
            outputBuffer[1] = Convert.ToByte(command);
            outputBuffer[2] = 0;
            Write(ref outputBuffer);

            if (command == OutCmd.FirmwareStart || command == OutCmd.TaylorTestStart || command == OutCmd.UserTestStart)
            {
                SetupRead();
            }
        }
コード例 #3
0
        //This method is used for the cases where a single response packet will be enough to contain the results, and we will not have to iterate through a large amount of data
        private string GetSinglePacketResponse(OutCmd outCommand)
        {
            try
            {
                ////build command to send buffer
                byte[] outputBuffer = new byte[MyHid.Capabilities.OutputReportByteLength];
                outputBuffer[0] = 0;
                outputBuffer[1] = Convert.ToByte(outCommand);//the value of the query firmware state
                outputBuffer[2] = 0;


                //Write command to buffer
                Hid.OutputReportViaInterruptTransfer outputReport = new Hid.OutputReportViaInterruptTransfer();
                if (!outputReport.Write(outputBuffer, writeHandle))
                {
                    //Failure writing to the report
                    throw new Exception();
                }


                //Read from the input report
                bool deviceConnected = true;
                bool success         = false;

                Hid.InputReportViaInterruptTransfer myInputReport = new Hid.InputReportViaInterruptTransfer();
                myInputReport.Read(hidHandle, readHandle, writeHandle, ref deviceConnected, ref inputBuffer, ref success);

                if (!success)
                {
                    //failure reading from the report
                    throw new Exception();
                }


                InputReportReceived(ref inputBuffer, success);
                newInputData = true;


                if (outCommand.Equals(OutCmd.SendFwVers) || outCommand.Equals(OutCmd.SendTestFileVers))
                {
                    //Both of these types of queries return the same type of packet, an encoded string
                    return(Encoding.GetEncoding("iso-8859-1").GetString(inputBuffer, 3, inputBuffer[2]));
                }

                if (outCommand.Equals(OutCmd.QueryFirmwareState))
                {
                    switch ((InCmd)inputBuffer[1])
                    {
                    case InCmd.BootloaderRunning:
                        return("BootloaderRunning");

                    case InCmd.MainFwRunning:
                        return("MainFwRunning");

                    default:
                        return("Unknown");
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(null);
        }
コード例 #4
0
        public void ReceiveFile(string fileName, OutCmd outCmd)
        {
            BinaryWriter outputFileWriter = null;

            try
            {
                // Open the output file and create an BinaryWriter object so we can write to it
                outputFileWriter = new BinaryWriter(File.Open(fileName, FileMode.OpenOrCreate, FileAccess.Write));

                // Request the file from the colorimeter
                WriteCommandToOutputBuffer(outCmd);

                // Wait for ACK
                newInputData = ReadInputBuffer();

                if ((InCmd)inputBuffer[1] == InCmd.ACK)
                {
                    byte checksum = 0;
                    bool done     = false;
                    while (!done)
                    {
                        // ACK received, now wait for test data

                        newInputData = false;
                        newInputData = ReadInputBuffer();

                        if (newInputData)
                        {
                            // Verify that the data we received is correct given outCmd
                            if ((outCmd == OutCmd.SendUserTests && inputBuffer[1] == (byte)InCmd.TestData) ||
                                (outCmd == OutCmd.SendTestResults && inputBuffer[1] == (byte)InCmd.ResultsData))
                            {
                                // Update our checksum
                                for (int i = 0; i < inputBuffer[2]; i++)
                                {
                                    checksum ^= inputBuffer[3 + i];
                                }

                                // If input report received successfully, write data
                                outputFileWriter.Write(inputBuffer, 3, inputBuffer[2]);

                                WriteCommandToOutputBuffer(OutCmd.ACK);
                            }
                            else if (inputBuffer[1] == (byte)InCmd.DataSendComplete)
                            {
                                done = true;
                                if (checksum == inputBuffer[3])
                                {
                                    WriteCommandToOutputBuffer(OutCmd.ACK);
                                }
                                else
                                {
                                    WriteCommandToOutputBuffer(OutCmd.NAK);
                                }
                            }
                            else
                            {
                                WriteCommandToOutputBuffer(OutCmd.NAK);
                                done = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            finally
            {
                if (outputFileWriter != null)
                {
                    outputFileWriter.Close();
                }
            }
        }
コード例 #5
0
 public byte[] GenerateMessage(OutCmd cmd, object data)
 {
     throw new NotImplementedException();
 }