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.
Hi
I am new to netduino platform. I experiment the environment for a couple of days.
In my final project I want to use the device to transfer data between the serial ports to external devices.
I managed to program the device using the following instructions:
Power
* Attach 7.5V-12V power to pin 24 (top-right corner just right of notch at top). And from your power supply, attach ground to pin 23.
Programming
RS232: cut the end off of an RS232 cable and wire the RX, TX, DTR, and GND wires to pins 1, 2, 3, and 4.
In Visual Studio, set the deployment to Serial instead of USB and select your COM port.
All that work fine. I even managed to flash the device to firmware NetduinoMini_Firmware_4.2.0.1_RS232, so uart ports behaves well.
The steps I follow:
1. Deploy the application from VSstudio2010. (all fine)
2. Test that it works (debugging), all fine.
3. Power off the netduino mini, Close the VS studio.
4. Power up the netduino mini.
5. Wait the mini to boot and open a terminal application (TeraTerm or Real Term)
6. Send Keystrokes from Terminal application.
The peculiar behavior starts here….
a. The netduino application enters the event handler SerialDataReceivedEventHandler
b. The led flashes.
c. I can send hardcoded data back to the PC terminal application, from netduino but…
The problem is that there are no data to netduino receive buffer, the .BytesToRead always return zero
In the attached excample allways Bytes Readed=0
Could someone help me.
Thank you in advance.
The Code...
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoMini;
using System.IO.Ports;
using System.Text;
namespace NetduinoMiniApplication3
{
public class Program
{
static bool LedValue;
static OutputPort Led = new OutputPort(Cpu.Pin.GPIO_Pin12, false);
static SerialPort PCSerial=new SerialPort(SerialPorts.COM2, 1200, Parity.None, 8, StopBits.One);
public static void Main()
{
Thread.Sleep(5000); //To catch up for programming
PCSerial.DataReceived += new SerialDataReceivedEventHandler(PCSerialPortDataReceived);
PCSerial.Open();
LedValue = true;
while (true)
{
Thread.Sleep(2050); // sleep for 2500ms
}
}
static void PCSerialPortDataReceived(object sender, SerialDataReceivedEventArgs e)
{
//PCSerial.DataReceived -= new SerialDataReceivedEventHandler(PCSerialPortDataReceived);
System.Threading.Thread.Sleep(100); // wait a little for the buffer to fill
int Len=PCSerial.BytesToRead;
string s = "Bytes Readed" + Len.ToString() +'\r'+'\n';
PCSerial.Write(Encoding.UTF8.GetBytes(s), 0, s.Length);
Led.Write(LedValue);
LedValue = !LedValue;
//PCSerial.DataReceived += new SerialDataReceivedEventHandler(PCSerialPortDataReceived);
}
}
}
NooM
Thank you for the Reply.
I have tried this with no delay and the system is not working.
As you can see in the code:
string s = "Bytes Readed" + Len.ToString() +'\r'+'\n';
PCSerial.Write(Encoding.UTF8.GetBytes(s), 0, s.Length);
I can see the "Bytes Readed0" to my terminal, so I am using the correct port.
and also the event fires correctly (I can see the blinking led)
I also tried the ReadByte(), but it seems that is doing a blocking read an d the program not proceeds.
Do you use mini? If yes have you ever managed to communicate with COM2 pins(1,2)
The problem is not to the specific device, because I have tested 3 devices. (even with older firmware)
The problem is not to the specific device, because I have tested 3 devices. (even with older firmware)
The point is that COM1 and COM2 work on different voltage levels. Which COM port on your Mini did you use?
COM1 (pins 1 to 4) work at -12V to 12V
COM2 (pins 11, 12) work at 0V to 3.3V
What does the device want with which you try to communicate?
yes i have a mini and i communicated with another netmf device per uart (COM1) - i use COM2 for programming/debugging (pin 1,2)
it worked like a charm. i dont have the code anymore cos it was just for testing - it worked
in some days i can show you another one, iam going to stream display data from my pc to my netduino mini (for display/rgb matrix - the mini is really slow when using PutPixel)
//edit nothing todo with the mini itself, its a great device, mf is slow
The point is that COM1 and COM2 work on different voltage levels. Which COM port on your Mini did you use?
COM1 (pins 1 to 4) work at -12V to 12V
COM2 (pins 11, 12) work at 0V to 3.3V
What does the device want with which you try to communicate?
Hello Stefan
In my netduino mini the port that I manage to send data from mini to PC, is COM2 (with levels -12V to 12V, pins 1 to 4 see code).
Please inform me.
I use the (-12V +12V) port (pin 1..4), lets say COM2 (since this port is the one that worked to my code)
So Com2 is the port that I deploy and debug the application.
I also want to communicate with the PC throught the same port.
This is not possible since debugging and application use the same port.
Here is the question....
After downloading the code to the mini (COM2), I power OFF/ON the mini. Could you please inform me if after that the device enters to debug mode or not. I "supposed", till now, that when the mini does not find VS2010 to communicate it executes the program with no debug features.
And finally I want to use both serial ports (I will shift the levels of pins 11,12 )
in my project. Is it possible to put the mini in a mode that it does not start debuging or waiting for programming (I disconnected the pin 3 - DTR ???)
when you disconnect dtr it dont gets into bootloader mode as soon as you power it on.
i strongly suggest not using the same port for programming than you do for communication.
some serial reading code
ok the code looks messy, but works like a charm (so far, iam now not sending loads of data, its 8-9 bytes, once every while!)
i tested around more, and as expected when sending data faster it gets messed up.
anyone ideas to this?
i could use hardware flow control, but it would need pins wich are hard to spent on the mini.
currently iam reading into software flow control, wich seems to be ok too.
i also try to make kind of a stream/packet system, so it sorts it out automatically if data from the next packet gets into the one before.
i tested around more, and as expected when sending data faster it gets messed up.
anyone ideas to this?
i could use hardware flow control, but it would need pins wich are hard to spent on the mini.
currently iam reading into software flow control, wich seems to be ok too.
i also try to make kind of a stream/packet system, so it sorts it out automatically if data from the next packet gets into the one before.
Dear All
I have tested the system by downloading the code either by RS232 (+/-12V) or TTL (by using NetduinoMini_Firmware_4.2.0.1_RS232 or NetduinoMini_Firmware_4.2.0.1_TTL).
The system behaves fantastic when using the free serial port (not the one for debugging/downloading) and also can transmit data with the other debugging downloading port.
Whenever I tried to read data from (debugging/downloading) port the system misbehaved.
1. The Received event behaves well
2. The received data:
- Either nothing received to the buffer
- Or small parts of the data arrived to the buffer of the netduino.
1. Since in my project I want 2 serial ports (small baud rates up to 2400), I will give a try for a virtual serial port. By your experience, has the system enough processing power?
2. The bootloader or the Framework use the downloading/debugging serial port?
3. Is it possible to disable from framework/bootloader the usage of serial port? Because the system even it is equipped by two serial ports can only use for reading only one.
I just want to convert received bytes to/from Manchester encoding to drive ac coupled transmit/receive lines.
1. Since in my project I want 2 serial ports (small baud rates up to 2400), I will give a try for a virtual serial port. By your experience, has the system enough processing power?
After second thoughts, the above it is not possible since it requires under millisecond timer resolution for baud rates 1200bps, for just one sample and without voting.
Dear All
I finally manage to read from RS232-debug/download port. The problem seems to be the DataReceived event mechanism. By using the event mechanism from programming/debugging port the event fires but there are no data to read
xxx. BytesToRead allways==0
In the following code I manage to transfer /receive data between the two ports.
static SerialPort SerialRS232 = new SerialPort(SerialPorts.COM2, 1200, Parity.None, 8, StopBits.One);
static SerialPort SerialTTL = new SerialPort(SerialPorts.COM1, 1200, Parity.None, 8, StopBits.One);
public static void Main()
{
// In order to catchup debug / download
Thread.Sleep(5000);
SerialTTL.DataReceived += new SerialDataReceivedEventHandler(OtherSerialPortDataReceived);
SerialRS232.Open();
SerialTTL.Open();
while (true)
{
//read from SerialRS232 and Write to SerialTTL
int Len = SerialRS232.BytesToRead;
if (Len>0) {
byte[] b = new byte[Len];
SerialRS232.Read(b, 0, Len);
SerialTTL.Write(b, 0, Len);
}
}
}
static void OtherSerialPortDataReceived(object sender, SerialDataReceivedEventArgs e)
{
while (SerialTTL.BytesToRead > 0)
{
int Len = SerialTTL.BytesToRead;
byte[] b = new byte[Len];
SerialTTL.Read(b, 0, Len);
SerialRS232.Write(b, 0, Len);
}
}
Merry Christmas
yes, cos it doesent make sense, i guess the while loop is faster than the event, so it reads the data before the event can do.
you should du it as the tutorial from my link. it will work than i guess.
it worked for me.