普通的RS422数据格式,想要输出角度值,串口通信已经搭建好,textRecieve.text可接收数据
解决方案 »
- UDP客户端连接服务器问题,求解决
- 如何更改combobox中item的间距?
- 【求助】刚学完c#基础知识,请高手们详细指点一下提高的方法
- vs2005 sp1什么时候出啊?
- ICSharpCode.SharpZipLib使用问题,解压。
- ASP.NET如何存取SQLSERVER的TEXT类型字段的值?
- 怎样去掉WINFORM DATAGRID行前的选行按钮栏?急?
- c#中一个string中,从某个字符或者字符串 开始全部去掉 怎么写的?
- 一个XPath问题
- 关于在发VS.NET中用ASP访问数据库的问题?
- C#中的 WPF数据重复加载
- webform 和 winform 之间如何进行socket通信?
//编码
byte[] SetDate(decimal radian)
{
int i,j;
string[] s = radian.ToString().Split('.');
byte[] rs = new byte[5];
rs[0] = 0xff;
if (s.Length == 2)
{
i = int.Parse(s[1]);
i = i << 10;
i = i | int.Parse(s[0]);
}
else
{
i = int.Parse(s[1]);
}
for (j = 3; j > 0; j--)
rs[j] = (byte)(i >> (8 * (3 - j)));
rs[4]=0;
for (j = 0; j < 4; j++)
rs[4] = (byte)(rs[4] + rs[j]);
return rs;
}
//解码
decimal GetData(byte[] dat)
{
int i;
string s;
//验证 不写了
i = 0;
for (i = 1; i < 4; i++)
{
i = i | dat[i];
i = i << 8;
}
s = (i & 0x3ff).ToString();
s = s + ".";
s = s + (i >> 10).ToString();
return decimal.Parse(s);
}
byte[] SetDate(decimal radian)
{
int i,j;
string[] s = radian.ToString().Split('.');
byte[] rs = new byte[5];
rs[0] = 0xff;
if (s.Length == 2)
{
i = int.Parse(s[1]);
i = i << 10;
i = i | int.Parse(s[0]);
}
else
{
i = int.Parse(s[1]);
}
for (j = 3; j > 0; j--)
rs[j] = (byte)(i >> (8 * (3 - j)));
rs[4]=0;
for (j = 0; j < 4; j++)
rs[4] = (byte)(rs[4] + rs[j]);
return rs;
}
{
i = int.Parse(s[0]);
}