home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / commdemo / commdemo.txt < prev    next >
Text File  |  1991-07-11  |  5KB  |  225 lines

  1. Sub Form_Load ()
  2.  
  3.     Initialize
  4.  
  5.     Menu_Comm_Connect.Visible = TRUE
  6.     Menu_Comm_Disconnect.Visible = FALSE
  7.     
  8.     offset = 200
  9.  
  10.     CaptionLeft = offset
  11.     CaptionTop = offset
  12.     CaptionWidth = ScaleWidth - CaptionLeft - offset
  13.     CaptionHeight = TextHeight("qypgjXAQK") * 1.5
  14.  
  15.     UpdateCaption " Ready", 0
  16.  
  17.     Left = (Screen.width - width) / 2
  18.     top = Height - ScaleHeight
  19.     Height = top + CaptionTop + CaptionHeight + offset
  20.  
  21. End Sub
  22.  
  23.  
  24. Sub Menu_File_Exit_Click ()
  25.  
  26.     Unload CommDemo
  27.  
  28. End Sub
  29.  
  30. Sub Menu_Comm_Connect_Click ()
  31.  
  32.     UpdateCaption " Opening Comm Port... " + CommPortName, .5
  33.  
  34.     CommTBBuffer = PostTBBuffer
  35.     CommRBBuffer = PostRBBuffer
  36.     CommPortName = PostPortName
  37.  
  38.     CommHandle = OpenComm(CommPortName, CommRBBuffer, CommTBBuffer)
  39.  
  40.     If CommHandle = -2 Then
  41.         result% = MsgBox("Port already Open!" + Chr$(13) + "Do you want to use it anyway ?", 4 + 16 + 256, "Communication Sampler II")
  42.         
  43.         If result% = 6 Then
  44.             ApiErr% = CloseComm(0)
  45.             CommHandle = OpenComm(CommPortName, CommRBBuffer, CommTBBuffer)
  46.         End If
  47.     End If
  48.  
  49.     If CommHandle < 0 Then
  50.         UpdateCaption " OpenComm() API Failed! (ERR " + Str$(CommHandle) + ")", .5
  51.     Else
  52.         Menu_Windows.enabled = TRUE
  53.         Menu_Window_Receive_Transmit.Checked = TRUE
  54.  
  55.         Receive.Show
  56.         
  57.         CommEventMask = PostEventMask
  58.         CommDeviceNum = Val(Mid$(CommPortName, 4, 1))
  59.         ApiErr% = SetCommEventMask(CommHandle, CommEventMask)
  60.  
  61.         PostState = CommState
  62.         CommState.Id = Chr$(CommHandle)
  63.  
  64.         ApiErr% = SetCommState(CommState)
  65.  
  66.         Menu_Comm_Connect.Visible = Menu_Comm_Disconnect.Visible
  67.         Menu_Comm_Disconnect.Visible = Not Menu_Comm_Connect.Visible
  68.         UpdateCaption " Commuications Port Opened...", .5
  69.         DisplayQBOpen CommState, CommPortName, CommRBBuffer, CommTBBuffer, CommReadInterval
  70.  
  71.         CommReadInterval = PostReadInterval
  72.         Receive.Receive_Timer.interval = CommReadInterval
  73.     End If
  74.  
  75. End Sub
  76.  
  77. Sub Menu_Comm_Disconnect_click ()
  78.  
  79.     UpdateCaption " Closing Communication Port...", 0
  80.  
  81.     Receive.Receive_Timer.interval = 0
  82.  
  83.     ApiErr% = CloseComm(CommHandle)
  84.     CommHandle = -1
  85.     CommDeviceNum = -1
  86.     
  87.     Menu_Comm_Disconnect.Visible = Menu_Comm_Connect.Visible
  88.     Menu_Comm_Connect.Visible = Not Menu_Comm_Disconnect.Visible
  89.     
  90.     Menu_Windows.enabled = FALSE
  91.     Unload Receive
  92.     
  93.     UpdateCaption " Ready", 0
  94.  
  95. End Sub
  96.  
  97. Sub Form_Unload (Cancel As Integer)
  98.  
  99.     If CommHandle > -1 Then
  100.         Menu_Comm_Disconnect_click
  101.     End If
  102.  
  103.  
  104.     UpdateCaption " Terminating Communication Sampler II...", .5
  105.  
  106. End Sub
  107.  
  108. Sub Menu_Comm_Send_CRLF_Click ()
  109.     Menu_Comm_Send_CRLF.Checked = Not Menu_Comm_Send_CRLF.Checked
  110. End Sub
  111.  
  112. Sub Initialize ()
  113.     
  114.     IndexTrans = 0
  115.     IndexReceive = 0
  116.     
  117.     CommHandle = -1
  118.     CommDeviceNum = -1
  119.     
  120.     ' Default Port Settings
  121.  
  122.     CommPortName = "COM1:"
  123.     CommState.BaudRate = 9600
  124.     CommState.ByteSize = Chr$(8)
  125.     CommState.Parity = Chr$(0)
  126.     CommState.StopBits = Chr$(0)
  127.     
  128.     ' Default Line Settings
  129.  
  130.     CommRBBuffer = 2048
  131.     CommTBBuffer = 2048
  132.     CommState.RlsTimeOut = 0
  133.     CommState.CtsTimeOut = 0
  134.     CommState.DsrTimeOut = 0
  135.     CommEventMask = &H3FF
  136.     CommReadInterval = 500
  137.  
  138.     ' Post-Poned settings
  139.  
  140.     PostRBBuffer = CommRBBuffer
  141.     PostTBBuffer = CommTBBuffer
  142.     PostEventMask = CommEventMask
  143.     PostState = CommState
  144.     PostReadInterval = CommReadInterval
  145.     PostPortName = CommPortName
  146.  
  147. End Sub
  148.  
  149. Sub Menu_Settings_Port_Click ()
  150.     
  151.     UpdateCaption " Loading Dialog...", 0
  152.  
  153.     PortDlg.Show 1
  154.  
  155.     If Menu_Comm_Connect.Visible = TRUE Then
  156.         UpdateCaption " Ready ", 0
  157.     Else
  158.         UpdateCaption " Communication Port Open...", 0
  159.     End If
  160.  
  161. End Sub
  162.  
  163. Sub Menu_Settings_Event_Click ()
  164.     
  165.     UpdateCaption " Loading Dialog...", 0
  166.     
  167.     EventDlg.Show 1
  168.     
  169.     If Menu_Comm_Connect.Visible = TRUE Then
  170.         UpdateCaption " Ready ", 0
  171.     Else
  172.         UpdateCaption " Communication Port Open...", 0
  173.     End If
  174.  
  175. End Sub
  176.  
  177. Sub Menu_Settings_Line_Click ()
  178.  
  179.     UpdateCaption " Loading Dialog...", 0
  180.     
  181.     LineDlg.Show 1
  182.     
  183.     If Menu_Comm_Connect.Visible = TRUE Then
  184.         UpdateCaption " Ready ", 0
  185.     Else
  186.         UpdateCaption " Communication Port Open...", 0
  187.     End If
  188.     
  189. End Sub
  190.  
  191. Sub Form_Paint ()
  192.     
  193.     Draw3d CaptionLeft, CaptionTop, CaptionWidth, CaptionHeight, CommDemo
  194.     UpdateCaption CaptionText$, 0
  195.  
  196. End Sub
  197.  
  198. Sub Menu_Window_Receive_Transmit_Click ()
  199.  
  200.     Menu_Window_Receive_Transmit.Checked = Not Menu_Window_Receive_Transmit.Checked
  201.     
  202.     If Menu_Window_Receive_Transmit.Checked = TRUE Then
  203.         Receive.Show
  204.         Receive.Receive_Timer.interval = CommReadInterval
  205.     Else
  206.         Receive.Hide
  207.     End If
  208.  
  209. End Sub
  210.  
  211. Sub Menu_File_About_Click ()
  212.     
  213.     UpdateCaption " Loading Dialog...", 0
  214.  
  215.     AboutDlg.Show 1
  216.  
  217.     If Menu_Comm_Connect.Visible = TRUE Then
  218.         UpdateCaption " Ready ", 0
  219.     Else
  220.         UpdateCaption " Communication Port Open...", 0
  221.     End If
  222.  
  223. End Sub
  224.  
  225.