VB串口使用心得两则

来源:互联网 发布:下载股市行情软件 编辑:程序博客网 时间:2024/04/28 23:09
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

最近本人,使用VB串口编程,得到心得两则,拿来和大家共享,

如果对则,褒奖本人两句,如果不对,则欢迎大虾指教。

心得1:串口的输出属性:

按照书上或是MSDN中给出OUTPUT的数据类型是字符串或VARIANT类型,我出现的问题是我想传送0至255之间的数,可是按照,以上的输出数据类型进行设置的化,传输不了诸如200,210等大于125的数,我又不想按照帖子上介绍的文章进行转换,于是有了一点心得:  将给OUTPUT的变量的数据类型设置为BYTE的数组,数组元素的个数为1即可。                                                                                                       

Dim Sendtemp(0)  As Byte  

Const SendCmd = &H55

   Sendtemp(0) = SendCmd
 MSComm1.Output = Sendtemp()

心得2:设置改变带来的一个问题

      当你的串口设置好后,一旦在以后你对串口的某一项设置改变后所有的设置都需要重新设置,如设定了串口的端口号,而没有设置串口的输入模式,如果你认为前面已经设置了输入模式,而不去理他,则他会用默认的模式去处理你的输入。造成不必要的麻烦,本人就为此调试了一会,才找到此问题,希望大家以后注意。

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击