C#.net中的串行通信 [英] Serial Communication in C#.net

查看:62
本文介绍了C#.net中的串行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,

我正在开发一个使用C#.net2.0 FrameWork的应用程序,其中与GSM调制解调器的通信是强制性的。我的应用程序的主要目的是它应该与GSM moden交互发送消息以及接收消息。目前我在C#.net2.0中使用mscomm。问题是我可以将消息发送到串口(RS-232)但无法与调制解调器交互。

任何建议Plz。


I am developing an application using C#.net2.0 FrameWork ,in which communication with GSM modem is mandatory.The main aim of my application is it should interact with GSM moden for sending messages and as well as receiving messages .Presently i am mscomm available in C#.net2.0 .the problem is i can just send the message to the serialport(RS-232) but unable to interact with the modem .
Any suggestions Plz.

推荐答案

您好,


请将您的代码段发布到您的下一个.. as这将更容易帮助你..我们将帮助你验证你的代码..祝你好运我的fren ..:)
Hi there,

pls post you code segment in your next.. as that will be alot more easier to assist you.. we will help you to validate your code.. good luck my fren.. :)


hi sashi,

首先感谢你们的支持,我正在给出关于mscomm的部分代码,以便我可以更加受益

*****************代码*** ******************

private void InitComPort()

{

//将com端口设置为1

com.CommPo rt = 1;


//此端口已经打开,关闭它以重置它。

if(com.PortOpen)com.PortOpen = false;


//收到数据时触发OnComm事件

com.RThreshold = 1;


//将端口设置为9600波特,无奇偶校验位,8个数据位,1个停止位(全部标准)

com.Settings =" 9600,n,8,1;


//不使用握手

com.Handshaking = MSCommLib.HandshakeConstants.comNone;
< br $>
//不要乱用字节数组,只能处理简单数据(字符AZ和数字)

com.InputMode = MSCommLib.InputModeConstants.comInputModeText;



//使用com.Input时读取整个等待数据

com.InputLen = 0;


//不要丢弃空值,0x00是一个有用的字节

com.NullDiscard = false;


//附上事件处理程序

com.OnComm + = new System.EventHandler(this.OnComm);


//打开com端口

com.PortOpen = true;

}


private void OnComm(对象发送者,EventArgs e)// MSCommLib OnComm事件处理程序

{

//如果数据在缓冲区中等待,则处理它。


if(com.InBufferCount> 0)ProcessComData((string)com.Input);

}


private void ProcessComData(字符串输入)

{

//将传入数据发送到富文本框

rtfTerminal.AppendText(输入+" \ n");

}


非常感谢

msreddy
hi sas
First thanks for ur support,i am giving my partial code regarding mscomm so that i may more benifit
*****************code*********************
private void InitComPort()
{
// Set the com port to be 1
com.CommPort = 1;

// This port is already open, close it to reset it.
if (com.PortOpen) com.PortOpen = false;

// Trigger the OnComm event whenever data is received
com.RThreshold = 1;

// Set the port to 9600 baud, no parity bit, 8 data bits, 1 stop bit (all standard)
com.Settings = "9600,n,8,1";

// No handshaking is used
com.Handshaking = MSCommLib.HandshakeConstants.comNone;

// Don''t mess with byte arrays, only works with simple data (characters A-Z and numbers)
com.InputMode = MSCommLib.InputModeConstants.comInputModeText;



// Read the entire waiting data when com.Input is used
com.InputLen = 0;

// Don''t discard nulls, 0x00 is a useful byte
com.NullDiscard = false;

// Attach the event handler
com.OnComm += new System.EventHandler(this.OnComm);

// Open the com port
com.PortOpen = true;
}

private void OnComm(object sender, EventArgs e) // MSCommLib OnComm Event Handler
{
// If data is waiting in the buffer, process it.

if (com.InBufferCount > 0) ProcessComData((string) com.Input);
}

