Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Serial Comm communication Issue

Status
Not open for further replies.

jgo333n

Programmer
Jul 16, 2007
27
GB
i am using VB6 to talk to an instrument via comportm port, using a portmonitor i can see the strings being sent all ok. I cannot however seem o get a response back to my request.

I am using the mscomm control and trying to receive the repsone, whioch should be an acknoloedgement via the
MSComm1_OnComm() event. But nothing is returned, i am wondering if i ned to wait a while to see if a response is genereated but connot find out if or how to do this.

here is how i am opening my port:

Private Sub CommOpen(PortID As Integer, Settings As String)

With MSComm1
.Settings = Settings '(9600,N,8,1)
.CommPort = PortID '5
.InBufferSize = 1024
.RTSEnable = 1 'True 'set this to enable receing of information.
.EOFEnable = 1 'True
.InputLen = 0 'lenght of string being sent 0 - read everything
.InputMode = comInputModeText
'3rd party hardware uses XOnXOff handshaking
.Handshaking = comXOnXoff
.PortOpen = True
End With

End Sub

where is how i send the message:

strMessage = ":I:pR1/?/.."
'mscomm1.OutBufferSize = Len(strMessage)
MSComm1.Output = strMessage + Chr(13)
'try to get the response
sResponse = MSComm1.Input
msgbox sResponse 'comes back blank.

and here is the mscomm1_comm event code.

Private Sub mscomm1_OnComm()
MsgBox CStr(MSComm1.Input)
end sub

I am asuming i must have missed a config setting soemwhere of have set it wrong, but after looking on the interweb for hours everything seesm to be as everyone suggests.

Can anyone help me or, if i can find them, do I have to call the A team



 
You don't have to wait between sending and receiving because the receiver is always waiting in a loop for a response once opened.

I presume you dont have the startup and transmit code in the same sub.
Try them in different Command_click subs of 2 different command buttons.

Are you sure you have the correct wiring in your RS232 cord and plugs. You have to have 4 wires. Check one pair has not swapped + and -. Check transmit & receive are not swapped
Some devices you connect the computer transmit pair to the device transmit pair, others you connect transmit to receive. There isn't a golden rule.

I would set the mscomm properties in the Properties box of the form, not in code. Otherwise if you try to send immediately after you set these properties it may not have taken effect.
Commport 5
DTREnable True
EOFEnable False
Handshaking 0-None
InBuffersize 1024
InputLen 0
InputMode 0-comInputModeText
NullDiscard False
RThreshold 1 (important)
RTSEnable False
OutBufferSize 512
Settinga 9600,n,8,1 (as long as your device is the same)
SThreshhold 0
Thin will cause the OnComm to fire on the first byte received and every other one after so you never miss a byte.
Just have mscomm1.Portopen=true in the Sub ComOpen
 
Thank you tedsmith for your reply, sending si nto an issue I can see vai a port monitr application the data going accross. but am not able to receive any information back si i know my comm port configuration is correct as far as sending ( and have used the settings manufature has provided.

I will try your suggestion and get back to you.
 
Hi TedSmith,
I have tried hard coding the parameters in the property box and alas not made any change to what i am seeing.


 
>using a portmonitor

Are you using PortMon? or some other product?

And are you saying the monitor does not see any return traffic?

If so, this would suggest that you may not be sending messages to the device that the device actually understands
 
strongm

Yes i am using portmon and what a cool tool it is.

You may be right as on further investigfation there are two non priable characters the current software sends i thin htese are <cr><lf>.

When i get some instrument time (instrument is in use most of day) I am going to record the trace in hex mode examine the oput put and put what ever these chaaracters are in my sorftware and i hope that is the answer.

I shall post an update when i know.

Cheers.

 
Try something other than msgbox because the very first flicker of data will show the box and stop any more bytes being received

Try a label instead to print everything
Private Sub mscomm1_OnComm()
Label1.caption=Label1.Caption & CStr(MSComm1.Input)
end sub

or this will only print the received contents if it ends with Chr(13)

Dim Buffer as string

Private Sub mscomm1_OnComm()
Buffer=Buffer & CStr(MSComm1.Input)
If instr(Buffer,vbCr) then
Label1.caption =Buffer
Buffer=""
End If
End Sub

Is your comm port physically functioning?
If you have some data plugs, wire and a soldering iron, there is a hardware way of seeing if your physical computer ports are working or not.
If you don't have a soldering iron you can buy crimp connectors and use separated ribbon cable.
Wire up 2 plugs with the send pins connected to the receive pins.(Plenty of RS232 wiring diagrams on the web)
No matter what you send, you should get it back with my example 1 above.
 
If you device is not sending out printable characters say
Label1.caption=Label1.caption & asc((MSComm1.Input)
Set the label to multiline.
 
Tedsmith,

I have almost resolved the issue, firstly when looking at the hex output i need to send a cr and lf which in text mode was not showing up when the original software sent its signel, secondly i need to check what is returned and wait for an acknowledgement return string, where as i was taking the first bit returned and acting on it not checkingeach reurn byte until the acknowledgment was setn.

Both these things in place i am starting to be able tocommunicate more sucessfully now.

I update this thread as necessary.

Thanks for tour help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top