Create a serial port connection to a modem

Hi everybody,
  I am new in creating serial port connection, this application will connect to a gprs modem using api functions like shown below, but does not know how to used them, Can anyone show me how exactly to use them and values to enter to be able to create a serial port connection with this modem Please show actual codes. I am using C#.

   I like to create a serial port connection where the modem will be attcehd and be able to commuincate with this modem. The data values will be coming from a file.

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



Answer this question

Create a serial port connection to a modem

  • sticky

    Hi John,

       I know there is one in Ver2.0 but I am using ver 1.1, and is not possible at moment to get VS 2005 (.Net Framework 2.0). Thanks for reply.

     

    den2005

     


  • albert tan

    I believe you will probably have to search the web for a third party implementation.

  • J Kramer

    There is a new namespace in v2.0 of the .NET framework that appears to have support for serial ports.  See msdn for the class System.IO.Ports.SerialPort

  • Create a serial port connection to a modem