2013-09-25 73 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.