Click here to Skip to main content
15,915,172 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to get message from Queue? Pin
Rashid.Mahmood13-Dec-05 18:33
Rashid.Mahmood13-Dec-05 18:33 
GeneralWebBrowser and Console Applications Pin
S. Senthil Kumar13-Dec-05 4:32
S. Senthil Kumar13-Dec-05 4:32 
GeneralRe: WebBrowser and Console Applications Pin
Judah Gabriel Himango13-Dec-05 4:43
sponsorJudah Gabriel Himango13-Dec-05 4:43 
GeneralRe: WebBrowser and Console Applications Pin
S. Senthil Kumar15-Dec-05 5:01
S. Senthil Kumar15-Dec-05 5:01 
GeneralRe: WebBrowser and Console Applications Pin
Judah Gabriel Himango15-Dec-05 5:22
sponsorJudah Gabriel Himango15-Dec-05 5:22 
GeneralRe: WebBrowser and Console Applications Pin
Dave Kreskowiak13-Dec-05 6:50
mveDave Kreskowiak13-Dec-05 6:50 
GeneralRe: WebBrowser and Console Applications Pin
S. Senthil Kumar15-Dec-05 5:01
S. Senthil Kumar15-Dec-05 5:01 
QuestionWin32 CommTimeouts Pin
goldoche13-Dec-05 4:31
goldoche13-Dec-05 4:31 
Hi, I have a problem with the functions SetCommTimeouts and GetCommTimeouts of the Win32 API.

First of all, I want to make a synchronous read on a USB device with a timeout of 250 ms, that is, the ReadFiule function returns after 250 ms if no data is received.

This is the COMMTIMEOUTS Structure

<code>
[StructLayout(LayoutKind.Sequential)]
public struct COMMTIMEOUTS
{
public int ReadIntervalTimeout;
public int ReadTotalTimeoutMultiplier;
public int ReadTotalTimeoutConstant;
public int WriteTotalTimeoutMultiplier;
public int WriteTotalTimeoutConstant;
}
</code>

These are the 2 functions: GetCommTimeouts and SetCommTimeouts

<code>
[DllImport("kernel32.dll")]
public static extern bool GetCommTimeouts(IntPtr hFile, out COMMTIMEOUTS lpCommTimeouts);

[DllImport("kernel32.dll")]
public static extern bool SetCommTimeouts(IntPtr hFile, ref COMMTIMEOUTS lpCommTimeouts);
</code>

And finally, here is how I try to adjust the timeouts

<code>
FileIO.COMMTIMEOUTS timeouts;

// Create handle
hidHandle = unchecked( FileIO.CreateFile(path,
(uint)(FileIO.GENERIC_READ | FileIO.GENERIC_WRITE),
FileIO.FILE_SHARE_READ | FileIO.FILE_SHARE_WRITE,
ref security,
FileIO.OPEN_EXISTING,
0,
IntPtr.Zero));

if(hidHandle == FileIO.INVALID_HANDLE_VALUE)
{
success = false;
}
else
{
// Read timeouts
if(FileIO.GetCommTimeouts(hidHandle, out timeouts))
{
timeouts.ReadIntervalTimeout = 0;
timeouts.ReadTotalTimeoutConstant = 0;
timeouts.ReadTotalTimeoutMultiplier = 0;
timeouts.WriteTotalTimeoutConstant = 0;
timeouts.WriteTotalTimeoutMultiplier = 0;

// Set them
if(FileIO.SetCommTimeouts(hidHandle, ref timeouts))
{
// I READ THEM AGAIN AND THEY HAVE NOT CHANGED!!!
FileIO.GetCommTimeouts(hidHandle, out timeouts);
success = true;
}
}
else
{
int lastError = FileIO.GetLastError();
}
}
</code>

I create a handle successfully, I call GetCommTimeouts, it returns true, I modify the timeouts and apply them by calling SetCommTimeouts, it returns true. But then, when I call GetCommTimeouts again, the timeouts are just like before! They haven't changed!

Where's my mistake?

Thank you!
Questionapp.config Pin
fmardani13-Dec-05 4:11
fmardani13-Dec-05 4:11 
AnswerRe: app.config Pin
Curtis Schlak.13-Dec-05 4:18
Curtis Schlak.13-Dec-05 4:18 
GeneralRe: app.config Pin
fmardani13-Dec-05 4:22
fmardani13-Dec-05 4:22 
GeneralRe: app.config Pin
Curtis Schlak.13-Dec-05 4:30
Curtis Schlak.13-Dec-05 4:30 
GeneralRe: app.config Pin
fmardani13-Dec-05 4:31
fmardani13-Dec-05 4:31 
GeneralRe: app.config Pin
Curtis Schlak.13-Dec-05 4:42
Curtis Schlak.13-Dec-05 4:42 
GeneralRe: app.config Pin
fmardani13-Dec-05 4:47
fmardani13-Dec-05 4:47 
GeneralRe: app.config Pin
Curtis Schlak.13-Dec-05 4:52
Curtis Schlak.13-Dec-05 4:52 
GeneralRe: app.config Pin
fmardani13-Dec-05 4:53
fmardani13-Dec-05 4:53 
GeneralRe: app.config Pin
Curtis Schlak.13-Dec-05 4:59
Curtis Schlak.13-Dec-05 4:59 
GeneralRe: app.config Pin
fmardani13-Dec-05 5:01
fmardani13-Dec-05 5:01 
GeneralRe: app.config Pin
Curtis Schlak.13-Dec-05 5:27
Curtis Schlak.13-Dec-05 5:27 
GeneralRe: app.config Pin
fmardani13-Dec-05 5:32
fmardani13-Dec-05 5:32 
GeneralRe: app.config Pin
Curtis Schlak.13-Dec-05 5:36
Curtis Schlak.13-Dec-05 5:36 
GeneralRe: app.config Pin
fmardani13-Dec-05 5:37
fmardani13-Dec-05 5:37 
GeneralRe: app.config Pin
Curtis Schlak.13-Dec-05 5:40
Curtis Schlak.13-Dec-05 5:40 
GeneralRe: app.config Pin
fmardani13-Dec-05 5:57
fmardani13-Dec-05 5:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.