Hi guys! :p
I'm using c232 class to read data from a keypad and I’m having Read TimeOut error, when run this command
c232.Read(1)
Do it can be due to a malfunctioning device?
Do somebody know have any idea on way to solve it? :confused:
Printable View
Hi guys! :p
I'm using c232 class to read data from a keypad and I’m having Read TimeOut error, when run this command
c232.Read(1)
Do it can be due to a malfunctioning device?
Do somebody know have any idea on way to solve it? :confused:
Have you set up your connection settings properly (baud, stop bits, parity etc...)?
Here my code ...
VB Code:
Imports Microsoft.VisualBasic Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " 'Ba Bla bla #End Region Friend Const PORTNUM As Integer = 1 Friend Const BAUDRATE As Integer = 9600 Friend Const DATABIT As Integer = 8 Friend Const PARITY As clsRs232.DataParity = clsRs232.DataParity.Parity_None Friend Const STOPBIT As clsRs232.DataStopBit = clsRs232.DataStopBit.StopBit_1 Friend ReadOnly RESET_STRING As String = Chr(1) & "01" & Chr(11) & Chr(4) & Chr(13) Friend InitString As String = Chr(1) & "01" & Chr(11) & Chr(4) & Chr(13) Private Const BufferSize As Integer = 12 Private WithEvents c232 As clsRs232 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load c232 = New clsRs232 txtOutPut.AppendText("Opening port ..." & Environment.NewLine) c232.Open(PORTNUM, BAUDRATE, DATABIT, PARITY, STOPBIT, BufferSize) c232.EnableEvents() txtOutPut.AppendText("Send init string :" & InitString & Environment.NewLine) c232.Write(InitString) txtOutPut.AppendText("Reseting " & RESET_STRING & Environment.NewLine) c232.Write(RESET_STRING) End Sub Private Sub c232_CommEvent(ByVal source As clsRs232, ByVal Mask As clsRs232.EventMasks) Handles c232.CommEvent Dim Buffer As String = "" txtOutPut.AppendText("CommEvent occur" & Environment.NewLine) If Not c232.IsOpen Then txtOutPut.AppendText("c232 is not open" & Environment.NewLine) Exit Sub End If txtOutPut.AppendText("c232 IS open" & Environment.NewLine) txtOutPut.AppendText("Read buffer ..." & Environment.NewLine) Try 'Throw a Time out error txtOutPut.AppendText("Read -> '" & [COLOR=Red]c232.Read(BufferSize)[/COLOR].ToString & "'" & Environment.NewLine) Catch ex As Exception MessageBox.Show(ex.Message) End Try txtOutPut.AppendText("Reading stream string ..." & Environment.NewLine) Buffer = c232.InputStreamString txtOutPut.AppendText("Buffer -> '" & Buffer & "'" & Environment.NewLine) c232.ClearInputBuffer() txtOutPut.AppendText("End Comm Event" & Environment.NewLine) End Sub End Class
Ok .. forget it .. i've found what was the problem ...