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.
using System;
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.Netduino;
using System.Text;
using System.IO.Ports;
namespace Bluetooth
{
public class Program
{
static SerialPort serial;
public static void Main()
{
// initialize the serial port for COM1 (pins D0 and D1)
serial = new SerialPort(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One);
// open the serial-port, so we can send and receive data
serial.Open();
// add an event-handler for handling incoming data
serial.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);
//wait until the end of the Universe :-)
Thread.Sleep(Timeout.Infinite);
}
static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// create a single byte array
byte[] bytes = new byte[1];
// as long as there is data waiting to be read
while (serial.BytesToRead > 0)
{
// read a single byte
serial.Read(bytes, 0, bytes.Length);
// send the same byte back
serial.Write(bytes, 0, bytes.Length);
}
}
}
}
It does what its supposed to. Picks up characters tossed at the attached Bluetooth device from one connected to the host. It then sends it back and the terminal doing the sending promptly displays it.
I'm trying to figure out how to safely insert the usual steps to enable a GPIO or two or three or four to react to the digital stream being sent between the Serial Port 0 connection.
Ideally the big problem is one of being able to definitely send the stream from the serial-in connection, then to say GPIO_D2, and then GPIO_D3 and GPIO_D4 and of course GPIO_D5, and then to the serial-out connection. All without breaking the flow of logic he wrote.
Incidentally that's the first and best example I found of being able to use the on-board serial port on the board.
For clarification I have over in the general portion of the board, one labeled "New device Monday" and one on powering a Netduino in there, but I suspect it will need to be moved here.
Instead of using the event, fire a thread endlessly running which consumes the bytes incoming (basically the event handler content).
I think should be more reliable as timing, because the events are dispatched sequentially, but there's no guarantee of accuracy and you may experience a messy stream...
Anyway, I'm not sure to understand what you want to do.
Do you want the Netduino:
receive a message from the serial, then
process the message by de/activating one or more I/Os, then
send an answer out on the same serial
Is that what you want?
Biggest fault of Netduino? It runs by electricity.
Instead of using the event, fire a thread endlessly running which consumes the bytes incoming (basically the event handler content).
I think should be more reliable as timing, because the events are dispatched sequentially, but there's no guarantee of accuracy and you may experience a messy stream...
Anyway, I'm not sure to understand what you want to do.
Do you want the Netduino:
receive a message from the serial, then
process the message by de/activating one or more I/Os, then
send an answer out on the same serial
Is that what you want?
Hello!
Close enough.
What I'm looking for, is to have the Netduino process the message and since its single character ASCII then dump it in the same serial form out one or more I/O points and then pass it back unchanged to the serial out connection.
What that author created is what I was looking for as an excellent example of serial communications on the board and even the use of these serial out Bluetooth devices.
If the characters arrive with a relative "distance" (in terms of time) each other, the original snippet should be good. I wondering how could happen whenever a long stream of bytes arrive at once.
At this point, where's the problem on inserting the I/O control inside the loop?
BTW, I believe the Netduino could be a bit touchy: remove the "until the end of the Universe" comment, then re-run the program...that might yield a way better result.
Cheers
Biggest fault of Netduino? It runs by electricity.
Okay the story so far. I pulled up the code and examined it. I then found a known working example and copied a reference for the D2 I/O connector for the board. I then inserted the seemingly correct definition into it. Here's the code:
using System;
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.Netduino;
using System.Text;
using System.IO.Ports;
namespace Bluetooth
{
public class Program
{
static SerialPort serial;
public static void Main()
{
// initialize the serial port for COM1 (pins D0 and D1)
serial = new SerialPort(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One);
// open the serial-port, so we can send and receive data
serial.Open();
// add an event-handler for handling incoming data
serial.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived);
//wait until the end of the Universe :-)
OutputPort d2 = new OutputPort(Pins.GPIO_PIN_D2, false);
OutputPort d3 = new OutputPort(Pins.GPIO_PIN_D3, false);
Thread.Sleep(Timeout.Infinite);
}
static void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// create a single byte array
byte[] bytes = new byte[1];
// as long as there is data waiting to be read
while (serial.BytesToRead > 0)
{
// read a single byte
serial.Read(bytes, 0, bytes.Length);
// send the same byte back
serial.Write(bytes, 0, bytes.Length);
d2.Write(bytes, 0, bytes, bytes.Length);
d3.Write(bytes, 0, bytes, bytes.Length);
}
}
}
}
Instead those two inserts after the serial read instructions causes an error. Here:
Error 1 The name 'd2' does not exist in the current context C:\Users\GCL.CMDRSKYWALKER.000\documents\visual studio 2010\Projects\Bluetooth0\Bluetooth0\Program.cs 45 17 Bluetooth0
Error 2 The name 'd3' does not exist in the current context C:\Users\GCL.CMDRSKYWALKER.000\documents\visual studio 2010\Projects\Bluetooth0\Bluetooth0\Program.cs 46 17 Bluetooth0
As usual the programming IDE does not provide enough information. I have all of the using something definitions defined. I even have the write definition for the term included. Ideally the IDE needs to have more comprehensive help added.
More information. Here's the known working example that I chose that contained that term.
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
namespace B7
{
public class Program
{
public static void Main()
{
// write your code here
OutputPort a0 = new OutputPort(Pins.GPIO_PIN_D2, false);
OutputPort a1 = new OutputPort(Pins.GPIO_PIN_D3, false);
while (true)
{
Thread.Sleep(250);
a0.Write(false); //
a1.Write(false); // O0 output engaged
Thread.Sleep(2500);
a0.Write(true); //
a1.Write(false); // O1 output engaged
Thread.Sleep(2500);
a0.Write(false); //
a1.Write(true); // O2 output engaged
Thread.Sleep(2500);
a0.Write(true); //
a1.Write(true); // O3 output engaged
Thread.Sleep(2500);
a0.Write(false); //
a1.Write(false); // O4 output engaged
}
}
}
}
The premise there is that it toggles two lines and causes the attached device to step through a series of sequences. It worked, but, ah, the responses were peculiar. The project was eventually abandoned.
Okay now it becomes peculiar. I relocated the definitions inside the loop and corrected a typo in the variables being presented to the output port. Now I'm getting this error:
Error 1 No overload for method 'Write' takes 3 arguments C:\Users\GCL.CMDRSKYWALKER.000\documents\visual studio 2010\Projects\Bluetooth0\Bluetooth0\Program.cs 46 17 Bluetooth0
Error 2 No overload for method 'Write' takes 3 arguments C:\Users\GCL.CMDRSKYWALKER.000\documents\visual studio 2010\Projects\Bluetooth0\Bluetooth0\Program.cs 47 17 Bluetooth0
Its the same thing inside the parenthesis being used to send and receive data regarding the serial port into and out the attached Bluetooth device.
Help, ah, doesn't.
What I'm looking for obviously is a means to send into and out of the GPIO connections the same data circling through the serial port. The reluctance of the Visual Studio obviously confirms that it doesn't like the sequence of events.
Thanks man. That'll work. I'll know in about fifteen or twenty minutes if it works. It'll certainly replace the original application, which was exported from that blog.
However trying to put that code into the IDE promptly causes an error message to pop up about a missing { symbol, and of course the system can not explain what it means.
More about:
Okay Juzzer, I removed what I copied before, and copied it again, and then stuck it into my framework. It then cleared the errors that I put there before.
To Chris:
I'm not sure how much input you have into the folks at Microsoft for the Framework development, but it would be nice if the error messages also produced meaningful output.
Consider this, during the days of running ordinary BASIC on the PC, if the user made a mistake in a line, the interpretation sequencer would complain with a syntax error message. And it would be obvious.
But all of what I've entered into this thread regarding errors, aren't. They are obscuring the responses with FUD on the screens which surface when such clarification is requested.
Its the same thing inside the parenthesis being used to send and receive data regarding the serial port into and out the attached Bluetooth device.
Help, ah, doesn't.
What I'm looking for obviously is a means to send into and out of the GPIO connections the same data circling through the serial port. The reluctance of the Visual Studio obviously confirms that it doesn't like the sequence of events.
It sounds like you need to bit-bang the data through the GPIO ports yourself. Writing a series of bytes to a GPIO pin is not supported natively you can only set the pin high or low.
It sounds like you need to bit-bang the data through the GPIO ports yourself. Writing a series of bytes to a GPIO pin is not supported natively you can only set the pin high or low.
Regards,
Mark
I'm a bit confused what you are actually trying to achieve and what examples are missing to get you going...
Are you just trying to achieve BT comms?
To answer both of you. What I was looking for was to have the board respond to the Bluetooth device. Besides passing the text back and forth between the serial I/O pins, I originally wanted the two chosen GPIO pins to do just that Nevyn, to blink back and forth between those character deliveries.
But it got too complicated, and I realized that yes indeed the GPIO pins do what you're thinking of, and that what's I'm good at. Then it would get more interesting from there.
Besides, I'm off on something new regarding the older programs I already had debugged. But never fear I'll revisit this thread and even the problems soonest.