Main Site Documentation

Question about SerialPort


#1

This is probably kind of a stupid question, but I’m going to ask anyway.

In a line of code like the one below, how do I know for which USART on my main board is referred to as “COM1” etc.

SerialPort UART = new SerialPort(“COM1”, 115200);

I realize I can figure it out by writing stuff on the serial line and measuring on which UART I can detect it. But I expect that some in the documentation I should be able to determine this without the guesswork. Or is it simply that UART0 of the mainboard relates to “COM1” and UART1 relates to “COM2” etc?


#2
 GT.Socket socket = GT.Socket.GetSocket(2, false, null, "");
            _imuPort = new SerialPort(socket.SerialPortName, 38400, Parity.None, 8, StopBits.One);

#3

That is correct.


#4

Thanks to both Justin and Mike. Both answered my question. Justin’s answer is very specific.


#5

That is not necessarily the case - it depends on your board.

The Mountaineer boards, as an example, have COM1 == USART1, COM2 == USART2, etc.
(documented in http://www.mountaineer.org/app/download/6083970675/Mountaineer.Netmf.Hardware.pdf )


#6

@ wire_dancer - you are correct. it depends on how the chip numbers it’s uarts. the lowest uart is com1 usually. of course, this could be changed in the port of netmf.


#7

I think I found the answer to my question in the GHI documentation here:

Quote from : https://www.ghielectronics.com/docs/15/uart

[quote]NETMF supports serial ports (UART) in the same way the full .NET framework on the PC is supported. To use the Serial port, add Microsoft.SPOT.Hardware.SerialPort assembly and add using System.IO.Ports at the beginning of your code.

Note that serial ports on PC’s and on NETMF are named COM ports and they start from COM1. There is no COM0 on computer systems. This can cause a little confusion when we want to map the COM port to the UART port on the processor because the processor usually start with UART0 not UART1. So, COM1 is UART0, COM2 is UART1, and so on.[/quote]