如何使用C#编写串口 [英] How to write serial port using C#

查看:96
本文介绍了如何使用C#编写串口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用c#window应用程序创建了一个串口通信应用程序但无法为串口编写代码。我有数组中的数据,但无法在串口中写入该数据数据..



请尽快回复我..



我尝试了什么:



列出

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

推荐答案

尝试:

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





这些所有信息都在一个名为array1的数组中声明,然后在串行写入端口中调用该数组1



那你为什么不告诉我们昨天这是一个整数列表?

他们是微不足道的处理!



"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();


这篇关于如何使用C#编写串口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