Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

upgrading 2.5 code to 4.0 - serial port

3 views
Skip to first unread message

Bleary Eye

unread,
Dec 3, 2009, 3:56:01 PM12/3/09
to
I have some code written for mf 2.5 that I'm trying to bring up to 4.0. The
classes seem to have changed.

I have a reference to Microsoft.SPOT.Hardware.Serial, but when I use
Intellisense, I can get as far as Microsoft.SPOT.Hardware, and after that
there are no options.

On the other hand, System.IO.Ports has a SerialPort class with constructors
but no methods, so it’s not clear how to actually do anything.

Here's an example of the 2.5 code we have now.

SerialPort.Configuration _serialConfig;
SerialPort _sp;
_serialConfig = new SerialPort.Configuration(SerialPort.Serial.COM1,

SerialPort.BaudRate.Baud115200,
false);

Ideas? Thx, Bill

JRMalin

unread,
Dec 3, 2009, 9:32:40 PM12/3/09
to
Yes, the serial port API and namespaces in V4.0 have changed. Let me give
you some information for conversion.
1. First I assume that you have installed the V4.0 SDK, edited the .csproj
file and udated the <TargetFrameworkVersion> to v4.0, loaded the solution
and let VS do the rest of the conversion.

2. Add a new reference to the references: Microsoft.SPOT.Hardware.SerialPort

3. Add a new using statement: using System.IO.Ports

4. The serial configuration is no longer used, so comment those statements.
The SerialPort class now has overloaded constructors that accept the
configuration arguments directly, i.e.
SerialPort mySerialPort = new SerialPort("COM2", BaudRate.Baudrate115200,
Parity.None, 8, StopBits.None);

Note that the integer values for the baudrate, parity, etc can be used. The
serial port identifier is now the string that names the serial port, "COM1",
"COM2", etc.

5. You can specify the handshake mode via SerialPort Handshake property,
i.e.
mySerialPort.Handshake = Handshake.None;

6. Before writing to or reading from the serial port, it now must be
explicitly opened, i.e.
mySerialPort.Open();

7. The Write & Read method now has 3 paramenters: pointer to the byte
buffer, the offset into the buffer to start at, and the number of bytes to
write or read, i.e.:
mySerialPort.Write(WriteBuffer, 0, 4);
mySerialPort.Read(ReadBuffer, 0, ReadBuffer.Length);

8.) If you are through with the serial port, do an explicit close, i.e.
mySerialPort.Close();

I think that should give you what you need to convert your earlier serial
applications.

Regards,
-JRMalin, SJJ Embedded Micro Solutions

"Bleary Eye" <Blea...@discussions.microsoft.com> wrote in message
news:13D6B11F-8D71-478C...@microsoft.com...

Dheeraj Pulluri

unread,
Dec 4, 2009, 4:01:01 AM12/4/09
to
I am looking at HardwareProvider class in Microsoft.SPOT.Hardware. The
method Microsoft.SPOT.Hardware.HardwareProvider.GetSerialPins signature was
changed to include CTS and RTS pins. Could you suggest me any documentation
regarding this method. The MSDN library I guess has not been updated yet.
Strange. http://msdn.microsoft.com/en-us/library/ee433898.aspx.

"JRMalin" wrote:

> .
>

Jan Kučera

unread,
Dec 4, 2009, 7:49:34 PM12/4/09
to
Hi Dheeraj, what are you trying to use this method for?

This is valid syntax:

Microsoft.SPOT.Hardware.Cpu.Pin rx, tx, cts, rts;
Microsoft.SPOT.Hardware.HardwareProvider.HwProvider.GetSerialPins("COM1",
out rx, out tx, out cts, out rts);

after this call, the rx variable will contain number of processor pin on
which the data arrives to COM1, other signals similar.

Jan


"Dheeraj Pulluri" <Dheeraj...@discussions.microsoft.com> wrote in
message news:95177F38-D261-4B88...@microsoft.com...

0 new messages