Quote Originally Posted by David.Poundall
OK - just a couple of points. I am referring to a comprehensive PLC comms routine that I have been successfully running for the past 5 years. But as you may imagine it was written five years ago. Anyway - enough of my problem and on to yours.

Here are a few snippets of my code that works. Unlike yours it works in binary mode though.

My receive code just unloads the Rxbuff array. The data received event fires when I receive the correct number of incoming bytes as PLC comms is quite predictable.

VB Code:
  1. ' ---------------------------------------------------------------------
  2. ' Globals
  3. Public Rxbuff() As Byte
  4.  
  5. ' ---------------------------------------------------------------------
  6. ' Code behind the Form containing the comm control
  7. Private Sub MSComm1_OnComm()
  8.      Select Case MSComm1.CommEvent          
  9.           Case comEvReceive         ' Received RThreshold # of chars.
  10.                Rxbuff() = MSComm1.Input
  11.                Call HandleReceivedData              
  12.      End Select
  13. End Sub
  14.  
  15. ' ---------------------------------------------------------------------
  16. ' called at comms kickoff
  17. Sub InitialiseComms()
  18.      frmPlcComms.MSComm1.CommPort = ComPort
  19.      frmPlcComms.MSComm1.Settings = "9600,E,7,1"
  20.      frmPlcComms.MSComm1.PortOpen = True
  21.      frmPlcComms.MSComm1.DTREnable = True
  22.      frmPlcComms.MSComm1.RTSEnable = True
  23.      frmPlcComms.MSComm1.InputMode = comInputModeBinary
  24.      frmPlcComms.MSComm1.InputLen = 0       'Forces entire buffer read
  25. End Sub
  26.  
  27. ' ---------------------------------------------------------------------
  28. ' send code
  29. Sub Transmit()
  30.     Dim txbuff() As Byte, k as long
  31.     Dim SendBuffer(1) As Variant                       ' VIP for sending Binary
  32.  
  33.     frmPlcComms.MSComm1.InBufferCount = 0     'Flush the RX Buffer
  34.          
  35.     ' Dim the TX buffer
  36.     redim txbuff(0 to 100)
  37.  
  38.     k = 0
  39.     ' Send pre-amble
  40.     txbuff(k) = &H2   : k = k+1
  41.     txbuff(k) = &H31  : k = k+1
  42.     txbuff(k) = &H31  : k = k+1
  43.  
  44.     ' Add further text to the byte buffer as byte...
  45.  
  46.     ' Trim the TXbuffer
  47.     ReDim txbuff(0 to k-1)
  48.  
  49.     SendBuffer(1) = txbuff()
  50.     frmPlcComms.MSComm1.Output = SendBuffer(1)
  51.  
  52.     ' Set the  RX buffer length to the value expected from the PLC
  53.     frmPlcComms.MSComm1.RThreshold = 1          ' Note - Not typical.
  54.    
  55. End Sub

Something in that lot may jog your thinking.
Yes, the key was the "RThreshold" and I had found it (almost at the same time you posted it) at http://www.programmers-corner.com/sourcecode/111.


VB Code:
  1. 'enable the oncomm event for every reveived character
  2.     .RThreshold = 1