locked
How Do I send a Start bit, then Bytes then Stop Bit to an RS232 Port

    Question

  • I am a Windows fanatic. I am an Electronic Engineering Student developing an automatic open and close gate system. I am using RFID. I am OK with the decoding of RFID tags, Database e.t.c at the moment.

    May you help me with how I can send some characters using VB to a serial port (Connected to a PIC). I developed the below code. Will it work? I haven't programmed the PIC yet so I can't do the test. Then the other most important thing is that before I send the bytes I want to send a start bit and after the bytes I want to send a stop bit. How can I do that.

    The Code Sample

    1. Dim WithEvents msComm0 As New SerialPort()
       2. 
       3. With msComm0
       4.             .PortName = "COM1"
       5.             .BaudRate = 9600
       6.             .DataBits = 8
       7.             .StopBits = StopBits.One
       8.             .Parity = Parity.None
       9.             .Handshake = Handshake.None
      10.             .ReadTimeout = 1000
      11.             .WriteTimeout = 1000
      12. End With
      13. 
      14. msComm0.Open()
      15. Dim mssg As Byte() = New Byte(3) {}
      16.
      17. mssg(0) = &H4F  ' for "O"  ;;for opening gate by PC
      18. mssg(1) = &H44   ' for "D"  ;;for a 30s Delay,,I know I can do it in PIC,,just 4 demo
      19. mssg(2) = &H43  ' for "C"  ;;;for Closing Gate by PIC
      20.
      21. msComm0.Write(mssg, 0, 2)

    By

    Lee

    Tuesday, February 22, 2011 6:22 AM

Answers

  • But each *byte* is surrounded with a start and stop bit...
    http://www.alanjmcf.me.uk/ Please follow-up in the newsgroup. If I help, mark the question answered
    • Edited by Alan J. McFarlane Wednesday, February 23, 2011 7:27 PM +"bit"
    • Marked as answer by Va Lee Sunday, February 27, 2011 7:56 PM
    Wednesday, February 23, 2011 7:27 PM

All replies

  • But each *byte* is surrounded with a start and stop bit...
    http://www.alanjmcf.me.uk/ Please follow-up in the newsgroup. If I help, mark the question answered
    • Edited by Alan J. McFarlane Wednesday, February 23, 2011 7:27 PM +"bit"
    • Marked as answer by Va Lee Sunday, February 27, 2011 7:56 PM
    Wednesday, February 23, 2011 7:27 PM
  • Thanks so much. It looks so simple but few books specify if those bits are manually put or they are there by default. Thanks
    Sunday, February 27, 2011 7:58 PM