|
-
April 19th, 2001, 09:00 AM
#1
MSCOMM
I am actually a domino developer (Lotus Notes), but I have had to incorporate the MSCOMM control into a domino application to send SMS messages direct from the application to certain network providers.
The code dialss and sends the sms, however, I have had to use the Sleep command to pause my code while I wait for the modem to connect.
Ideally, I need to read each line of the input stream so I know exactly when to send my information through the port, this is also required as occasionally, the service I dial into alters slightly and I need to recognise this to force a drop connection and redial.
I can read the mscomm1.input, but when I view it I have the whole of the Output/Prompt sequence from the network provider in the buffer, where ideally I need to act on the input buffer line by line
Can anyone give me a hint - I've been through MSDN and not a lot of it makes much sense to me - I basically need to read the ibout from the modem, clear it, act on it, then read the next line
cheers
-
April 19th, 2001, 10:18 AM
#2
Re: MSCOMM
You need to break the buffer up try adding this to the OnComm Event, this will fire when data arrives on the comm port.
Private Sub MSComm1_OnComm()
Dim RxBuffer As String
Dim CurrentLine As String
Dim Linepos As Long
If MSComm1.InBufferCount > 1 Then 'Any data in Rx Buffer?
RxBuffer = MSComm1.Input
Do
Linepos = InStr(1, RxBuffer, vbCrLf) 'Search for VBCRLF
If Linepos > 1 Then 'Is there a CHR(13)+CHR(10)??
CurrentLine = Left(RxBuffer, Linepos) 'Extract current line for buffer
Select Case CurrentLine 'Act on line
Case "OK"
MsgBox "Modem response OK"
Case "CONNECT"
'connected
Case Else
'handle other messages here
End Select
RxBuffer = Right(RxBuffer, Len(RxBuffer) - Linepos) 'REMOVE parsed line
Else
Exit Do 'Not enough data, get out of here!
End If
Loop 'PARSE ALL other lines in RxBuffer
End If
End Sub
just add the handlers for each line in the select case.
Jean-Guy
-
April 19th, 2001, 10:22 AM
#3
Re: MSCOMM
There are a couple of options here:
1) If your output from the network providers is in fixed-length blocks of data (say 1024 bytes), then you can set the MSCOMM1.InputLen property to this number. Then whenever you read the input via the mscomm1.input you will get the data in 1024 byte blocks (if you have 1024 bytes waiting, else you will get a zero length string [text mode])
2) If your output uses a specific key sequence to denote the end or beginning of a line of data such as CR-LF combination, then you can set the MSCOMM1.InputLen property to 0 (read entire buffer) and then get the buffer with MSCOMM1.Input and parse the strings by using the Split command. Split(StringToSplit, Delimiter)
Hope this helps,
-K
-
April 19th, 2001, 10:41 AM
#4
Re: MSCOMM
Cheers - the problem with this is I have multiple operators, with varying lengths of datablocks, and various endings. I need a way to read each line and act on say "(Do not press return):" - this is one line of the prompt which I need to respond to but the second network prompt is different
-
April 19th, 2001, 10:43 AM
#5
Re: MSCOMM
Cheers - I'll give it a go
-
April 20th, 2001, 03:34 AM
#6
Re: MSCOMM
I tried this but the oncomm event does not fire, and I do not have the physical control to work with, only the code behind it
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
|