Bonjour.
Je suis en terminale S.I et j'ai naturelement un PPE a faire.
Pour notre PPE mes collegues et moi devons faire un programme qui transfert des données (Tension, heure et déplacement) présentes dans un PIC et les afficher dans un graphique.
Pour cela nous avons utiliser un programme deja existant et nous l'avons grandement modifié cependant nous faisons face a un dernier probleme a regler: on ne recoit que 64 valeur a la fois alors qu'il faudrait qu'on en recoit beaucoup plus.
Il faudrait donc lancer plusieur reception a la suite pour que la courbe soit complete.
voila la partie du code qui pose probleme et le soucis c'est qu'il faudrait envoyer 16 paquet de 64 au lieu d'un.Code:private static FileStream fileStreamDeviceData; private Boolean FindTheHid() { Boolean deviceFound = false; String[] devicePathName = new String[128]; String functionName = ""; Guid hidGuid = Guid.Empty; Int32 memberIndex = 0; Int32 myProductID = Int32.Parse("1234", NumberStyles.AllowHexSpecifier); Int32 myVendorID = Int32.Parse("1234", NumberStyles.AllowHexSpecifier); Boolean success = false; try { myDeviceDetected = false; CloseCommunications(); Hid.HidD_GetHidGuid(ref hidGuid); functionName = "GetHidGuid"; deviceFound = MyDeviceManagement.FindDeviceFromGuid(hidGuid, ref devicePathName); if (deviceFound) { memberIndex = 0; do { hidHandle = FileIO.CreateFile(devicePathName[memberIndex], 0, FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE, IntPtr.Zero, FileIO.OPEN_EXISTING, 0, 0); functionName = "CreateFile"; if (!hidHandle.IsInvalid) { MyHid.DeviceAttributes.Size = MyHid.Capabilities.InputReportByteLength; success = Hid.HidD_GetAttributes(hidHandle, ref MyHid.DeviceAttributes); if (success) { if ((MyHid.DeviceAttributes.VendorID == myVendorID) && (MyHid.DeviceAttributes.ProductID == myProductID)) { myDeviceDetected = true; myDevicePathName = devicePathName[memberIndex]; } else { myDeviceDetected = false; hidHandle.Close(); } } else { myDeviceDetected = false; hidHandle.Close(); } } // Keep looking until we find the device or there are no devices left to examine. memberIndex = memberIndex + 1; } while (!((myDeviceDetected || (memberIndex == devicePathName.Length)))); } if (myDeviceDetected) { success = MyDeviceManagement.RegisterForDeviceNotifications(myDevicePathName, FrmMy.Handle, hidGuid, ref deviceNotificationHandle); MyHid.Capabilities = MyHid.GetDeviceCapabilities(hidHandle); if (success) { hidUsage = MyHid.GetHidUsage(MyHid.Capabilities); GetInputReportBufferSize(); hidHandle.Close(); hidHandle = FileIO.CreateFile(myDevicePathName, FileIO.GENERIC_READ | FileIO.GENERIC_WRITE, FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE, IntPtr.Zero, FileIO.OPEN_EXISTING, 0, 0); if (hidHandle.IsInvalid) { exclusiveAccess = true; } else { if (MyHid.Capabilities.InputReportByteLength > 0) { Byte[] inputReportBuffer = null; inputReportBuffer = new Byte[MyHid.Capabilities.InputReportByteLength]; fileStreamDeviceData = new FileStream(hidHandle, FileAccess.Read | FileAccess.Write, MyHid.Capabilities.InputReportByteLength, false); } if (MyHid.Capabilities.InputReportByteLength > 0) { Byte[] outputReportBuffer = null; outputReportBuffer = new Byte[MyHid.Capabilities.InputReportByteLength]; } // Flush any waiting reports in the input buffer. (optional) MyHid.FlushQueue(hidHandle); } } } return myDeviceDetected; } catch (Exception ex) { DisplayException(this.Name, ex); throw; } } private void GetInputReportData(IAsyncResult ar) { String byteValue = null; Int32 count = 0; Byte[] inputReportBuffer = new Byte[MyHid.Capabilities.InputReportByteLength]; try { inputReportBuffer = (byte[])ar.AsyncState; fileStreamDeviceData.EndRead(ar); int Colon = 1; if ((ar.IsCompleted)) { for (count = 1; count < MyHid.Capabilities.InputReportByteLength; count++) { byteValue = String.Format("{0} ", inputReportBuffer[count]); MyMarshalToForm("TextBoxSelectionStart", txtBytesReceived.Text); if (count == 75 * Colon) { Colon++; MyMarshalToForm("AddItemToTextBoxS", byteValue); } else { MyMarshalToForm("AddItemToTextBoxN", byteValue); } } } else { MyMarshalToForm("AddItemToListBox", "The attempt to read an Input report has failed."); } MyMarshalToForm("EnableCmdOnce", ""); } catch (Exception ex) { DisplayException(this.Name, ex); throw; } } public void ExchangeInputAndOutputReports() { Byte[] inputReportBuffer = null; Byte[] outputReportBuffer = null; Boolean success = false; try { success = false; if (!hidHandle.IsInvalid) { if (MyHid.Capabilities.InputReportByteLength > 0) { outputReportBuffer = new Byte[MyHid.Capabilities.OutputReportByteLength]; outputReportBuffer[0] = 0; outputReportBuffer[1] = Convert.ToByte(MyHid.DeviceAttributes.Init_Type); if (fileStreamDeviceData.CanWrite) { fileStreamDeviceData.Write(outputReportBuffer, 0, MyHid.Capabilities.OutputReportByteLength); success = true; } if (!success) { CloseCommunications(); } inputReportBuffer = new Byte[MyHid.Capabilities.InputReportByteLength]; success = MyHid.GetInputReportViaControlTransfer(hidHandle, ref inputReportBuffer); if (!success) { if (fileStreamDeviceData.CanRead) { fileStreamDeviceData.BeginRead(inputReportBuffer, 0, MyHid.Capabilities.InputReportByteLength, new AsyncCallback(GetInputReportData), inputReportBuffer); } else { CloseCommunications(); } } } else { AccessForm("EnableCmdOnce", ""); } } catch (Exception ex) { DisplayException(this.Name, ex); throw; } }
Donc si vous arrivez a reperer ce qui cloche merci d'avance.
Si vous voulez plus de renseignements demandé moi et je vous les posterai.
-----