private void ProcessComData(string input)
{
// Send incoming data to a Rich Text Box
rtfTerminal.AppendText(input + "\n");
}

many thanks
msreddy


HI,

我正在使用C#.net2.0 FrameWork开发一个应用程序,其中

与GSM调制解调器的通信是强制性的。我的应用程序的主要目的是


它应该与GSM模式交互以发送消息以及


接收消息。目前我是mscomm在C#.net2.0中可用。


问题是我可以发送消息到th e serialport(RS-232)但无法与调制解调器互动


任何建议Plz。


问候

nmsreddy

__________________________________________________ ________________________

hi sashi,

首先感谢您的支持,我给予了关于mscomm的部分代码如此


我可能更有利

*****************代码* ********************

private void InitComPort()

{

//将com端口设置为1

com.CommPort = 1;


//此端口已打开,关闭它以重置它。

if(com.PortOpen)com.PortOpen = false;


com .RThreshold = 1;


//将端口设置为9600波特,无奇偶校验位,8个数据位,1个停止位(所有


标准)

com.Settings =" 9600,n,8,1" ;;


//不使用握手

com.Handshaking = MSCommLib.HandshakeConstants.comNone;


//不要乱用字节数组,只能处理简单的数据(字符AZ


和数字)

com.InputMode = MSCommLib.InputModeConstants.comInputModeText;



//在com时读取整个等待数据。输入使用

com.InputLen = 0;


//不要丢弃空值,0x00是一个有用的字节

com.NullDiscard = false;


//附加事件处理程序

com.OnComm + = new System.EventHandler(this.OnComm);


//打开com端口

com.PortOpen = true;

}


private void OnComm(对象发送者,EventArgs e)// MSCommLib OnComm事件


处理程序

{

//如果数据在缓冲区中等待,则处理它。


if(com.InBufferCount> 0) ProcessComData((string)com.Input);

}


private void ProcessComData(字符串输入)

{

//将传入数据发送到富文本框

rtfTerminal.AppendText(输入+" \ n");

}


非常感谢

msreddy

I am developing an application using C#.net2.0 FrameWork ,in which

communication with GSM modem is mandatory.The main aim of my application is

it should interact with GSM moden for sending messages and as well as

receiving messages .Presently i am mscomm available in C#.net2.0 .the

problem is i can just send the message to the serialport(RS-232) but unable

to interact with the modem .
Any suggestions Plz.

with regards
nmsreddy
__________________________________________________ ________________________
hi sas
First thanks for ur support,i am giving my partial code regarding mscomm so

that i may more benifit
*****************code*********************
private void InitComPort()
{
// Set the com port to be 1
com.CommPort = 1;

// This port is already open, close it to reset it.
if (com.PortOpen) com.PortOpen = false;

// Trigger the OnComm event whenever data is received
com.RThreshold = 1;

// Set the port to 9600 baud, no parity bit, 8 data bits, 1 stop bit (all

standard)
com.Settings = "9600,n,8,1";

// No handshaking is used
com.Handshaking = MSCommLib.HandshakeConstants.comNone;

// Don''t mess with byte arrays, only works with simple data (characters A-Z

and numbers)
com.InputMode = MSCommLib.InputModeConstants.comInputModeText;



// Read the entire waiting data when com.Input is used
com.InputLen = 0;

// Don''t discard nulls, 0x00 is a useful byte
com.NullDiscard = false;

// Attach the event handler
com.OnComm += new System.EventHandler(this.OnComm);

// Open the com port
com.PortOpen = true;
}

private void OnComm(object sender, EventArgs e) // MSCommLib OnComm Event

Handler
{
// If data is waiting in the buffer, process it.

if (com.InBufferCount > 0) ProcessComData((string) com.Input);
}

private void ProcessComData(string input)
{
// Send incoming data to a Rich Text Box
rtfTerminal.AppendText(input + "\n");
}

many thanks
msreddy


这篇关于C#.net中的串行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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