|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Help needed using sample RS232 class to read from serial portWriting to the port works fine. (I've got hyperterminal on the other comm port and a crossover cable between COM1 and COM2) The port is opened with: Public switchcom As New Rs232 switchcom.Open(2, 57600, 8, Rs232.DataParity.Parity_None, Rs232.DataStopBit.StopBit_1, 512) But reading is giving me no end of trouble. Since there are no com port events anymore in dot NET, I wish to run a timer and read the entire input buffer as a string. I found some sample code and interpreted it like this: Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim j As Integer Dim i As Integer Dim strDataIn As String Dim DataIn As Array Try j = 0 While switchcom.Read(1) <> -1 DataIn(j) = Asc(switchcom.InputStreamString.Chars(0)) j += 1 strDataIn = "" For i = 0 To DataIn.Length - 1 strDataIn &= DataIn(i) Next End While Catch ' // "Switcher buffer empty" End Try TextBox1.Text = strDataIn End Sub But I can't get anything in the port. Furthermore, when option strict is on, the compiler complains about "late binding" on DataIn(j). I'm still pretty new to this stuff: Should I just turn Option Strict off, or do I need to fix something? Any help appreciated, thanks. -- Dave Harry the .NET Framework contains (again) a serial-port component... much easier
to use :-) Show quoteHide quote "Dave Harry" <DaveHa***@please.keep.replies.in.the.newsgroup> wrote in message news:e9NFRtjTGHA.1868@TK2MSFTNGP09.phx.gbl... >I found the RS232 class from MS's 101 VB samples. > > Writing to the port works fine. (I've got hyperterminal on the other comm > port and a crossover cable between COM1 and COM2) > The port is opened with: > > Public switchcom As New Rs232 > switchcom.Open(2, 57600, 8, Rs232.DataParity.Parity_None, > Rs232.DataStopBit.StopBit_1, 512) > > > But reading is giving me no end of trouble. Since there are no com port > events anymore in dot NET, I wish to run a timer and read the entire input > buffer as a string. I found some sample code and interpreted it like this: > > Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Timer1.Tick > > Dim j As Integer > Dim i As Integer > > Dim strDataIn As String > Dim DataIn As Array > > Try > j = 0 > While switchcom.Read(1) <> -1 > DataIn(j) = Asc(switchcom.InputStreamString.Chars(0)) > j += 1 > > strDataIn = "" > For i = 0 To DataIn.Length - 1 > strDataIn &= DataIn(i) > Next > > End While > > Catch > ' // "Switcher buffer empty" > End Try > > TextBox1.Text = strDataIn > > End Sub > > > But I can't get anything in the port. Furthermore, when option strict is > on, the compiler complains about "late binding" on DataIn(j). I'm still > pretty new to this stuff: Should I just turn Option Strict off, or do I > need to fix something? > > Any help appreciated, thanks. > > -- > Dave Harry > Hi,
Visual Studio 2005 has the System.IO.Ports namespace. Earlier versions did not. I presume, because of the question, that OP is using VS2003. -- Richard Grier, MVP Hard & Software Author of Visual Basic Programmer's Guide to Serial Communications, Fourth Edition, ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004. See www.hardandsoftware.net for details and contact information. Hi,
>> But reading is giving me no end of trouble. Since there are no com portevents anymore in dot NET, I wish to run a timer and read the entire input buffer as a string. I found some sample code and interpreted it like this: << Depends on the class/object that you are using. If you download DesktopSerialIO.dll from my homepage, you will see them (and the use is straight forward). Dick -- Richard Grier, MVP Hard & Software Author of Visual Basic Programmer's Guide to Serial Communications, Fourth Edition, ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004. See www.hardandsoftware.net for details and contact information. Thank you Dick
That seems to be just what I want. The finer points of using it are coming to me slowly, but it seems to have most everything. -- Show quoteHide quoteDave Harry "Dick Grier" <dick_grierNOSPAM@.msn.com> wrote in message news:upz7ZYpTGHA.4772@TK2MSFTNGP09.phx.gbl... > Hi, > >>> > But reading is giving me no end of trouble. Since there are no com port > events anymore in dot NET, I wish to run a timer and read the entire input > buffer as a string. I found some sample code and interpreted it like this: > << > > Depends on the class/object that you are using. If you download > DesktopSerialIO.dll from my homepage, you will see them (and the use is > straight forward). > > Dick > > -- > Richard Grier, MVP > Hard & Software > Author of Visual Basic Programmer's Guide to Serial Communications, Fourth > Edition, > ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004. > See www.hardandsoftware.net for details and contact information. >
VB.NET - Issues with VB.NET FTP Class to UNIX FTP Server
Reading Excel in VB.NET SQL Distinct Learning - displaying selection in pictureboxes Null, DBNull, Nothing, VBNullstring Create 30 Day trial version how to avoid broken references when give out projects Opening a query in MS Access with parameters using VB.net Help with Access Database and tables XQuery amd SQL 2005 |
|||||||||||||||||||||||