Results 1 to 7 of 7

Thread: Serial port help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Ca
    Posts
    124

    Cool Serial port help

    Hi everyone

    I could use some pointer on serial port programming. I haven’t done any hardware type programming as of yet. I have a Heidenhain Length gauge. It uses photoelectric linear encoders. This instrument has a digital readout with a RS232 output line. I’m looking to get the Value off the digital readout and bring it into my program.

    I have put a mscomm32.ocx onto my application. I’ve been reading up on serial port stuff.

    I have the input mode set to text because when it is set to binary i get nothing!

    Code
    Private Sub cmdHeidenhain_Click()
    ' Open the serial port
    MSComm1.CommPort = 1

    MSComm1.Settings = "9600,N,7,2"

    MSComm1.PortOpen = True

    ' Tell the control to read entire buffer when Input is used.
    MSComm1.InputLen = 0


    If MSComm1.PortOpen Then
    ' Send the keystroke to the port.

    ' Now " Ctrl + B" to Buffer

    MSComm1.Output = Chr$(2)
    aaa = MSComm1.Input
    Text1.Text = aaa


    ' I get a value here in the MSComm1.Input of
    ' -.37184 and three square boxes
    ' but i cannot assign it to my variable Text1
    ' This is my text box


    ' Unless Echo is on, there is no need to
    ' let the text control display the key.
    ' A modem usually echos back a character
    If Not Echo Then
    ' Place position at end of terminal
    txtTerm.SelStart = Len(txtTerm)
    End If
    End If

    MSComm1.PortOpen = False
    End Sub



    Thanks for any help

    reston

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762
    ' I get a value here in the MSComm1.Input of
    ' -.37184 and three square boxes
    ' but i cannot assign it to my variable Text1
    The 3 square boxs are values that come back and are not "text" they may be ACK or NACK or EOF type characters. You should look at the ASCII value of them to figure out what to do with them.
    ' This is my text box
    Notihing came out after this...is your text box empty???

    Regarding the ECHO thing...i'm a bit confused about your question.
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    To go along with what KEBO said - those characters are non-printable.

    You should really design a display on your form that shows the value received a bit differently.

    Let's say you get -.34532xxx (the xxx represents the unprintable chr's).

    You should display more like this at first, while developing:


    -.34532xxx
    LEN=10
    C1="-" (asc=45)
    C2="." (asc=46)
    C3="3" (asc=51)
    .
    .
    .
    C8="x" (asc=13)
    C9="x" (asc=10)
    C10="x" (asc=0)


    For instance.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Ca
    Posts
    124

    Cool re serial port help

    Hi You guys

    I'm not interested in the square box’s after the value. I want to strip the value out of that string in the mscomm.input. If my program is running and i have a break point set, i can hover my mouse over the msComm.input and see what is being returned from the gauge. But i can not capture the value.

    reston

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    You are not interested in the square boxes after the input?

    Knowing what they are means you can do an INSTR for them and cut them off...

    Whatever...

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Ca
    Posts
    124

    Cool re serial port help

    I'm not sure stripping the characters can be done. I can not create a variable out of what i get.

    Thanks for the help though

    I will try and strip those characters off

    Reston

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    If you find out they are CHR(13)+CHR(10)+CHR(0) then you know they are end-of-line sequence from old-style equipment.

    So test if RIGHT(strVbl,3)=Chr(13)+Chr(10)+Chr(0) then...

    But if it's not, then get familiar with what the ASCII values are of those unprintable characters...

    Good luck

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