0

I'm using a Moxa Serial Hub centralize some devices that communicate using RS-232 / NMEA protocol.

The serial hub is working as a TCP client, witch every time it receives data transmits it to a know IP/port in my machine.

schema

The problem is that I'm not receiving the data properly (I thought all I had to do was create a TCP server that accepts connections, and read the data as bytes, but that just gives me some weird characters)

I receive the bytes...but when converting to text... its just some weird characters, I'm missing some detail in this conversion. so far I've tried:

byte[] b = new byte[1000];
int k = s.Receive(b);
Console.WriteLine(Encoding.UTF8.GetString(b, 0, 1000));
Console.WriteLine(Encoding.ASCII.GetString(b));
for (int i = 0; i < k; i++)
   Console.Write(Convert.ToChar(b[i])); 

all these 3 approaches write the same text...

Does any one know how to properly read the data in this cases?

9
  • 2
    So you actually get a connection request from the moxa hub and receive (wrong) data? Then it might be related to wrong serial port settings on the moxa device (probably the wrong baud rate) Commented Dec 15, 2011 at 11:48
  • 1
    are you sure that your data should be text (and not some raw byte array)? Commented Dec 15, 2011 at 11:49
  • 1
    This sounds like an encoding problem based on the fact you claim you recieved "wierd" characters. Are you able to verify the bytes you recieve/send perhaps are actually correct by hand? So convert it.....What exactly is your question you have provided no code. Commented Dec 15, 2011 at 11:55
  • 1
    What bytes do you get, and what data did you expect to get? Commented Dec 15, 2011 at 12:12
  • 2
    @Hans Passant: could you please stop adding [Solved] to the title of questions? If the question has been answered in a comment or by the OP himself, add it as an answer instead. See here: meta.stackexchange.com/questions/116101/… Commented Dec 15, 2011 at 14:13

1 Answer 1

1

This comment provided the solution to the problem:

So you actually get a connection request from the moxa hub and receive (wrong) data? Then it might be related to wrong serial port settings on the moxa device (probably the wrong baud rate) – Jan 2 hours ago

Indeed, the baud rate was wrong.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.