03-14-2007 10:30 AM
03-15-2007 09:09 AM
03-16-2007 09:53 AM
Hi Brandon,
We tried the example code you mentioned (SimpleAcynchronousReadWrite) but haven't had a lot of success with it. It's not doing what we hoped it would do which is to sync up to the data records sent by our product. The data rate is slow (4800 baud) with 106 bytes of data sent every .4 seconds continuously.
Alex
03-20-2007 07:41 AM
03-20-2007 08:01 AM
Hi Ebele,
Our product sends record data at the rate of 106 bytes (hex, not ascii) every .4 second without quierying so our com routine is just listens. We tried "ReadByteArray()" called at a rate to read every record and it keeps losing data. A data record starts with three 0's, which is how we sync to it. What happens is we keep losing the start of the data record and don't know why. We also tried "BeginRead" and "OnReadComplete" with similar unsuccessful results.
Thanks,
Alex
03-22-2007 02:07 PM - edited 03-22-2007 02:07 PM
Message Edited by _Belle on 03-22-2007 02:09 PM
03-22-2007 04:11 PM
Hi Ebele,
Thanks for your reply. We have a product called a "tool" that is used to locate the drill bit for oil/gas/coal drilling. The tool sends back data to a power supply that then sends data to our GUI running on a PC. The tool data is sent as a record of 106 bytes and it is sent every .4 seconds or so. The interface to the power supply can also be a USB connection but the data rates are the same. The serial port transmits at 4800 baud, no parity, 1 stop, and no handshaking.
The code I played with uses the "ReadByteArray" method and it is called after a timer event. I've played with the interval and timeout parameters and got it so it could read good but still would start missing records and sometimes hangup.
Thanks, Alex.
Here is a code snipet:
Private Sub RecPort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RecPort.TextChanged
Dim comstr As String
If RecPort.SelectedItem <> Nothing Thencomstr = RecPort.SelectedItem
If ComPort <> comstr ThenComPort = comstr
If VisaResourceStr <> Nothing ThenmbSession.Dispose()
End If Select Case ComPort Case "COM1"VisaResourceStr = "ASRL1::INSTR"
Case "COM2"VisaResourceStr = "ASRL2::INSTR"
Case "COM3"VisaResourceStr = "ASRL3::INSTR"
Case "COM4"VisaResourceStr = "ASRL4::INSTR"
Case "COM5"VisaResourceStr = "ASRL5::INSTR"
End Select If VisaResourceStr <> Nothing Then Dim SerSess As New VisaNS.SerialSession(VisaResourceStr)mbSession = SerSess
'mbSession.Timeout = 10000SerSess.BaudRate = 4800
SerSess.StopBits = StopBitType.One
SerSess.Parity = Parity.None
SerSess.FlowControl = FlowControlTypes.None
SerSess.Timeout = 100
SerSess.DefaultBufferSize = 2048
End If End If End If End SubPrivate Sub Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click
Timer1.Interval = 300
Timer1.Start()
End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tickread_tool()
End Sub Private Sub read_tool() Dim rbarray() As ByteIf VisaResourceStr <> Nothing Then Try
rbarray = mbSession.ReadByteArray(106)
Catch ex As Exception 'MessageBox.Show("Exception: " & ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.None) 'Exit Sub End Try If (Not (rbarray Is Nothing)) Thenib.Copy(rbarray, ib, rbarray.Length)
copy_records(ib, rbarray.Length)
End If Else 'MessageBox.Show("Enter a valid COM port", "Error", MessageBoxButtons.OK, MessageBoxIcon.None) End If End Sub03-23-2007 09:13 AM
03-23-2007 01:52 PM