G
Guest
Hi everybody,
I am new in serial port connection. How do you create and established a
serial port communication with a gprs modem (via a serail port)? I found
these api functions. How they are used? please show codes how to use them.
Thanks.
[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
I am new in serial port connection. How do you create and established a
serial port communication with a gprs modem (via a serail port)? I found
these api functions. How they are used? please show codes how to use them.
Thanks.
[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