Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I want to write one by one byte at comport from byte array.

I have data like this:
C#
byte[] tempdata = FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 02 80 00 00 82 CD

I want to write FF then write FF.... one by one not hole string together like this
C#
comPort.Write(tempdata,0,tempdata.Length);
I don't want to write from this code.

I use this code:
C#
for (int i = 0; i < tempdata.Length; i++)
                {
                    comPort.Write(tempdata,i,i);
                }
But this will not work i don'e know how to write this as i want.
Posted
Updated 3-Jan-12 3:47am
v2

Just change one parameter
C#
for (int i = 0; i < tempdata.Length; i++)
{
    comPort.Write(tempdata, i, 1);
}

to write 1 byte at a time instead of i bytes.
 
Share this answer
 
Comments
[no name] 3-Jan-12 9:57am    
my 5 for the faster.
Regards
lukeer 4-Jan-12 2:10am    
Thank you.
Use this:

C#
for (int i = 0; i < tempdata.Length; i++)
                {
                    comPort.Write(tempdata,i,1); // Here 1 instead i
                }


Regards
 
Share this answer
 
Comments
lukeer 4-Jan-12 2:12am    
Have 5 for agreeing about the solution.
It looks like academic question; not related to live project. Remove it from this list.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900