Questions about sending 128 bytes (quickly)
Questions about sending 128 bytes (quickly)
Questions about sending 128 bytes (quickly)
Questions about sending 128 bytes (quickly)
Questions about sending 128 bytes (quickly)
Questions about sending 128 bytes (quickly) Questions about sending 128 bytes (quickly) Questions about sending 128 bytes (quickly) Questions about sending 128 bytes (quickly) Questions about sending 128 bytes (quickly) Questions about sending 128 bytes (quickly) Questions about sending 128 bytes (quickly) Questions about sending 128 bytes (quickly)
Questions about sending 128 bytes (quickly) Questions about sending 128 bytes (quickly)
Questions about sending 128 bytes (quickly)
Go Back  Xtreme Visual Basic Talk > > > Questions about sending 128 bytes (quickly)


Reply
 
Thread Tools Display Modes
  #1  
Old 08-13-2010, 08:55 AM
bonedoc bonedoc is offline
Junior Contributor
 
Join Date: Mar 2006
Posts: 376
Default Questions about sending 128 bytes (quickly)


I have 128 bytes to send through the serial port. As of now, the information is a continuous string of 128 values that are 3 digit numbers that do not exceed a byte each (in other words they are all 255 or less, and the number 3 is 003).

I need to send out 128 bytes consecutively and I am a bit confused as how to do it.

Should I somehow create a byte array (dont know how ) and then use:

SerialPort1.Write(New Byte() {"data"}, 0, 128)

This would be the easiest, but I am not sure how I should break up the string so that it knows that each 3 DECIMALS in the string is a BYTE to send.

Any recommendations?
Reply With Quote
  #2  
Old 08-13-2010, 09:34 AM
bonedoc bonedoc is offline
Junior Contributor
 
Join Date: Mar 2006
Posts: 376
Default

Is this appropriate?

Code:
  Dim SerialBytes(128) As Byte
        Dim ByteCounter As Int16 = 0

        For Count As Integer = 0 To 128 Step 3
            SerialBytes(ByteCounter) = Convert.ToInt16(MyData.Substring(Count, 3))
            ByteCounter = ByteCounter + 1
        Next

        SerialPort1.Open()
        SerialPort1.Write(SerialBytes, 0, 128)
        SerialPort1.Close()
Reply With Quote
  #3  
Old 08-13-2010, 09:47 AM
Qua's Avatar
QuaQuestions about sending 128 bytes (quickly) Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

Your idea is correct. There is minor issues though such as your loop only filling in 128 / 3 spots. I would personally use Byte.Parse instead of Convert.ToInt16():
Code:
Dim myStringData As String = "12312313123andsofroth"
Dim bytesToSend(128) As Byte

for count as integer = 0 to 128 * 3 step 3
   dim currentByte As Byte = Byte.Parse(myStringData.SubString(count, 3))
   bytesToSend(count / 3) = currentByte
next

SerialPort1.Open()
SerialPort1.Write(bytesToSend, 0, 128)
SerialPort1.Close()
Also, can you guarantee that the string containing the numbers will have a length exactly equaling 128*3? If not, then the your code needs to take this into consideration.
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Questions about sending 128 bytes (quickly)
Questions about sending 128 bytes (quickly)
Questions about sending 128 bytes (quickly) Questions about sending 128 bytes (quickly)
Questions about sending 128 bytes (quickly)
Questions about sending 128 bytes (quickly)
Questions about sending 128 bytes (quickly) Questions about sending 128 bytes (quickly) Questions about sending 128 bytes (quickly) Questions about sending 128 bytes (quickly) Questions about sending 128 bytes (quickly) Questions about sending 128 bytes (quickly) Questions about sending 128 bytes (quickly)
Questions about sending 128 bytes (quickly)
Questions about sending 128 bytes (quickly)
 
Questions about sending 128 bytes (quickly)
Questions about sending 128 bytes (quickly)
 
-->