读/写字符串到com端口 [英] Read/ write string to com port

查看:74
本文介绍了读/写字符串到com端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,


我在asp.net中编写代码来读取或写入com端口(COM1)中的字符串。但是当我运行程序时我没有得到任何输出.Below是我的代码。如何检查我在com端口发送的字符串是否可用于com端口。


private SerialPort port = new SerialPort(" COM1" ,9600,Parity.None,8,StopBits.One);

port.Open();



// port.Write(He);


port.Close();

port.Open();

port.ReadTo(" e);

Console.WriteLine(port.ReadLine());


Hi friends,

I have written code in asp.net to read or write string in com port(COM1).But when i run the program i am not getting any output .Below is my code .How can i check the string which i have send in com port is available in com port for read.

private SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
port.Open();



// port.Write("He");

port.Close();
port.Open();
port.ReadTo("e");
Console.WriteLine(port.ReadLine());


please reply as soon as possible.........................Thanx in advance for reply...

推荐答案

是否可以使用asp.net中的句柄获得serialdatareceived args?如果是这样,试试吧,也许还没有收到它。你总是可以在google上查看例子。


ex收到的数据处理程序:

Is it possible to have a serialdatareceived args, with the handles in asp.net? If so, try that, maybe its not receiving it yet. You can always look up examples on google.


ex of the data received handler:

展开 | 选择 | Wrap | 行号


你怎么知道它不工作?

你知道代码将在服务器的COM端口上运行,而不是在计算机上运行正确查看网页?
How do you know it is not working?
You know that code will be run on the server''s COM port and not on the computer viewing the webpage right?


因为在我写完port.write语句后


Console.WriteLine(port.ReadExisting());并且在我的控制台窗口中进行任何输出;


2)即使我使用了

port.DataReceived + = new SerialDataReceivedEventHandler(port_DataReceived);



private void port_DataReceived(object sender,SerialDataReceivedEventArgs e)

{

//显示所有传入的数据端口的缓冲区

Console.WriteLine(port.ReadExisting());

}

此句柄不会触发;



Thanx回复。如果你能提供更多解决方案,我等待你的建议。
because after port.write statement i have written

Console.WriteLine(port.ReadExisting()); and in my console window m nog getting any out put;

2)even if i used
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);


private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// Show all the incoming data in the port''s buffer
Console.WriteLine(port.ReadExisting());
}
this handle does not fire;


Thanx for reply .if you can provide more solution i am waiting to ur suggestion.


这篇关于读/写字符串到com端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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