The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
I'm new to netduino need to establish a communication with COM1 netduino and PC serial Port area using "Tera Term" but communication does not work I press the letter "a" on the keyboard and returns me another character. I'm working with a Baude Rate of 9600. Alguine I can say I'm doing wrong? Thank you. I leave the source code.
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using System.IO.Ports;
namespace NetduinoPlusApplication1
{
public class Program
{
static SerialPort serial;
static OutputPort Led = new OutputPort(Pins.ONBOARD_LED, false);
public static void Main()
{
// initialize the serial port for COM1 (using D0 & D1)
serial = new SerialPort("COM1",9600, Parity.None, 8, StopBits.One);
// open the serial-port, so we can send & receive data
serial.Open();
// add an event-handler for handling incoming data
serial.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);
// wait forever...
Thread.Sleep(Timeout.Infinite);
}
static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int bytesToRead = serial.BytesToRead;
//start reading the stream
if (bytesToRead > 0)
{
// get the waiting data
byte[] buffer = new byte[bytesToRead];
serial.Read(buffer, 0, buffer.Length);
serial.Write(buffer, 0, buffer.Length);
Led.Write(true);
}
Led.Write(false);
}
}
}
Edited by Chris Walker, 12 July 2012 - 04:40 AM. added [code][/code] tags
Hi efrain7805,
Can you confirm that you're using all the same settings on the PC (8 data bits, no parity, one stop bit)?
Also, what kind of cable are you using to attach your Netduino to the PC? RS232? USB-TTL? Are you doing any voltage level conversion?
Welcome to the Netduino community,
Chris
thanks for responding.
The configuaracion of PC is equal to the program but I'm not using using a voltage level converter. I directly connect the P0, P1 and ground directly to the Port netduino plus 232 of the PC to the Pines 2,3,5. if I use a voltage level converter which recommend?
once again thank you very much.
Can you post the character you recvive when you type "a" into the console?
Do you get a character like this? ž or ×?
If so then you need to logically invert the RX or TX lines as what you are receiving back to the console is the logical inverse of the byte you expected.
i.e.
//The letter 'a' in ascii byte values is 0x61
//In binary this is 0110 0001
//If the RX or TX lines are not inverting the response you will get a value of 0x9E (158 decimal)
//i.e. the non inverted value would be 1001 1110
Can you set a breakpoint on the line
serial.Write(buffer, 0, buffer.Length);
What do you see in the buffer, i.e. if you press the 'a' key you should see a byte array with a single entry with the value of 0x61 (or 97 if you haven't enabled hex view). If you see that then it seems likely that the culprit is the TX line which needs inverting, otherwise its the RX line.
I suspect as you are not using a voltage converter you are not getting the inversion done for free, so either use a voltage converter like a MAX232, or invert the RX and TX lines using a device like a 74HCT14N although i would recomend a purpose built RS232 level converter if you are likely to experience 12V serial signals which you would typically get from a PC serial port (although not always if you are using a USB serial port, dc-dc converters are expensive and 5v is enough to trigger most modern (later than 1980's) logic devices...)
I have been trying different examples all day. This one works the best but it still doesn't accept "SerialPort" saying "The type or namespace name 'SerialPort' could not be found (are you missing a using directive or an assembly reference?)
What do I need?
Okay, I had to make "SerialPort" plural to accept it but it still doesn't work below in the program. On line with " serial = new SerialPorts("COM2", 9600, Parity.None, 8, StopBits.One); I get "Cannot create an instance of static class 'SecretLabs.NETMF.Hardware.NetduinoPlus.SerialPorts'"
Okay, I had to make "SerialPort" plural to accept it but it still doesn't work below in the program. On line with " serial = new SerialPorts("COM2", 9600, Parity.None, 8, StopBits.One); I get "Cannot create an instance of static class 'SecretLabs.NETMF.Hardware.NetduinoPlus.SerialPorts'"
If you take the plural "s" out of "= new SerialPorts", does that work? I believe that the class you're looking for is System.IO.SerialPort rather than 'SerialPorts'.
With "SerialPort" I get the error "Type or namespace name 'SerialPort' could not be found (are you missing a using directive or an assembly reference?)"
With "SerialPort" I get the error "Type or namespace name 'SerialPort' could not be found (are you missing a using directive or an assembly reference?)"
Two quick questions...
1. Do you have Microsoft.SPOT.Hardware.SerialPort.dll added as a reference to your project?
2. Do you have the text "using System.IO.Ports;" at the top of your source code file?
I have "using System.IO.Ports;" but how do you add "Microsoft.SPOT.Hardware.SerialPort.dll" to the references. I have "Microsoft.SPOT.Hardware" under which heading is "{}Microsoft.SPOT\ {}Microsoft.SPOT.Hardware\ {}System.IO.Ports" in references.
I have "using System.IO.Ports;" but how do you add "Microsoft.SPOT.Hardware.SerialPort.dll" to the references. I have "Microsoft.SPOT.Hardware" under which heading is "{}Microsoft.SPOT\ {}Microsoft.SPOT.Hardware\ {}System.IO.Ports" in references.
Click on "Project -> Add reference" in the menu bar at the top. Now select Microsoft.SPOT.Hardware.SerialPort.
There is nothing under the ".NET" tab. I re-downloaded .NET Micro Framework making sure it was for the Netduino Plus and not the Netduino Go. Got out of Visual Studio and back in again. Re-loaded my program which is a .NET Micro Framework project. and there still is nothing under the .NET tab.
Hi Kentj,
Could you please go to "Project -> Project Properties" and make a screenshot? It should look like this:
project_properties.png30.86KB37 downloads
Also, go to "Project -> Add Reference...". I have this list, you should add the selected reference:
add_reference.png34.13KB38 downloads
It won't be there if it's the wrong project type though. The actual DLL is found here:
C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.1\Assemblies\le\
Sorry, I don't remember how to do a screen shot since I haven't done it since the '80s (DOS). The "Project Properties" screen looks the same though. The other one does not.
Sorry, I don't remember how to do a screen shot since I haven't done it since the '80s (DOS). The "Project Properties" screen looks the same though. The other one does not.
To make a screenshot, press the PrtScn button on your keyboard. That will add an image of the full screen in your clipboard. If you press Alt+PrtScn it will just do the active window.
Then go to an image editor, for example Microsoft Paint, paste (Ctrl+V) and store it to the disk.