using MSCOMM


  • I do have a vb form that has three optionbuttons 1,2,and 3.If any of these otion is selected a signal should be sent to a serial port pin.


    can you please show me how MSCOMM is used to implement this.


    thanks in advance

    Thursday, October 18, 2007 2:07 AM


  • ControlChip,


    According to your question on using MSCOMM to send signal to serial prot, I would like to provide you the example as follows:


    1. Please add reference in your project for Microsoft Comm Control 6.0. In order To use the MSComm control, you must install the related COM components of Microsoft Visual Basic 6.0 on the same computer that has Microsoft Visual Studio .NET installed.


    Code Block

    Imports MSCommLib


    Module Module1


        Sub Main()

            'New a MSComm control

            Dim MSComm1 As MSComm

            MSComm1 = New MSComm

            ' Buffer to hold input string.

            Dim Buffer As String

            ' Use the COM1 serial port.

            MSComm1.CommPort = 1

            ' 9600 baud, no parity, 8 data, and 1 stop bit.

            MSComm1.Settings = "9600,N,8,1"

            ' Tell the control to read the whole buffer when Input is used.

            MSComm1.InputLen = 0

            ' Open the serial port.

            MSComm1.PortOpen = True

            Console.WriteLine("Open the serial port.")

            ' Tell the control to make the Input property return text data.

            MSComm1.InputMode() = InputModeConstants.comInputModeText

            'Clear the receive buffer.

            MSComm1.InBufferCount() = 0

            ' Send the attention command to the modem.

            MSComm1.Output = "ATV1Q0" & Chr(13)

            Console.WriteLine("Send the attention command to the modem.")

            Console.WriteLine("Wait for the data to come back to the serial port...")

            ' Make sure that the modem responds with "OK".

            ' Wait for the data to come back to the serial port.


                Buffer = Buffer & MSComm1.Input

            Loop Until InStr(Buffer, "OK" & vbCrLf)

            ' Read the "OK" response data in the serial port.

            ' Close the serial port.

            Console.WriteLine("Read the OK response data in the serial port.")

            MSComm1.PortOpen = False

            Console.WriteLine("Close the serial port.")

        End Sub


    End Module



    2. The following article and thread in MSDN can provide you further help on this kind of problems:


    Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications


    Mscomm, Serial ports and bit manipulation


    Hope that can help you.

    Monday, October 22, 2007 5:40 AM