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’m getting an error on the readout.
Code
Private Sub cmdHeidenhain_Click()
Dim Buffer As Variant
Dim Arr() As Byte
' Set and open port
MSComm1.CommPort = 1
MSComm1.PortOpen = True
' Set InputMode to read binary data
MSComm1.InputMode = comInputModeBinary
' Wait until 10 bytes are in the input buffer
Do Until MSComm1.InBufferCount < 10
DoEvents
Loop
' Store binary data in buffer
Buffer = MSComm1.Input
' Assign to byte array for processing
Arr = Buffer
End Sub
This is the code that I found in the help file.
I’m not sure what to do with the Variable Arr ?? My plan is to input data and put it into a text box so my app. can use it in my equation.
I tried the code for putting the Arr into a text box but i'm not recieving anything from the Heidenhain rs232 that i can see in my app.?? Any thoughts on this
Have u set the communication parameters for your vb program and the gauge ?
Code:
MSComm1.CommPort = 1
MSComm1.Settings = "9600,e,7,1" 'i think u might to set the communication parameters
MSComm1.InputLen = 0
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
If Not MSComm1.PortOpen Then
MSComm1.PortOpen = True
End If
.
tiguy, a technique I use when messing with the serial port is to use Hyper terminal. It allows you to connect your device and accually see what is coming in without messing with VB. Once you know your computer is interfacing with your device by seeing the feed in hyperterminal then you can move on to your project.