Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sending text to COM port....
Message
From
22/04/2002 02:05:45
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Title:
Sending text to COM port....
Miscellaneous
Thread ID:
00647441
Message ID:
00647441
Views:
48
Hi All,

I am trying to transmit and receive text data using COM port ( VFP6).
WHen I use this peace of code on 3rd printout I got garbage after the line
Comm1.Output = "AT+CMGS="+chr(34)+"+61414457256"+chr(34)+CHR(13)
instead of OK

Any idea of why?
Is there any better way of reading and writing to COM port from VFP6?

Regards

Dejan Jocic



* use MSCOMM32.OCX
PUBLIC InString, Comm1
clea

Comm1 = CREATEOBJ('MSCOMMLib.MSComm')

* Use COM1.
Comm1.CommPort = 1
* 9600 baud, no parity, 8 data, and 1 stop bit.
Comm1.Settings = "9600,N,8,1"
Comm1.Handshaking = 2 && RTS/CTS or 3
* Tell the control to read entire buffer when Input is used.
Comm1.InputLen = 0
Comm1.InBufferCount = 0 && Flush the input buffer

* Open the port.
Comm1.PortOpen = .T.
* Send the attention command to the molem.
*Comm1.Output = "ATDT0414529283" + CHR(13)
lcSMSCNo = "+61415011501"
Comm1.Output = "AT" + CHR(13)
waitforOK()

?printmodembuffer()
Comm1.InBufferCount = 0
Comm1.Output = "AT+CMGF=1" + CHR(13)
waitforOK()
?printmodembuffer()
Comm1.InBufferCount = 0
Comm1.Output = "AT+CSCA="+chr(34)+lcSMSCNo+chr(34)+CHR(13)
waitforOK()
?printmodembuffer()
lcDestNo = "0414457256"
Comm1.InBufferCount = 0
Comm1.Output = "AT+CMGS="+chr(34)+"+61414457256"+chr(34)+CHR(13)
InString=''
waitforOK()
?printmodembuffer()


* Wait for data to come back to the serial port.
*wait window 'Press any key to hang...'

* Close the serial port.
Comm1.Output = "ATZ+ CHR(13) + CHR(10)" && (usually resets & hangs up)
Comm1.Output = "AT+ CHR(13)"
Comm1.Output = "ATH+ CHR(13)"
Comm1.PortOpen = .F.

procedure printmodembuffer
InString = ''


DO WHILE Comm1.InBufferCount >0 && <= 2
* Read the "OK" response data in the serial port.
InString = Comm1.Input
if 'OK'$InString
exit
endif

ENDDO

return InString


procedure waitforOK

FOR i = 1 to 20000000 && 00
*!* Comm1.inputlen = 2
*!* *Comm1.InBufferCount = 2
*!* lnChar = Comm1.input
*!* IF lnchar = "OK"
*!* EXIT
*!* ENDIF
ENDFOR

return .t.
Reply
Map
View

Click here to load this message in the networking platform