15 04 MH37WWZACMQQ5WQ35D66LWUGUXLFUZNPFBTRC3Q




Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:Serial Communication
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6! (Publisher: The Coriolis Group) Author(s): Peter G. Aitken ISBN: 1576102815 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




The Text Box control’s KeyPress event procedure links the user’s input to the Comm control. Rather than sending each individual character as it is typed, this procedure saves the input in a buffer and sends it all at once when the user presses the Enter key.
Received data is handled in the OnComm event procedure. After checking the CommEvent property to see that the event was indeed triggered by receipt of data, the code adds the received character to the end of the Text Box’s Text property, then moves the insertion point to the end of the text.

Figure 15.1  Executing the “dumb terminal” program.

Listing 15.2 Code in COMMDEMO.FRM.


Option Explicit

Dim Buf1 As String

Private Sub Text1_KeyPress(KeyAscii As Integer)

‘ Add the key to the buffer.
Buf1 = Buf1 & Chr$(KeyAscii)

‘ If it was a carriage return, send the buffer contents
‘ to the Comm control and empty the buffer.
If KeyAscii = 13 Then
MSComm1.Output = Buf1
Buf1 = “”
End If

End Sub

Private Sub Form_Load()

‘ Initialize the Comm control.
MSComm1.CommPort = 1
MSComm1.Settings = “14000,E,7,1”
Debug.Print “----------------”

‘ Comm event will be triggered when a single character is received.
MSComm1.RThreshold = 1

‘ Open the port.
MSComm1.PortOpen = True

End Sub

Private Sub Form_Resize()

‘ Set Text Box to fill the form.
Text1.Width = Form1.ScaleWidth
Text1.Height = Form1.ScaleHeight
Text1.Left = 0
Text1.Top = 0

End Sub

Private Sub Form_Unload(Cancel As Integer)

‘ Close the port.
MSComm1.PortOpen = False

End Sub

Private Sub MSComm1_OnComm()

Dim s As String

‘ When a comm event occurs.

‘ Was it a “receive” event? If so, add the received character
‘ to the Text Box and set the insertion point at the end of
‘ the text. Other events are ignored.

Select Case MSComm1.CommEvent
Case comEvReceive
s = MSComm1.Input
If Asc(s) = 13 Then s = vbCrLf
Text1.Text = Text1.Text & s
Text1.SelStart = Len(Text1.Text)
End Select

End Sub


If you use this program with a modem, you’ll have to type the modem commands yourself (the commands are usually sent automatically by a communication program). Most modems adhere to the AT command set, originally developed by Hayes for its modems. The first command you should send is ATZ, which resets and initializes the modem. The model will respond OK. A few other commands are listed in Table 15.3; refer to your modem documentation for more information.
This very basic demonstration program is intended to show you only the fundamentals of using the Comm control. As it stands, the program includes no error handling and is vulnerable to many problems in use. Even with the Comm control, writing a full-featured and reliable serial communication program is a major task. Whenever I need anything but the most basic communication capabilities in a Visual Basic program, I always investigate the third-party market for a custom control rather than trying to do the job myself using the Comm control.

Table 15.3 Modem commands.



Command
Description

ATDT
Dial the following number using tone dialing. For example, ATDT5551212 would cause the modem to dial 555-1212.

ATE
Disable echoing of input. Use this command if the program is displaying everything you type twice.

ATH
Hang up the phone.








Previous
Table of Contents
Next






Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.



Wyszukiwarka

Podobne podstrony:
15 04 2014 Pietrzyk
15 04 Pilarki lancuchowe
Cennik zasobniki ciepła 15 04 2013
15 04 08 sem VIII
15 04 08 sem VIII
15 04
Cennik świadczeń zdrowotnych MPS 15 04 2015 r LAB na stronę 1(2)
15 04 2004 szczerba
15 04 MB
120167637347a0205589a35 idLA 15 [ 04 01 2010 ]
Afganistan 300 kobiet obrzuconych kamieniami (15 04 2009)
Literaturoznawstwo (15 04 2013)

więcej podobnych podstron