|
|
|
date: Thu, 22 Dec 2005 22:37:01 -0800,
group: microsoft.public.win32.programmer.directx.networking
back
Using kernel32.dll for serial port connection
Hi everybody,
I am new in creating serial port connection. How do you create a serial
port connection using this following api functions? I will use this serail
port connection to communicate with a gprs modem operating in Widnows XP
Embedded. Can you provide some simple codes, the serial port is fixed. I used
C# and VB.Net.
[DllImport("kernel32.dll")]
private static extern Boolean GetCommProperties(IntPtr hFile, out COMMPROP
cp);
[DllImport("kernel32.dll")]
private static extern Boolean GetCommModemStatus(IntPtr hFile, out UInt32
lpModemStat);
[DllImport("kernel32.dll")]
private static extern Boolean GetCommState(IntPtr hFile, ref DCB lpDCB);
[DllImport("kernel32.dll")]
private static extern Boolean SetCommState(IntPtr hFile, [In] ref DCB lpDCB);
[DllImport("kernel32.dll", SetLastError=true)]
private static extern IntPtr CreateFile(String lpFileName, UInt32
dwDesiredAccess, UInt32 dwShareMode, IntPtr lpSecurityAttributes, UInt32
dwCreationDisposition, UInt32 dwFlagsAndAttributes, IntPtr hTemplateFile);
[DllImport("kernel32.dll")]
private static extern Boolean CloseHandle(IntPtr hObject);
[DllImport("kernel32.dll", SetLastError=true)]
private static extern Boolean ReadFile(IntPtr hFile, [Out] Byte[] lpBuffer,
UInt32 nNumberOfBytesToRead, out UInt32 nNumberOfBytesRead, IntPtr
lpOverlapped);
[DllImport("kernel32.dll", SetLastError=true)]
private static extern Boolean WriteFile(IntPtr fFile, Byte[] lpBuffer,
UInt32 nNumberOfBytesToWrite, out UInt32 lpNumberOfBytesWritten, IntPtr
lpOverlapped);
[DllImport("kernel32.dll")]
private static extern Boolean CancelIo(IntPtr hFile);
[DllImport("kernel32.dll")]
private static extern Boolean TransmitCommChar(IntPtr hFile, Byte cChar);
[DllImport("kernel32.dll")]
internal static extern Boolean SetupComm(IntPtr hFile, UInt32 dwInQueue,
UInt32 dwOutQueue);
den2005
--
MCP Year 2005, Philippines
date: Thu, 22 Dec 2005 22:37:01 -0800
author: den 2005
|
|