Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have made a serial port communication application using c# window application but unable to write code for serial port . I have data in array , but not able to write that array of data in serial port..

Please Reply me soon..

What I have tried:

List
Posted
Updated 18-Sep-16 3:11am
v14

1 solution

Try:
SerialPort mySerialPort = new SerialPort();
mySerialPort.BaudRate = ...  // Set your parameters;
...
mySerialPort.Open();
byte[] data = ... // your byte data;
mySerialPort.Write(data, 0, data.Length);


"These all information i declare in an array named array1 ,then calling that array1 in serial write port"

So why didn't you tell us yesterday "it's an List of integers"?
They are trivial to deal with!
List<int> array1 = new List<int>();
array1.Add(1);
array1.Add(666);
array1.Add(int.MaxValue);
byte[] data = array1.SelectMany(BitConverter.GetBytes).ToArray();
 
Share this answer
 
v2
Comments
ADI@345 17-Sep-16 10:18am    
where i have to call my array ..
OriginalGriff 17-Sep-16 10:26am    
byte[] data = ... // your byte data;
ADI@345 17-Sep-16 10:38am    
Actually i want to know that,
List array1 = new List();
I have to write this array1 in serialWrite
OriginalGriff 17-Sep-16 10:43am    
What is it a list of, and how do you convert it to serial data - I don't know this because I can't see your screen. So give me information to work from and I'll try to help you - but a Generic List that doesn't even tell me what it's a list of doesn't help at all!
ADI@345 17-Sep-16 10:47am    
I am unable to post my code here..

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