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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help about MSComm.Input

Status
Not open for further replies.

CGR707

Programmer
Jul 7, 2002
20
PH
Hi,

I'm trying to develop a VB program that intercept text messages and display it into the PC screen (SMS). I use the MSComm control to communicate the serial port. I have a problem regarding "MSComm1.Input", it doesn't have any data in the buffer or sometime the data is garbage. Could somebody help on this one and please, give some examples. Thanks.


CGR707
 
Can you give more details on what you explicitly want to happen?
i.e. do you want a real time system that as soon as you receive communication on the COM port it is displayed on the screen? Are you filtering for specific commands and then displaying subsequent messages etc.
Do you know how long the buffer is?,
I worked with MSComm in a manafacturing environment and found little to no problems, the main problems we had were to do with the external device communicating with the COM port, and the actual PC setup.

You can capture all input by putting this on a form_load event

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

' Assign to byte array for processing
Arr = MSComm1.Input



Alternatively
Set the Rthreshold property to be amount of characters you expect- note the MSComm_OnComm event wont be fired until this amount of characters are received. (you can set to 1 to process each char individually)


Private Sub MSComm_OnComm ()
Select Case MSComm1.CommEvent
' Handle each event or error by placing
' code below each case statement

' Events
Case comEvReceive ' Received RThreshold # of
' chars.
'Do my code here to process message i.e
txtMyDisplay.text = MSComm1.Input
Case comEvEof ' An EOF charater was found in
' the input stream
End Select
End Sub



Email me if you want a full working example of code.

 
Hi,
First of All, you must set your comm control to the same BaudRate, Start/Stop bits and HandShake protocol used by your mobile phone!
You should also be aware of comunication timings (SMS protocol is very complex).
I've Develope an GPS/GSM Application that uses hi speed serial comunication over GSM network, and part of the application has to be changed to a windows service, since you have to manage several delays/timmings simultaneously.
For specific mscomm problems, just be more concise on your doubt!

Hope this helps a bit,

Carlos
 
Also understand that the &quot;Input&quot; event will ALWAYS return IMMEDIATELY with a result, which may be NULL. If you want to wait for input, test the value of &quot;InBufferCount&quot; to be greater than 0 before calling Input.

If parity/baud/stop are set correctly, check to see if the phone sends control characters like STX/ETX around the message. That may be the &quot;garbage&quot; you're seeing.

Howard Dingman
Pro-Tel Communications
Endicott, NY

webmaster<at>holocom<dot>com
 
hi hmckillop,

Thanks for your answer, but i still have a problem during the message is received, I send a text &quot;testing&quot; but what i received is this &quot;üðððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððð&quot;

this is my settings :


MSComm1.CommPort = 2
MSComm1.Settings = &quot;9600,N,8,1&quot;
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
MSComm1.Inputlen = 0
MSComm1.Handshaking = ComRTSXOnXOff
MSComm1.EOFEnable = True
MSComm1.RTSEnable = True
MSComm1.DTREnable = True
MSComm1.PortOpen = True
MSComm1.InputMode = comInputModeBinary


Could you help on this one? please


Thanks

CGR707

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top