cdholding image

comm32 home
comm32 download
comm32 forum
buy comm32

EOFChar

Sets or Retrieves the character that will indicate EOF (End of File) - Used in conjuntion with the EOFEnable property

Available at Design time and Runtime. Can also be changed while the port is open.

Only available using the Comm32 ocx. Not supported by MSComm32

         Syntax object.EOFChar = value
     
  object Name of the communications control.
  value A decimal expression. Ascii value 0 to 255 Default is 26
     
  Examples  
    object.EOFChar = 4 '// Set the value (Look for the EOT char)
       
   

n = object.EOFChar

'// Retrieves the value
       

Remarks:

MSComm32 is old and therefore still uses the standard Win3/Dos EOF char (Ascii char 26). Modern file systems do not require or use the EOF character to indicate the End of File but some communications protocols may use EOF or, more likely, some other ascii character as a way to indicate 'End of Message' or 'End of Transmision'.

The Ascii table has a number of such characters such as ETX ( 3 ) and EOT ( 4 ) and Comm32 therefore allows you to use any ascii character.

See also the EOFEnable property. If enabled this property will cause an OnComm event to be triggered when the EOFChar is read by the Input property. It is important to note that the OnComm event is raise AFTER the character was read by the Input property.


Example Lets assume we're receiving an unknown amount of data. We don't know how much data but in this example we do know that it'll be terminated by the EOF character. Maybe we're running at a very high baud rate so we don't want to waste processor time inspecting each character to see if it's EOF. We'll simply store all incoming data in a textbox and use the evEof OnComm event to tell us when the EOF character has arrived.

'// InputLen = 0              we will read all available chars from the buffer each time we call Input.
'// RThreshold = 1          we want OnComm events when any data arrives.
'// EOFEnable = True     
'// EOFChar = 26          This is the default EOF character.

Private Sub Comm1_OnComm

       Select Case Comm1.CommEvent

              Case evReceive
                     Text1.Text = Text1.Text & Comm1.Input

              Case evEof
                      '// When this event occurs it means the EOFchar was received and added to Text1
                      '// We can now do any processing we want with the data.
       End Select
End Sub

Remember - Using our Comm32 you can change the value of the EOFChar (MSComm32 doesn't let you do that) But, also interesting is that you can even change it while the port is open sending and receiving data. Imagine you want to receive packets of data which have special start and end characters. A common example would be packets of data with STX (Ascii 2) to indicate the start and ETX (Ascii 3) to indicate the end. You could start of with EOFChar = 2 and ignore all data untill you get the evEof event waking you up to the fact that STX was received indicating the start of a packet of data. At that moment switch the EOFChar to 3 (so that you'll get the next evEof event when ETX arrives) and start saving the data waiting for the evEof event to happen again telling you that you that ETX arrived and you know, without looking, that you have a whole correctly formatted STX - to - ETX framed packet of data ready to process. (This would work best if you set InputLen to 1)

 

See also the properties evtChar and evtCharEnable properties. Neither of these is available using the MSComm32 control. They differ from EOFChar/EOFEnable in that an evtChar OnComm event is generated independent of the Input property. The evtChar event is triggered as soon as the evtChar is detected in the incoming data stream. Using this property you could set RThreshold=0 so that no evReceive events are ever triggered and simply wait for the evtChar event to indicate that the evtChar has arrived and is waiting to be read from the buffer.

For those users who understand the windows communications API - the evtChar and evtCharEnable properties are directly connected to the DCB EvtChar property and the RXFlag CommEvent.

 
Copyright (c) 2010 Axis Controls Ltd