|
-
Jun 30th, 2005, 03:53 AM
#1
Thread Starter
Member
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:
Private Sub cmdGo_Click()
frmMain.piezoComm1.Settings = "115200, N, 8, 1" 'set baud rate, parity, data bits and stop bits
frmMain.piezoComm1.CommPort = 1 'set PC COMM port
frmMain.piezoComm1.InputLen = 0 'retrieve all of the input buffer
frmMain.piezoComm1.InputMode = comInputModeText 'input buffer to receive text - not binary
frmMain.piezoComm1.PortOpen = True 'open port
frmMain.piezoComm1.Handshaking = comRTS 'request to send handshaking
frmMain.piezoComm1.Output = frmMain.Text1 + Chr$(13) + Chr$(10) 'send command in text box
frmMain.lblResult1.Caption = frmMain.piezoComm1.Input 'put contents of input buffer into label
frmMain.piezoComm1.PortOpen = False 'close port
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
-
Feb 22nd, 2006, 10:40 PM
#2
New Member
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.
-
Feb 23rd, 2006, 04:23 PM
#3
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
-
Feb 28th, 2006, 11:27 AM
#4
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|