在新的C#2005 Expres中通过串行端口传输'char'数组 [英] Transmitting a 'char' array thru serial port in new C# 2005 Expres

查看:87
本文介绍了在新的C#2005 Expres中通过串行端口传输'char'数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在新的C#2005中从串口发送一个6字节的char数组

Express:

com.Write(new string(new char [] {(char)34,(char)14,(char)192,(char)51,

(char)0,(char)0},0,6));


我从端口收到34,14,63,51,0,0因为我使用以下代码将Tx和Rx引脚相互连接

: br />

private void com_DataReceived(object sender,SerialDataReceivedEventArgs e)

{

bytes = com.BytesToRead;

if(bytes> = 6)

com.Read(buffer,0,bytes);

}


难以理解的是:在这个数组中,如果我用127或

替换192以下任何数字,我会将数组恢复原状。任何超过127的数字都是

收到63.


关于其潜在原因的任何想法?

I am trying to send a 6 byte char array from the serial port in new C# 2005
Express:
com.Write(new string(new char[] { (char)34, (char)14, (char)192, (char)51,
(char)0, (char)0 }, 0, 6));

I am receiving 34,14,63,51,0,0 from the port as I connected Tx and Rx pins
to each other by using the following code:

private void com_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
bytes = com.BytesToRead;
if (bytes >= 6)
com.Read(buffer, 0, bytes);
}

The hard thing to understand is: in this array if I replace 192 with 127 or
any number below I get the array back as it is. Any number above 127 is
received as 63.

Any ideas about the underlying reasons for this?

推荐答案

halukg< ha **** @ discussion.microsoft.com>写道:
halukg <ha****@discussions.microsoft.com> wrote:
我试图从新的C#2005串口发送一个6字节的char数组
快递:
com.Write(new string(new char [] { (char)34,(char)14,(char)192,(char)51,
(char)0,(char)0},0,6));

我我从端口接收34,14,63,51,0,0,因为我使用以下代码将Tx和Rx引脚相互连接:

private void com_DataReceived(object sender ,SerialDataReceivedEventArgs e)
{
bytes = com.BytesToRead;
if(bytes> = 6)
com.Read(buffer,0,bytes);
难以理解的是:在这个数组中,如果我用127替换192或
以下任何数字,我会将数组恢复原样。任何超过127的数字都会被收到63.

任何关于其潜在原因的想法?
I am trying to send a 6 byte char array from the serial port in new C# 2005
Express:
com.Write(new string(new char[] { (char)34, (char)14, (char)192, (char)51,
(char)0, (char)0 }, 0, 6));

I am receiving 34,14,63,51,0,0 from the port as I connected Tx and Rx pins
to each other by using the following code:

private void com_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
bytes = com.BytesToRead;
if (bytes >= 6)
com.Read(buffer, 0, bytes);
}

The hard thing to understand is: in this array if I replace 192 with 127 or
any number below I get the array back as it is. Any number above 127 is
received as 63.

Any ideas about the underlying reasons for this?




听起来像它使用ASCII编码 - 你用什么编码

想要它使用?


-

Jon Skeet - < sk *** @ pobox.com>
http:// www .pobox.com / ~siget

如果回复小组,请不要给我发邮件



It sounds like it''s using ASCII for its encoding - what encoding to you
want it to use?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too




63是'用于奇偶校验错误的默认字符,不确定你如何获得在同一端口上发送和接收数据的奇偶校验错误
$ b虽然$ b。如果你想从端口发送字节,它可能有助于将它们作为一个字节数组而不是字符串数组发送给它。

" halukg" <公顷**** @ discussions.microsoft.com>在消息中写道

新闻:EB ********************************** @ microsof t.com ...

63 is the default character that''s used for parity errors, not sure how you
could a get a parity error sending and receiving data on the same port
though. If you want to send bytes out the port it may help to send them as
a byte array instead of as a string though.
"halukg" <ha****@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
我试图从新的C#2005串口发送一个6字节的char数组
快递:
com.Write(new string(new char [] {(char)34,(char)14,(char)192,(char)51,
(char)0,(char)0},0,6));

