2013-09-25 59 views
-1

我在VB源代码,我想将它转换成C#来&字符串命令发送到COM1。什么是C#代码来做到这一点?发送命令和字符串COM1

这段代码在VB6:

Comm1.Output = Chr$(&H5) 
Comm1.Output = Chr$(&H2) + Chr$(&H10) + Chr$(&H31) + msg + Chr$(&H10) + Chr$(&H32) + msg2 + Chr$(&H3) 
+1

你试过自​​行解决这个问题? – freemanoid

+0

我还没有看到任何动作,你有更多的问题吗? – paqogomez

回答

1

基于几个测试和fewarticles,我认为这将更好地工作。

char char2 = (char)int.Parse("2", NumberStyles.AllowHexSpecifier); 
char char3 = (char)int.Parse("3", NumberStyles.AllowHexSpecifier); 
char char5 = (char)int.Parse("2", NumberStyles.AllowHexSpecifier); 
char char10 = (char)int.Parse("10", NumberStyles.AllowHexSpecifier); 
char char31 = (char)int.Parse("31", NumberStyles.AllowHexSpecifier); 
char char32 = (char)int.Parse("32", NumberStyles.AllowHexSpecifier); 

Comm1.Write(char5); 
Comm1.Write(string.Format("{0}{1}{2}{3}{4}{5}{6}{7}", char2, char10, char31, msg, char10, char32, msg2, char3)); 

没有你如何初始化串口提,我的假设是,已经是正确的。如果不是,有articles to read on the subject.