MsComm.OCX使用C# [英] MsComm.OCX working with C#
本文介绍了MsComm.OCX使用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在处理 MSComm.ocx
沟通。
我想将15个长度数据发送到串口。
当我设置 axMSComm1.RThreshold = 15
axMSComm1_OnComm事件
没有被解雇。
但是如果我设置 axMSComm1.RThreshold = 1
那么 axMSComm1_OnComm
被解雇了。
请帮帮我。
code snip :
Hi,
I am working on MSComm.ocx
communication.
I want to send 15 length data to serial port.
when I set axMSComm1.RThreshold = 15
the axMSComm1_OnComm event
is not getting fired.
but if I set axMSComm1.RThreshold = 1
then axMSComm1_OnComm
gets fired.
Please help me on this.
code snip:
int[] values = { 7, 1, 18, 2, 253, 61, 170 };
char[] chars = values.Select(x => (char)x).ToArray();
string str = new string(chars);
str = ":" + str;
sent_command = str;
axMSComm1.Settings = "9600, N, 8, 2";
axMSComm1.CommPort = 1;
axMSComm1.RThreshold = 8 + 6 + 1;
axMSComm1.DTREnable = true;
axMSComm1.RTSEnable = true;
axMSComm1.PortOpen = true;
axMSComm1.Output = sent_command;
推荐答案
正如CPallini所说,可能没有必要在C#中使用MSComm.ocx SerialPort类 [ ^每一个都可以使用activeX控件,但是以更多的OOP方式。
在现代系统上它也不是一个好主意:OCX是一个32位控制,所以你需要使用regsrv32.exe将它注册到系统中,并将你的应用程序编译为32位。
说真的,使用更现代的方法 - 使用过时的控件只能使用将来会导致比现在解决的更多问题。
As CPallini says, it's probably not necessary to use MSComm.ocx in C# as the SerialPort class[^] does everythign the activeX control can, but in a much more OOPs way.
It's also not a good idea on modern systems: the OCX is a 32bit control so you'll need to use regsrv32.exe to register it into the system, and compile your app for 32 bit only.
Seriously, use the more modern approach - using outdated controls is only ever going to cause more problems in the future than it solves now.
这篇关于MsComm.OCX使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文