title: How to receive data properly from Mbus in C#?
body: <p>I have really terrible problem that makes me almost sick. For 2-3 days, I've been dealing with this protocol issue and i find myself here to get some help from you guys. I hope I'll be solving. Thanks in advance. I had code in Vb that uses Old MsComm Library. So I decided to change all stuff with C#. I'm okey with opening , closing port and sending data etc. </p>
  
  <p>In Vb; I have the following part of code which is for receiving data from Mbus driver via RS485. Once you sent this it responses you to obtain data. It works and no problem.</p>
  
  <pre><code>Dim SendData(19) As Byte
  Dim sending As String
  SendData(0) = &amp;HFA
  SendData(1) = Mid(DriverNo, 1, 2)
  SendData(2) = Mid(DriverNo, 3, 2)
  SendData(3) = Mid(DriverNo, 5, 2)
  SendData(4) = Mid(DriverNo, 7, 2)
  SendData(5) = 210
  
  SendData(6) = CheckSum_Temass(5)
  SendData(7) = &amp;HFB
  
  sending = ""
  For i = 0 To 7
      sending= sending + Chr(SendData(i))
  Next
  
  SP.Output = sending
  </code></pre>
  
  <p>So , the code above is working fine in Vb and Vb.Net. However when I convert it to C# like the following ; I cant get response from mbus driver. While sending data via RS485, I can see that yellow led fires. Normally while receiving data, you can see that red led also fires. The Code in C# ; </p>
  
  <pre><code>string sending= "";
  byte[] SendData = new byte[8];
  SentData[0] = 0xfa;
  SendData[1] = Convert.ToByte((Strings.Mid(DriverNo, 1, 2)));
  SendData[2] =  Convert.ToByte((Strings.Mid(DriverNo, 3, 2)));
  SendData[3] = Convert.ToByte((Strings.Mid(DriverNo, 5, 2)));
  SendData[4] = Convert.ToByte((Strings.Mid(DriverNo, 7, 2)));
  SendData[5] = 210
  SendData[6] = CheckSum_Temass(5); 
  SendData[7] = 0xfb;
  
  for (int i = 0; i &lt;= 7; i++)
  {
      sending= sending+ ((char)SendData[i]);
  }
  
  sp.Write(sending);
  </code></pre>
  
  <p>I cant see any problem with this but Vb Code works and C# does not. </p>
  
  <p>In c# , the following is the part of my open port function ;</p>
  
  <pre><code>    sp.PortName = portName;
      sp.BaudRate = baudRate;
      sp.DataBits = databits;
      sp.Parity = parity;
      sp.StopBits = StopBits.One;//stopBits;
      sp.PinChanged += SerialPinChangedEventHandler1;
      sp.ErrorReceived += SerialErrorReceivedEventHandler1;
      sp.DataReceived += new SerialDataReceivedEventHandler(DataReceived);
  
      sp.ReadTimeout = 1000;
      sp.WriteTimeout = 1000;
  </code></pre>
  
  <p>Everything works fine. I can see as I said the flow of data through Mbus via RS485. I can see it from TX led which fires all the time I send data.However, as i said again, RX led does not fires. </p>