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.
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.
Dim SendData(19) As Byte
Dim sending As String
SendData(0) = &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) = &HFB
sending = ""
For i = 0 To 7
sending= sending + Chr(SendData(i))
Next
SP.Output = sending
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# ;
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 <= 7; i++)
{
sending= sending+ ((char)SendData[i]);
}
sp.Write(sending);
I cant see any problem with this but Vb Code works and C# does not.
In c# , the following is the part of my open port function ;
sp.PortName = portName;
sp.BaudRate = baudRate;
sp.DataBits = databits;
sp.Parity = parity;
sp.StopBits = StopBits.One;
sp.PinChanged += SerialPinChangedEventHandler1;
sp.ErrorReceived += SerialErrorReceivedEventHandler1;
sp.DataReceived += new SerialDataReceivedEventHandler(DataReceived);
sp.ReadTimeout = 1000;
sp.WriteTimeout = 1000;
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.