cdholding image

comm32 home
comm32 forum
buy comm32

Introduction
Install Comm32
Why Not MsComm?

Properties
   .Break
   .CDHolding
   .CommEvent
   .CommPort
   .CTSHolding
   .DSRHolding
   .DTREnable
   .EOFEnable
   .Handshaking
   .InBufferCount
   .InBufferSize
   .Input
   .InputLen
   .InputMode
   .NullDiscard
   .OutBufferCount
   .OutBufferSize
   .OutPut
   .ParityReplace
   .PortOpen
   .RThreshold
   .RTSEnable
   .Settings
   .STHreshold


Comm32 Properties
   .DeviceName
   .EOFChar
   .EvtChar
   .EvtCharEnable
   .OutPutEx
   .OutPutMode
   .ParallelEnable
   .TxTimeout

Comm32 Functions
   .getByte

   .GetPortStatus
   .InstalledDrivers
   .putByte
   .PortExists
   .ReadBytes
   .ReadString
   .WriteBytes
   .WriteString

OnComm Event
Hardware/Cables etc

OnComm Event

If an application is waiting for data to arrive via the serial port many developers will utilize a timer event or run a continuous loop inspecting the serial port waiting for something to happen. Of course that isn't very efficient.

In the real world you don't keep running to the door to see if you have a visitor - you get on with something productive (or sleep) until the doorbell rings.

The OnComm event, just like a doorbell, is triggered when the com port needs your attention.

Place the Comm32 control on your form - double click it and that will open the code window and create the template for your OnComm event. Any code you write inside the OnComm event will run every time 'something' happens at the ComPort. Here's the simplest OnComm event we could think of:-

Private Sub Comm1_OnComm( )

      Text1.Text = "Hello World"

End Sub

Of course that doesn't do much. You don't know what type of event. Was it the arrival of data or perhaps an error. But at least your application didn't spend all day in a CPU intensive loop waiting for something to happen. Because of the number of different things that can happen the Comm32 control has a property called CommEvent. Whenever an OnComm event occurs you can interrogate the CommEvent property and that tells you what happened. Here's a more useful OnComm event.

Private Sub Comm1_OnComm( )

      Select Case Comm1.CommEvent

            Case comEvReceive

' Now this is quite useful. Any data arriving at the com
' port will be placed into the textbox.

                  Do While Comm1.InbufferCount > 0
                         Text1.Text = Text1.Text & Comm1.Input
                  Loop


            Case Is > 1000

' The CommEvent property always returns a numerical value.
' Whenever the CommEvent property returns a number
' above 1000 then you know that an error occurred.

                   Text2.Text = "Some ComPort Error occurred"

             Case Else

' What happened? It wasn't the arrival of data - and it wasn't
'
an error. See the ' CommEvent property for a full listing
' of all the events and errors.

      End Select

End Sub

In the above example we just handled two eventualities. The arrival of data or an error. Everything else would be ignored. There are quite a few different event values that can be returned by the CommEvent property as well as a number of different errors. See the CommEvent page.

We'd also suggest downloading our code samples they're very simple, fully functional, 'event driven' applications written in VB6, VB.Net and C#.

 

 

Copyright (c) 2010 Axis Controls Ltd