Click here to Skip to main content
15,896,118 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to use bytes in bytes buffer? Pin
Member 474292223-Jul-09 23:41
Member 474292223-Jul-09 23:41 
AnswerRe: How to use bytes in bytes buffer? Pin
Muhammad Mazhar23-Jul-09 23:45
Muhammad Mazhar23-Jul-09 23:45 
GeneralRe: How to use bytes in bytes buffer? Pin
Member 474292223-Jul-09 23:52
Member 474292223-Jul-09 23:52 
GeneralRe: How to use bytes in bytes buffer? Pin
harold aptroot24-Jul-09 4:06
harold aptroot24-Jul-09 4:06 
GeneralRe: How to use bytes in bytes buffer? Pin
musefan24-Jul-09 0:03
musefan24-Jul-09 0:03 
GeneralRe: How to use bytes in bytes buffer? Pin
Member 474292224-Jul-09 1:14
Member 474292224-Jul-09 1:14 
AnswerRe: How to use bytes in bytes buffer? Pin
0x3c024-Jul-09 0:39
0x3c024-Jul-09 0:39 
AnswerRe: How to use bytes in bytes buffer? Pin
Luc Pattyn24-Jul-09 0:49
sitebuilderLuc Pattyn24-Jul-09 0:49 
Hi,

this is what I would write:

List<byte> list=new List<byte>();
list.Add(a);
list.Add(b);
list.Add(c);
writeWithXor(port, list);
...
public void writeWithXor(SerialPort port, List<byte>list) {
    int xor=0;
    foreach(byte b in list) xor^=b;
    list.Add((byte)xor);
    port.Write(list.ToArray());
    list.Clear();
}


This way you don't have the hassle of counting bytes and allocating the right array; and you can reuse
writeWithXor() for any amount of data that needs to be followed by a 'checksum'; and of course I would keep the serial port open, probably as long as my app is running.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.

QuestionHow to make a Component like MSN status label? Pin
Don.Y23-Jul-09 23:19
Don.Y23-Jul-09 23:19 
AnswerRe: How to make a Component like MSN status label? Pin
DaveyM6923-Jul-09 23:21
professionalDaveyM6923-Jul-09 23:21 
AnswerRe: How to make a Component like MSN status label? Pin
Muhammad Mazhar23-Jul-09 23:38
Muhammad Mazhar23-Jul-09 23:38 
AnswerRe: How to make a Component like MSN status label? Pin
Tamer Oz24-Jul-09 0:21
Tamer Oz24-Jul-09 0:21 
Questiona strange problem with windows service Pin
saeidfarahi23-Jul-09 22:53
saeidfarahi23-Jul-09 22:53 
AnswerRe: a strange problem with windows service Pin
musefan23-Jul-09 23:17
musefan23-Jul-09 23:17 
AnswerRe: a strange problem with windows service Pin
DoctorMick23-Jul-09 23:38
DoctorMick23-Jul-09 23:38 
GeneralRe: a strange problem with windows service Pin
musefan23-Jul-09 23:42
musefan23-Jul-09 23:42 
GeneralRe: a strange problem with windows service Pin
DoctorMick24-Jul-09 0:11
DoctorMick24-Jul-09 0:11 
GeneralRe: a strange problem with windows service Pin
musefan24-Jul-09 0:16
musefan24-Jul-09 0:16 
QuestionACOS3-24 smart card write operation C# Pin
GauravKP23-Jul-09 22:39
professionalGauravKP23-Jul-09 22:39 
AnswerRe: ACOS3-24 smart card write operation C# Pin
Nagy Vilmos23-Jul-09 23:27
professionalNagy Vilmos23-Jul-09 23:27 
AnswerRe: ACOS3-24 smart card write operation C# Pin
stancrm24-Jul-09 0:07
stancrm24-Jul-09 0:07 
QuestionIntPtr to Image ? Pin
Mohammad Dayyan23-Jul-09 22:38
Mohammad Dayyan23-Jul-09 22:38 
AnswerRe: IntPtr to Image ? Pin
stancrm23-Jul-09 22:55
stancrm23-Jul-09 22:55 
QuestionPatching classes/codes Pin
Member 143923423-Jul-09 21:20
Member 143923423-Jul-09 21:20 
AnswerRe: Patching classes/codes Pin
Christian Graus23-Jul-09 21:36
protectorChristian Graus23-Jul-09 21:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.