Bonjour a tous,

je developpe une appli sous Win CE et je dois récupérer les coordonnées fournies par le GPS intégré. le seul exemple de code fournit est en c++ (voir ci dessous). Dans mon projet C#, j'ai essayé d'utiliser l'élément serial port avec les propriétés suivantes:
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
 
 generateMember = true
Modifiers = private
baudRate = 9600
DiscardNull=false
dtrEnable = true
Handshake = none
parityReplace = 63
portName = Com1: (j'ai aussi essayé COM1 et COM6)
readBufferSize = 4096
readTimeout=-1
receivedBytresThresold = 1
rtsEnable = true
stopBits = One
writebufferSize=2048
WriteTimeout = 1000
Malheureusement, cela ne fonctionne pas, j'ai toujours une erreur System.IOEXCEPTION. J'ai alors essayé d'utiliser le code fournit sur la page suivante: http://www.pinvoke.net/default.aspx/Structures/DCB.html

mais même erreur. J'ai copié collé le code c++ visible ci dessous dans le projet C# ainsi que le code du site pinvoke.

Si quelqu'un sait ou peut me donner une solution quelle qu'elle soit pour venir a bout de ce pb, je lui en serait très reconnaissant. Merci

code c++:
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
DCB PortDCB;
 
// Initialize the DCBlength member. 
PortDCB.DCBlength = sizeof (DCB); 
 
// Change the DCB structure settings.
PortDCB.BaudRate = 9600;              // Current baud 
PortDCB.fBinary = TRUE;               // Binary mode; no EOF check 
PortDCB.fParity = TRUE;               // Enable parity checking 
PortDCB.fOutxCtsFlow = FALSE;         // No CTS output flow control 
PortDCB.fOutxDsrFlow = FALSE;         // No DSR output flow control 
PortDCB.fDtrControl = DTR_CONTROL_ENABLE; 
// DTR flow control type 
PortDCB.fDsrSensitivity = FALSE;      // DSR sensitivity 
PortDCB.fTXContinueOnXoff = TRUE;     // XOFF continues Tx 
PortDCB.fOutX = FALSE;                // No XON/XOFF out flow control 
PortDCB.fInX = FALSE;                 // No XON/XOFF in flow control 
PortDCB.fErrorChar = FALSE;           // Disable error replacement 
PortDCB.fNull = FALSE;                // Disable null stripping 
PortDCB.fRtsControl = RTS_CONTROL_ENABLE; 
// RTS flow control 
PortDCB.fAbortOnError = FALSE;        // Do not abort reads/writes on 
// error
PortDCB.ByteSize = 8;                 // Number of bits/byte, 4-8 
PortDCB.Parity = NOPARITY;            // 0-4=no,odd,even,mark,space 
PortDCB.StopBits = ONESTOPBIT;        // 0,1,2 = 1, 1.5, 2 
 
// Retrieve the time-out parameters for all read and write operations
// on the port. 
COMMTIMEOUTS CommTimeouts;
//GetCommTimeouts (m_hPort1, &CommTimeouts);
 
// Change the COMMTIMEOUTS structure settings.
CommTimeouts.ReadIntervalTimeout = MAXDWORD;  
CommTimeouts.ReadTotalTimeoutMultiplier = 0;  
CommTimeouts.ReadTotalTimeoutConstant = 0;    
CommTimeouts.WriteTotalTimeoutMultiplier = 10;  
CommTimeouts.WriteTotalTimeoutConstant = 1000;  
 
//COM Init
// Open the serial port.
m_hPort1 = CreateFile (TEXT("Com1:"), // Pointer to the name of the port
					   GENERIC_READ | GENERIC_WRITE, // Access (read-write) mode
					   0,            // Share mode
					   NULL,         // Pointer to the security attribute
					   OPEN_EXISTING,// How to open the serial port
					   0,            // Port attributes
					   NULL);        // Handle to port with attribute to copy
// Configure the port according to the specifications of the DCB structure.
if (!SetCommState (m_hPort1, &PortDCB))
{
	// Could not configure the serial port.
	MessageBox(TEXT("Unable to configure the serial port"), TEXT("Error"), MB_OK);
	return FALSE;
} 
// Set the time-out parameters for all read and write operations on the port. 
if (!SetCommTimeouts (m_hPort1, &CommTimeouts))
{
	// Could not set the time-out parameters.
	MessageBox(TEXT("Unable to set the time-out parameters"), TEXT("Error"), MB_OK);
	return FALSE;
}