Results 1 to 6 of 6

Thread: read from serial port

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Posts
    12

    read from serial port

    Hi,i am using serial communication to read from a plc.The plc will send a string :&H3A as a header byte then C(which is a variable that contains data)I want to read and mask out the header byte.I use the following code but cannot read anything.Any suggestions?

    Private Sub btnread_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnread.Click
    Msg = SerialPort1.ReadExisting
    count = Val(Mid(Msg, 3, 2))

    Lblno.Text = count
    End Sub

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: read from serial port

    what version of vb are you using? are you saying the device sends (in hex) this

    3AC
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Posts
    12

    Re: read from serial port

    I am using vb.net 2005

    The header byte &H3A is supposed to be ":"
    and then it sends C which means i think it sends ":C"

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: read from serial port

    what does "The header byte &H3A... " mean? does the device send on a periodic basis?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Posts
    12

    Re: read from serial port

    Sorry but i am also not very sure about that but i think that the plc must send the header byte as to inform when the string starts.&H3A is like a short code for the simbol ":" And also if the plc does not send continuosly does it mean i must change the plc program to constantly send the string in order for my vb program to work?

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: read from serial port

    you really need to know the protocol of the PLC device. if you need to interrogate the device or not, when it sends, what it sends, what it means, etc.

    ascii codes
    Last edited by dbasnett; Dec 18th, 2008 at 08:44 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width