本文介绍了VB&的方式有所不同吗? C#处理中断......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一些用C#编写的代码,我不得不将其转换为VB.NET。我看到VB处理Data Received事件的方式有所不同。在C#中,只要我能告诉数据到达端口,就会引发标志并收集数据进行处理。我通常使用Enum处理此问题,详见 [ ^ ]我在VB中尝试过一个类似的系统,它似乎没有正确读取数据,就像每个数据到达并重新设置句柄一样。这是不可能的(对吧?),因为两种语言都编译成相同的IL代码。这意味着必须有一些我在Enum列表中没有做的事情

Hi All,

I have some code I have written in C# and am having to convert it to VB.NET for a purpose. I am seeing some difference in the way VB handles the Data Received event. In C# as far as I can tell data arrives at the port, the flag is raised and the data is collected to be processed. I commonly handle this with an Enum as detailed in Serial Comms in C# for Beginners[^] I have tried a similar system in VB and it appears it isn't reading the data correctly almost like each piece of data arrives and set the handle again. This is impossible (right ?) as both languages compile to the same IL code. Meaning there must be something I am not doing right with the Enum list

Private Enum REPLY_FREQ As Integer
      NO_REPLY
      YES_REPLY
      TIMEOUT_REPLY
  End Enum

这与C#版本相比:

enum REPLY : int { NO_REPLY, YES_REPLY, TIMEOUT_REPLY }





通过以下设置/重置



They are Set/Reset via the following

'TmrNoDataAtPort.Enabled = False
    If (Reply_Status = REPLY_FREQ.TIMEOUT_REPLY) Then
        Data_Back_1823A = "TIMEOUT"
    ElseIf (Reply_Status = REPLY_FREQ.YES_REPLY) Then
        NoDataAtPort_Freq.Enabled = False
    End If

用于VB版本,而C#版本例如是

for the VB version and the C# version is for example

else if (Reply_Status == (int)REPLY.YES_REPLY)
   {
       Data_From_ATE = ATEComPort.ReadTo("\r\n");
      if ((Data_From_ATE.Substring(0, 1)) == (Data_To_ATE.Substring(1, 1)))
      {
        return (Data_From_ATE);
      }
   }
   else
   {
      Data_From_ATE = "SERIOUS_ERROR";
      return (Data_From_ATE);
  }
}

我只是愤怒地使用了VB6(直到现在!)并且在我做了简短的事后我尽快跳到C#(我的意思是简短的) !)在Borland C ++建设者中徘徊......

任何想法?

格伦

I have only used VB6 in anger (until now!) and jumped ship to C# as soon as I could after a brief (I mean brief!) wander in Borland C++ builder...
Any Ideas anyone?
Glenn

推荐答案


这篇关于VB&的方式有所不同吗? C#处理中断......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 11:20