Results 1 to 4 of 4

Thread: Using MSComm Input property

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    60

    Using MSComm Input property

    Hi
    I currently have a MSComm control (piezoComm1) which I use to send commands to a device attached to COM1.
    I am using the Output property to send commands to the device, eg. MOV A25 which will move the device to 25 microns. This is working fine as I have tested the device's position using Hyper Terminal. However, I would like to test the position of the device within my VB project and display the results in a label on the form. Heres my code:

    VB Code:
    1. Private Sub cmdGo_Click()
    2.     frmMain.piezoComm1.Settings = "115200, N, 8, 1"     'set baud rate, parity, data bits and stop bits
    3.     frmMain.piezoComm1.CommPort = 1                     'set PC COMM port
    4.     frmMain.piezoComm1.InputLen = 0                     'retrieve all of the input buffer
    5.     frmMain.piezoComm1.InputMode = comInputModeText     'input buffer to receive text - not binary
    6.     frmMain.piezoComm1.PortOpen = True                  'open port
    7.     frmMain.piezoComm1.Handshaking = comRTS             'request to send handshaking
    8.        
    9.     frmMain.piezoComm1.Output = frmMain.Text1 + Chr$(13) + Chr$(10) 'send command in text box
    10.     frmMain.lblResult1.Caption = frmMain.piezoComm1.Input           'put contents of input buffer into label
    11.  
    12.     frmMain.piezoComm1.PortOpen = False                 'close port
    13. End Sub

    When I type the query position command "POS? A" in the text box and click the button the designated label disappears, as if its caption value is set to blank/nothing. I am confident that this command works as I have used it in Hyper Terminal.

    Can anybody shed some light on this problem?

    Thank you in advance

    Wallace

  2. #2
    New Member
    Join Date
    Feb 2006
    Posts
    4

    Re: Using MSComm Input property

    You shouldn't put line:" frmMain.lblResult1.Caption = frmMain.piezoComm1.Input " into cmdGo_Click(). I suggest U to use the OnComm event and fire this command there. I would work better.

  3. #3
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Using MSComm Input property

    To clarify foae's post, you are sending info to the serial port and then immediately attempting to read back in from it. The port will not respond in such a time, and hence you simply don't get a respone. A better approach would be to finish executing the command and then listen to the port, monitoring what comes in and waiting until you get what you expect. Certainly you will have to wait longer than the time it takes for the code to execute from one line to the next.

    zaza

  4. #4
    New Member
    Join Date
    Feb 2006
    Posts
    4

    Re: Using MSComm Input property

    yeah, zaza is right. In fact, sometimes i use a small delay time (about 50ms) oin the 1st line of OnComm event by using sleep API. But you can also use just some command lines => that's enough

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