我从端口接收34,14,63,51,0,0,因为我使用以下代码将Tx和Rx引脚相互连接:

private void com_DataReceived(object sender,SerialDataReceivedEventArgs
e)
{
bytes = com.BytesToRead;
if(bytes> = 6)
com.Read(buffer,0 ,字节);
}

要理解的难点是:在这个数组中如果我用127替换192

以下任何数字我得到阵列原样。任何高于127的数字都会被收到63.

有关此根本原因的任何想法?
I am trying to send a 6 byte char array from the serial port in new C# 2005
Express:
com.Write(new string(new char[] { (char)34, (char)14, (char)192, (char)51,
(char)0, (char)0 }, 0, 6));

I am receiving 34,14,63,51,0,0 from the port as I connected Tx and Rx pins
to each other by using the following code:

private void com_DataReceived(object sender, SerialDataReceivedEventArgs
e)
{
bytes = com.BytesToRead;
if (bytes >= 6)
com.Read(buffer, 0, bytes);
}

The hard thing to understand is: in this array if I replace 192 with 127
or
any number below I get the array back as it is. Any number above 127 is
received as 63.

Any ideas about the underlying reasons for this?



一个其他的想法,我没试过这个,但是,你有端口数据库

设置为7?我认为这会有效地限制你到0-127。

Tedb <一个** @ anon.com>在消息中写道

news:ef ************** @ tk2msftngp13.phx.gbl ...
One other thought, I have not tried this but, do you have the port databits
set to 7? I think that this would effectivly limit you to 0-127.
"Tedb" <an**@anon.com> wrote in message
news:ef**************@tk2msftngp13.phx.gbl...

63是用于奇偶校验错误的默认字符,但不确定如何获得在同一端口上发送和接收数据的奇偶校验错误
。如果你想从端口发送字节,可能有助于将它们作为字节数组发送,而不是作为字符串发送。

" halukg" <公顷**** @ discussions.microsoft.com>在消息中写道
新闻:EB ********************************** @ microsof t.com。 ..

63 is the default character that''s used for parity errors, not sure how
you could a get a parity error sending and receiving data on the same port
though. If you want to send bytes out the port it may help to send them
as a byte array instead of as a string though.
"halukg" <ha****@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
我试图从新的C#串口发送一个6字节的char数组#
2005
快递:
com.Write(new string(new char [] {(char)34,(char)14,(char)192,
(char)51,
(char)0,(char)0},0,6));

我从端口接收34,14,63,51,0,0,因为我使用以下代码将Tx和Rx
引脚相互连接:

private void com_DataReceived(object sender,SerialDataReceivedEventArgs
e)
{
bytes = com.BytesToRead;
if(bytes> = 6)
com.Read(buffer,0,bytes);
}

很难理解的是:在这个数组中,如果我用127替换192

我下面的任何数字都可以恢复原样。任何超过127的数字都会被收到63.

有关此根本原因的任何想法?
I am trying to send a 6 byte char array from the serial port in new C#
2005
Express:
com.Write(new string(new char[] { (char)34, (char)14, (char)192,
(char)51,
(char)0, (char)0 }, 0, 6));

I am receiving 34,14,63,51,0,0 from the port as I connected Tx and Rx
pins
to each other by using the following code:

private void com_DataReceived(object sender, SerialDataReceivedEventArgs
e)
{
bytes = com.BytesToRead;
if (bytes >= 6)
com.Read(buffer, 0, bytes);
}

The hard thing to understand is: in this array if I replace 192 with 127
or
any number below I get the array back as it is. Any number above 127 is
received as 63.

Any ideas about the underlying reasons for this?




这篇关于在新的C#2005 Expres中通过串行端口传输'char'数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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