본문 바로가기

IT-Consultant

비주얼 베이직 6.0에서 RS232 통신하기

참조 :  http://support.microsoft.com/kb/194922 


 

App1 만드는 단계

  1. 새 표준 EXE 프로젝트를 만듭니다. 기본적으로 Form1이 만들어집니다.
  2. 프로젝트 메뉴에서 구성 요소 선택, Microsoft 통신 "컨트롤"을 확인한 다음 확인을 클릭하십시오.
  3. MSCOMM 컨트롤을 폼에 추가하십시오.
  4. TextBox 및 있는 CommandButton 폼에 추가하십시오. 텍스트 여러 줄 속성을 True로 변경하십시오.
  5. Form1의 코드 창에 다음 코드를 추가하십시오.
          Private Sub Form_Load()
             Form1.Caption = "App1"
             With MSCOMM1
                .Handshaking = 2 - comRTS
                .RThreshold = 1
                .RTSEnable = True
                .Settings = "9600,n,8,1"
                .SThreshold = 1
                .PortOpen = True
                ' Leave all other settings as default values.
             End With
             Command1.Caption = "&Send"
             Text1.Text = "Test string from App1 "
          End Sub
    
          Private Sub Command1_Click()
             MSComm1.Output = Text1.Text
          End Sub
    
          Private Sub Form_Unload(Cancel As Integer)
             MSComm1.PortOpen = False
          End Sub
    
    						

App2 만드는 단계

  1. Visual Basic의 새 인스턴스를 시작하십시오.
  2. 새 표준 EXE 프로젝트를 만듭니다. 기본적으로 Form1이 만들어집니다.
  3. 프로젝트 메뉴에서 구성 요소 선택, Microsoft 통신 "컨트롤"을 확인한 다음 확인을 클릭하십시오.
  4. MSCOMM 컨트롤을 폼에 추가하십시오.
  5. TextBox 폼에 추가하십시오. 텍스트 여러 줄 속성을 True로 변경하십시오. 폼, 대부분의 다룰 있으므로 때 받은 모든 데이터는 그 안에 표시할 수 있습니다 TextBox를 확대하십시오.
  6. Form1의 코드 창에 다음 코드를 추가하십시오.
          Private Sub Form_Load()
             Form1.Caption = "App2"
             With MSComm1
                .CommPort = 2
                .Handshaking = 2 - comRTS
                .RThreshold = 1
                .RTSEnable = True
                .Settings = "9600,n,8,1"
                .SThreshold = 1
                .PortOpen = True
                ' Leave all other settings as default values.
             End With
             Text1.Text = ""
          End Sub
    
          Private Sub Form_Unload(Cancel As Integer)
             MSComm1.PortOpen = False
          End Sub
    
          Private Sub MSComm1_OnComm()
             Dim InBuff As String
    
             Select Case MSComm1.CommEvent
             ' Handle each event or error by placing
             ' code below each case statement.
    
             ' This template is found in the Example
             ' section of the OnComm event Help topic
             ' in VB Help.
    
             ' Errors
                Case comEventBreak   ' A Break was received.
                Case comEventCDTO    ' CD (RLSD) Timeout.
                Case comEventCTSTO   ' CTS Timeout.
                Case comEventDSRTO   ' DSR Timeout.
                Case comEventFrame   ' Framing Error.
                Case comEventOverrun ' Data Lost.
                Case comEventRxOver  ' Receive buffer overflow.
                Case comEventRxParity   ' Parity Error.
                Case comEventTxFull  ' Transmit buffer full.
                Case comEventDCB     ' Unexpected error retrieving DCB]
    
             ' Events
                Case comEvCD   ' Change in the CD line.
                Case comEvCTS  ' Change in the CTS line.
                Case comEvDSR  ' Change in the DSR line.
                Case comEvRing ' Change in the Ring Indicator.
                Case comEvReceive ' Received RThreshold # of chars.
                   InBuff = MSComm1.Input
                   Call HandleInput(InBuff)
                Case comEvSend ' There are SThreshold number of
                               ' characters in the transmit buffer.
                Case comEvEOF  ' An EOF character was found in the
                               ' input stream.
             End Select
    
          End Sub
    
          Sub HandleInput(InBuff As String)
             ' This is where you will process your input. This
             ' includes trapping characters, parsing strings,
             ' separating data fields, etc. For this case, you
             ' are simply going to display the data in the TextBox.
             Text1.SelStart = Len(Text1.Text)
             Text1.SelText = InBuff
          End Sub
    
    						

'IT-Consultant' 카테고리의 다른 글

DropBox는 Storage를 자체 구축했을까?  (0) 2012.02.28
NDrive Daum 클라우드 Ucloud 비교  (0) 2012.02.27
소셜분석서비스에 대해서...  (0) 2012.02.20
두번째 데모  (1) 2012.02.15
CakePHP + APC 설정  (0) 2012.01.10