bonjour tlm,
c'est mon premier poste dans ce forum :-)
j'ai commencé récemment un projet en C# (sachant que je suis débutant) sur l'utilisation d"un interface FTDI (Atmel) USB<==>Rj45.......
j'arrive pas à écrire ou à lire quoi que ce soit et je n'ai pu déterminé où ça cloche dans mon code, pourtant je peux lister les Device connecté à mon PC, tirer leurs descriptions, ID, Serial number..etc, de même pour les caractéristiques de connexion (Baud rate, data characteritics, CTS/RTS, Dtr, timeout) mais au moment où j'essaie d'écrire quoi que ce soit l'interface ne réagit pas.... !!
voici mon code d'écriture/lecture:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 string[] DTW ={"0x3f","0x54"} ; UInt32 numBytesWritten = 0; for (int i = 0; i <=1; i++) { ftStatus = Device.Write(DTW[i], DTW[i].Length, ref numBytesWritten); if (ftStatus != FTDI.FT_STATUS.FT_OK) { richTextBox1.Clear(); richTextBox1.SelectedText = " Failed to Write"; BConnect.Text = "Connect"; BConnect.Enabled = false; comboBox1.Enabled = true; return; } uint RxQ=0; ftStatus = Device.GetRxBytesAvailable(ref RxQ); if (ftStatus != FTDI.FT_STATUS.FT_OK) { richTextBox1.Clear(); richTextBox1.SelectedText = " Failed to Get RxQ"; BConnect.Text = "Connect"; BConnect.Enabled = false; comboBox1.Enabled = true; return; } if (RxQ != 0) { do { Thread.Sleep(100); } while (RxQ < DTW[i].Length); string[] readData={""}; UInt32 numBytesRead = 0; ftStatus = Device.Read(out readData[i], RxQ, ref numBytesRead); richTextBox1.SelectedText += readData[i].ToString(); if (ftStatus != FTDI.FT_STATUS.FT_OK) { richTextBox1.Clear(); richTextBox1.SelectedText = " Failed to set Dtr"; BConnect.Text = "Connect"; BConnect.Enabled = false; comboBox1.Enabled = true; return; } else { richTextBox1.SelectionColor = Color.Beige; richTextBox1.SelectedText += i+" " + DTW[i].ToString() + " " + RxQ.ToString() + " Device Note response"; return; } } }
Partager