Results 1 to 5 of 5

Thread: BS2, Serout and Visual Basic

  1. #1

    Default BS2, Serout and Visual Basic

    I am having a problem using data from a BS2, that is coming from a BOE
    that has a photodiode and AD592 from the Earth Measurements kit....the
    problem is that right now, the code works as needed, but I dont
    understand why. Here is the relevant part of my BS2 code
    ////////////////////////////////////////////////////////////////////////////
    /////////////
    serout 16,16468,[" Temperature is",dec ftemp, " "]
    ////////////////////////////////////////////////////////////////////////////
    /////////////
    ( taken straight from the Parallax manual, I'm no pioneer )
    (Ftemp of course, is my variable name for F temperature)

    here is the relevant part of the VB 6 code
    //////////////////////////////////////////////////////////////////////////
    Private Sub cmdcon_Click()
    'error trapping
    If MSComm1.PortOpen = True Then
    Exit Sub
    End If
    'Comm port
    MSComm1.CommPort = cbocomm.ListIndex + 1
    MSComm1.Settings = "9600,N,8,1" ' 9600 baud, no parity, 8 data, and 1 stop
    bit.
    MSComm1.InputLen = 5 ' read entire buffer
    MSComm1.RThreshold = 5
    MSComm1.InBufferSize = 12
    MSComm1.PortOpen = True ' Open the port.
    End Sub


    Private Sub Timer1_Timer()
    Dim data As String
    Data = MSComm1.Input
    If Mid(Data, 1, 1) <> "s" Then
    MSComm1.InputLen = 1
    Do While start <> "s"
    start = MSComm1.Input
    Loop
    StatusBar1.SimpleText = "Connected"
    MSComm1.InputLen = 8
    temp = Mid(Data, 1, 4)
    ////////////////////////////////////////////////////////////////////////

    Why cant I remove any of the text " The Temperature is" from the serout
    command without messing up the way the data is received by my program?
    I have poured over the manual in the serout section but cannot seem
    to get this to work right. Strangely enough, this code that you see
    will make the temperature update a textbox in real time......without
    any of the goofy text thats in the serout command......just the
    correct numbers!

    BUT! If I remove any or all of the text from the serout command, I
    then get all sorts of garbage text, sometimes bits and pieces of
    "The Temp is", and sometimes it crashes the app without connecting
    at all! I have tried to understand how this could work...but have
    run out of things to try.
    Can someone help me on the serout command, because I think thats where
    the problem lies.


    Dave
    Last edited by ForumTools; 10-01-2010 at 12:10 PM. Reason: Forum Migration

  2. #2

    Default

    >Why cant I remove any of the text " The Temperature is" from the serout
    > command without messing up the way the data is received by my
    program?

    You have the .InputLen set to 5 which limits you to read 5 bytes. Each
    character is going to be a byte.
    So if you decrease the length of your string " The Temperature is" then
    Mid(Data, 1, 1) <> "s" will never see the "s" in the first position. If
    your going to do it this way I would set the .InputLen value to 1 and read
    just the first character until you find the "s", then you could just
    continue reading in one byte at a time concatenating it in a variable and
    then updating the screen when you find the " ". The problem with this is you
    may continue to get more data in the buffer while you are reading as well as
    have more than one reading in the buffer. If the stamp is only sending every
    few seconds this probably won't be an issue.

    The oncomm event maybe a better technique, although I have not had the
    occasion to use it. You would need to have your string sent at a fixed
    length such as
    serout 16,16468,["T=",dec ftemp, " "]
    where ftemp would be a 3 digit number string such as "005". Then set your
    on_Comm trigger which is MSComm1.RThreshold = 6 so it triggers the onComm
    event when it receives 6 bytes.

    I have interfaced with a programmable temp controller that took the temp set
    point as (setpoint*10)+1000. The 1000 allowed the temperature to always be 4
    digits and the *10 removed the decimal. Once the controller got the string
    it converted the value back to its original form by reversing the process.
    The controller also reported values in the same way which made communicating
    with it pretty easy. All I had to do was look for a 4 character string and a
    return. If you have free memory space in the stamp maybe you could use the
    same technique.

    Hope this helps

    Jon Kreft
    Engineering Technician
    St. Jude Medical CRMD

    ----- Original Message -----
    From: <samhell@s...>
    To: <basicstamps@egroups.com>
    Sent: Tuesday, May 23, 2000 7:26 PM
    Subject: [basicstamps] BS2, Serout and Visual Basic


    > I am having a problem using data from a BS2, that is coming from a
    BOE
    > that has a photodiode and AD592 from the Earth Measurements kit....the
    > problem is that right now, the code works as needed, but I dont
    > understand why. Here is the relevant part of my BS2 code
    >
    ////////////////////////////////////////////////////////////////////////////
    > /////////////
    > serout 16,16468,[" Temperature is",dec ftemp, " "]
    >
    ////////////////////////////////////////////////////////////////////////////
    > /////////////
    > ( taken straight from the Parallax manual, I'm no pioneer )
    > (Ftemp of course, is my variable name for F temperature)
    >
    > here is the relevant part of the VB 6 code
    > //////////////////////////////////////////////////////////////////////////
    > Private Sub cmdcon_Click()
    > 'error trapping
    > If MSComm1.PortOpen = True Then
    > Exit Sub
    > End If
    > 'Comm port
    > MSComm1.CommPort = cbocomm.ListIndex + 1
    > MSComm1.Settings = "9600,N,8,1" ' 9600 baud, no parity, 8 data, and 1 stop
    > bit.
    > MSComm1.InputLen = 5 ' read entire buffer
    > MSComm1.RThreshold = 5
    > MSComm1.InBufferSize = 12
    > MSComm1.PortOpen = True ' Open the port.
    > End Sub
    >
    >
    > Private Sub Timer1_Timer()
    > Dim data As String
    > Data = MSComm1.Input
    > If Mid(Data, 1, 1) <> "s" Then
    > MSComm1.InputLen = 1
    > Do While start <> "s"
    > start = MSComm1.Input
    > Loop
    > StatusBar1.SimpleText = "Connected"
    > MSComm1.InputLen = 8
    > temp = Mid(Data, 1, 4)
    > ////////////////////////////////////////////////////////////////////////
    >
    > Why cant I remove any of the text " The Temperature is" from the serout
    > command without messing up the way the data is received by my
    program?
    > I have poured over the manual in the serout section but cannot seem
    > to get this to work right. Strangely enough, this code that you see
    > will make the temperature update a textbox in real time......without
    > any of the goofy text thats in the serout command......just the
    > correct numbers!
    >
    > BUT! If I remove any or all of the text from the serout command, I
    > then get all sorts of garbage text, sometimes bits and pieces of
    > "The Temp is", and sometimes it crashes the app without connecting
    > at all! I have tried to understand how this could work...but have
    > run out of things to try.
    > Can someone help me on the serout command, because I think thats where
    > the problem lies.
    >
    >
    > Dave
    >
    >
    >
    >
    >
    Last edited by ForumTools; 10-01-2010 at 12:10 PM. Reason: Forum Migration

  3. #3

    Default

    thanks Jon, I am busy on it , I wil let you know what I come up with.


    Dave
    -----Original Message-----
    From: Jon Kreft <JKreft@concentric.net>
    To: basicstamps@egroups.com <basicstamps@egroups.com>
    Date: Tuesday, May 23, 2000 11:36 PM
    Subject: Re: [basicstamps] BS2, Serout and Visual Basic

    >Why cant I remove any of the text " The Temperature is" from the serout
    > command without messing up the way the data is received by my
    program?

    You have the .InputLen set to 5 which limits you to read 5 bytes. Each
    character is going to be a byte.
    So if you decrease the length of your string " The Temperature is" then
    Mid(Data, 1, 1) <> "s" will never see the "s" in the first position. If
    your going to do it this way I would set the .InputLen value to 1 and read
    just the first character until you find the "s", then you could just
    continue reading in one byte at a time concatenating it in a variable and
    then updating the screen when you find the " ". The problem with this is you
    may continue to get more data in the buffer while you are reading as well as
    have more than one reading in the buffer. If the stamp is only sending every
    few seconds this probably won't be an issue.

    The oncomm event maybe a better technique, although I have not had the
    occasion to use it. You would need to have your string sent at a fixed
    length such as
    serout 16,16468,["T=",dec ftemp, " "]
    where ftemp would be a 3 digit number string such as "005". Then set your
    on_Comm trigger which is MSComm1.RThreshold = 6 so it triggers the onComm
    event when it receives 6 bytes.

    I have interfaced with a programmable temp controller that took the temp set
    point as (setpoint*10)+1000. The 1000 allowed the temperature to always be 4
    digits and the *10 removed the decimal. Once the controller got the string
    it converted the value back to its original form by reversing the process.
    The controller also reported values in the same way which made communicating
    with it pretty easy. All I had to do was look for a 4 character string and a
    return. If you have free memory space in the stamp maybe you could use the
    same technique.

    Hope this helps

    Jon Kreft
    Engineering Technician
    St. Jude Medical CRMD

    ----- Original Message -----
    From: <samhell@samhell.com>
    To: <basicstamps@egroups.com>
    Sent: Tuesday, May 23, 2000 7:26 PM
    Subject: [basicstamps] BS2, Serout and Visual Basic


    > I am having a problem using data from a BS2, that is coming from a
    BOE
    > that has a photodiode and AD592 from the Earth Measurements kit....the
    > problem is that right now, the code works as needed, but I dont
    > understand why. Here is the relevant part of my BS2 code
    >
    ////////////////////////////////////////////////////////////////////////////
    > /////////////
    > serout 16,16468,[" Temperature is",dec ftemp, " "]
    >
    ////////////////////////////////////////////////////////////////////////////
    > /////////////
    > ( taken straight from the Parallax manual, I'm no pioneer )
    > (Ftemp of course, is my variable name for F temperature)
    >
    > here is the relevant part of the VB 6 code
    > //////////////////////////////////////////////////////////////////////////
    > Private Sub cmdcon_Click()
    > 'error trapping
    > If MSComm1.PortOpen = True Then
    > Exit Sub
    > End If
    > 'Comm port
    > MSComm1.CommPort = cbocomm.ListIndex + 1
    > MSComm1.Settings = "9600,N,8,1" ' 9600 baud, no parity, 8 data, and 1 stop
    > bit.
    > MSComm1.InputLen = 5 ' read entire buffer
    > MSComm1.RThreshold = 5
    > MSComm1.InBufferSize = 12
    > MSComm1.PortOpen = True ' Open the port.
    > End Sub
    >
    >
    > Private Sub Timer1_Timer()
    > Dim data As String
    > Data = MSComm1.Input
    > If Mid(Data, 1, 1) <> "s" Then
    > MSComm1.InputLen = 1
    > Do While start <> "s"
    > start = MSComm1.Input
    > Loop
    > StatusBar1.SimpleText = "Connected"
    > MSComm1.InputLen = 8
    > temp = Mid(Data, 1, 4)
    > ////////////////////////////////////////////////////////////////////////
    >
    > Why cant I remove any of the text " The Temperature is" from the serout
    > command without messing up the way the data is received by my
    program?
    > I have poured over the manual in the serout section but cannot seem
    > to get this to work right. Strangely enough, this code that you see
    > will make the temperature update a textbox in real time......without
    > any of the goofy text thats in the serout command......just the
    > correct numbers!
    >
    > BUT! If I remove any or all of the text from the serout command, I
    > then get all sorts of garbage text, sometimes bits and pieces of
    > "The Temp is", and sometimes it crashes the app without connecting
    > at all! I have tried to understand how this could work...but have
    > run out of things to try.
    > Can someone help me on the serout command, because I think thats where
    > the problem lies.
    >
    >
    > Dave
    >
    >
    >
    >
    >



    Last edited by ForumTools; 10-01-2010 at 12:10 PM. Reason: Forum Migration

  4. #4

    Default

    In a message dated 5/24/00 6:50:22 AM Central Daylight Time,
    samhell@s... writes:

    > You have the .InputLen set to 5 which limits you to read 5 bytes. Each
    > character is going to be a byte. So if you decrease the length of your
    string
    > " The Temperature is" then Mid(Data, 1, 1) <> "s" will never see the "s"
    in
    > the first position. If your going to do it this way I would set the
    .InputLen value
    > to 1 and read just the first character until you find the "s", then you
    could just
    > continue reading in one byte at a time concatenating it in a variable and
    > then updating the screen when you find the " ". The problem with this is you
    > may continue to get more data in the buffer while you are reading as well as
    > have more than one reading in the buffer. If the stamp is only sending every
    > few seconds this probably won't be an issue.
    >
    > The oncomm event maybe a better technique, although I have not had the
    > occasion to use it. You would need to have your string sent at a fixed
    > length such as serout 16,16468,["T=",dec ftemp, " "] where ftemp would be
    > a 3 digit number string such as "005". Then set your on_Comm trigger which
    is
    > MSComm1.RThreshold = 6 so it triggers the onComm event when it receives
    > 6 bytes.

    Some additional notes that may be helpful: Set your RThreshold to 1 (so that
    it fires whenever a character arrives) and append a carriage return (13) to
    the data you send to the PC from the Stamp. Then use the OnComm event to
    build your string as the characters arrive. When the arriving character is a
    carriage return, you can process the string.

    You can use the Val function in VB to convert your (parsed) numeric strings
    to numbers. If the data your Stamp sends is Hex, then add a "&h" to the
    string before using Val (it's actually easier if you do this in the Stamp --
    then the same PC code will work with decimal or hex numbers).

    One caution on Val, though. If the Stamp sends "&hFFFF" then Val will return
    -1 since it wants to return a signed integer. If you want that value to be
    unsigned, then use a Long and this code:

    If IsNumeric(buffer) Then
    myLong = CLng(buffer)
    Else
    ' process error here
    End If

    One last note: If your VB program is sending data to the Stamp's programming
    port, it will be echoed back. Since you know what it is, it is easy to
    remove from the returned string. By terminating your command with a carriage
    return, your normal event code can deal with the echoed command.

    My July column in Nuts & Volts will discuss receiving and processing data
    from the Stamp using VB. One last thing...if you don't already have it, be
    sure to get a copy of Jan Axelson's book, "Serial Port Complete." It's the
    best reference you can have for serial programming. You can order from
    Amazon or Jan's web site: www.lvr.com.

    -- Jon Williams
    -- Dallas, TX
    -- Author, "Stamp Applications" - Nuts & Volts
    Last edited by ForumTools; 10-01-2010 at 12:10 PM. Reason: Forum Migration

  5. #5

    Default

    You will have to declare the variable your are using to build the string as
    a public variable. Otherwise once the OnComm procedure is finished your
    string variable you were building would be lost.


    Jon Kreft
    Engineering Technician, Manufacturing Systems Engineering
    St. Jude Medical (Maven Site)
    (864) 898 - 0305 x8113

    > -----Original Message-----
    > From: jonwms@a... [SMTP:jonwms@a...]
    > Sent: Wednesday, May 24, 2000 8:28 AM
    > To: basicstamps@egroups.com
    > Subject: Re: [basicstamps] BS2, Serout and Visual Basic
    >
    > In a message dated 5/24/00 6:50:22 AM Central Daylight Time,
    > samhell@s... writes:
    >
    > > You have the .InputLen set to 5 which limits you to read 5 bytes. Each
    > > character is going to be a byte. So if you decrease the length of your
    > string
    > > " The Temperature is" then Mid(Data, 1, 1) <> "s" will never see the
    > "s"
    > in
    > > the first position. If your going to do it this way I would set the
    > .InputLen value
    > > to 1 and read just the first character until you find the "s", then you
    >
    > could just
    > > continue reading in one byte at a time concatenating it in a variable
    > and
    > > then updating the screen when you find the " ". The problem with this is
    > you
    > > may continue to get more data in the buffer while you are reading as
    > well as
    > > have more than one reading in the buffer. If the stamp is only sending
    > every
    > > few seconds this probably won't be an issue.
    > >
    > > The oncomm event maybe a better technique, although I have not had the
    > > occasion to use it. You would need to have your string sent at a fixed
    > > length such as serout 16,16468,["T=",dec ftemp, " "] where ftemp would
    > be
    > > a 3 digit number string such as "005". Then set your on_Comm trigger
    > which
    > is
    > > MSComm1.RThreshold = 6 so it triggers the onComm event when it receives
    > > 6 bytes.
    >
    > Some additional notes that may be helpful: Set your RThreshold to 1 (so
    > that
    > it fires whenever a character arrives) and append a carriage return (13)
    > to
    > the data you send to the PC from the Stamp. Then use the OnComm event to
    > build your string as the characters arrive. When the arriving character
    > is a
    > carriage return, you can process the string.
    >
    > You can use the Val function in VB to convert your (parsed) numeric
    > strings
    > to numbers. If the data your Stamp sends is Hex, then add a "&h" to the
    > string before using Val (it's actually easier if you do this in the Stamp
    > --
    > then the same PC code will work with decimal or hex numbers).
    >
    > One caution on Val, though. If the Stamp sends "&hFFFF" then Val will
    > return
    > -1 since it wants to return a signed integer. If you want that value to
    > be
    > unsigned, then use a Long and this code:
    >
    > If IsNumeric(buffer) Then
    > myLong = CLng(buffer)
    > Else
    > ' process error here
    > End If
    >
    > One last note: If your VB program is sending data to the Stamp's
    > programming
    > port, it will be echoed back. Since you know what it is, it is easy to
    > remove from the returned string. By terminating your command with a
    > carriage
    > return, your normal event code can deal with the echoed command.
    >
    > My July column in Nuts & Volts will discuss receiving and processing data
    > from the Stamp using VB. One last thing...if you don't already have it,
    > be
    > sure to get a copy of Jan Axelson's book, "Serial Port Complete." It's
    > the
    > best reference you can have for serial programming. You can order from
    > Amazon or Jan's web site: www.lvr.com.
    >
    > -- Jon Williams
    > -- Dallas, TX
    > -- Author, "Stamp Applications" - Nuts & Volts
    >
    >
    >
    Last edited by ForumTools; 10-01-2010 at 12:10 PM. Reason: Forum Migration

Bookmarks

Posting Permissions

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