Wow, that's a heck of an undertaking! So what's the motivation? Are you implementing features not found on the Shearwater or Hammerhead units? (BTW, I'm not a CCR diver but I was tech diving long before the term was ever coined.)
- Netduino Forums
- → cce1911's Content
cce1911's Content
There have been 59 items by cce1911 (Search limited from 17-June 23)
#51282 Dive Computer and Rebreather Controller Based on a Netduino Mini
Posted by
cce1911
on 10 July 2013 - 02:39 AM
in
Project Showcase
#51284 Dive Computer and Rebreather Controller Based on a Netduino Mini
Posted by
cce1911
on 10 July 2013 - 03:21 AM
in
Project Showcase
What do you use for a HUD?
It looks like you have certainly found a creative outlet I look forward to following your progress...
#51667 N+2 Socket problem
Posted by
cce1911
on 24 July 2013 - 07:42 PM
in
Netduino Plus 2 (and Netduino Plus 1)
I'm new to sockets and just can't seem to get my app working. What I want to do is send a log file from the N+2 back to my laptop. The approach I took was to prepend the file size to the byte array before sending. However, I never seem to receive exactly what I send. I realize this is a very common problem with folks who are new to sockets and I've searched high and low to find tips on how to avoid this problem. Maybe this is something unique to N+2, but I kind of doubt it.
Here is my code. I've got a client app that runs on the N+2 and a console app running on my laptop. The data file I'm retrieving is attached below. This sort of works, but is not delivering the file consistently. Any help you can give me would be appreciated.
Client app running on N+2. When you press the onboard button, it sends the file.
[font="'courier new', courier, monospace;"]using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Text;
using System.IO;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;[/font]
[font="'courier new', courier, monospace;"]namespace SocketClient
{[/font]
[font="'courier new', courier, monospace;"] public class Program
{
static string strDeviceIP = "";
static string strDeviceSubnet = "";
static string strDeviceGateway = "";
static string strDevicePort = "";
static string strControllerIP = "";[/font]
[font="'courier new', courier, monospace;"] public static OutputPort opLED = new OutputPort(Pins.GPIO_PIN_D13, false);
InputPort button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled);[/font]
[font="'courier new', courier, monospace;"] public static void Main()
{
strDeviceIP = "192.168.2.102";
strDeviceSubnet = "255.255.255.0";
strDeviceGateway = "192.168.2.2";
strControllerIP = "192.168.2.222";
strDevicePort = "9999";
InterruptPort btn = new InterruptPort(Pins.ONBOARD_SW1, false,[/font]
[font="'courier new', courier, monospace;"]Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);
btn.OnInterrupt += new NativeEventHandler(ButtonPress);[/font]
[font="'courier new', courier, monospace;"] while (true)
{
}
}[/font]
[font="'courier new', courier, monospace;"] public static void ButtonPress(uint data1, uint data2, DateTime time)
{
opLED.Write(true);[/font]
[font="'courier new', courier, monospace;"] Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress hostAddress = IPAddress.Parse(strControllerIP);
IPEndPoint endpoint = new IPEndPoint(hostAddress, Int32.Parse(strDevicePort));[/font]
[font="'courier new', courier, monospace;"] string fileName = "runlog2.txt";
// read the file into a byte array
byte[] data = File.ReadAllBytes(@"SD" + fileName);
byte[] sizeinfo = new byte[4];
byte[] senddata = new byte[4 + data.Length];[/font]
[font="'courier new', courier, monospace;"] // check to make sure it's not too big
if (data.Length > 850 * 1024)
{
Debug.Print("File too large");
}[/font]
[font="'courier new', courier, monospace;"] // convert data.length into a byte array
sizeinfo[0] = (byte)data.Length;
sizeinfo[1] = (byte)(data.Length >> 8);
sizeinfo[2] = (byte)(data.Length >> 16);
sizeinfo[3] = (byte)(data.Length >> 24);[/font]
[font="'courier new', courier, monospace;"] // prepend the size into the senddata array
sizeinfo.CopyTo(senddata, 0);[/font]
[font="'courier new', courier, monospace;"] // copy read data into the senddata array
data.CopyTo(senddata, 4);[/font]
[font="'courier new', courier, monospace;"] // send the data
socket.Connect(endpoint);
socket.Send(senddata);
socket.Close();
opLED.Write(false);
}
}
}[/font]
[font="'courier new', courier, monospace;"]Here is my server side console app.[/font]
[font="'courier new', courier, monospace;"] [/font]
[font="'courier new', courier, monospace;"]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Collections;
using System.Threading;[/font]
[font="'courier new', courier, monospace;"]namespace SocketConsole
{
class Program
{
static void Main(string[] args)
{
Thread thread1 = new Thread(new ThreadStart(Listener));
thread1.Start();[/font]
[font="'courier new', courier, monospace;"] while (true)
{
}
}[/font]
[font="'courier new', courier, monospace;"] public static void Listener()
{
try
{
Socket sktMain = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sktMain.Bind(new IPEndPoint(IPAddress.Parse("192.168.2.222"), 9999));
sktMain.Listen(10);
var message = new ArrayList();[/font]
[font="'courier new', courier, monospace;"] while (true)
{
// create the client socket
using (var client = sktMain.Accept())
{
//If connected,
if (SocketConnected(client, 100))
{
while (SocketConnected(client, 100))
{
byte[] sizeinfo = new byte[4];[/font]
[font="'courier new', courier, monospace;"] //read the size of the message into sizeinfo
int totalread = 0, currentread = 0;
currentread = totalread = client.Receive(sizeinfo, 4, SocketFlags.None);[/font]
[font="'courier new', courier, monospace;"] while (totalread < sizeinfo.Length && currentread > 0)
{
currentread = client.Receive(sizeinfo, totalread, sizeinfo.Length - totalread, SocketFlags.None);
totalread += currentread;
}[/font]
[font="'courier new', courier, monospace;"] int messagesize = 0;
messagesize |= sizeinfo[0];
messagesize |= (((int)sizeinfo[1]) << 8);
messagesize |= (((int)sizeinfo[2]) << 16);
messagesize |= (((int)sizeinfo[3]) << 24);[/font]
[font="'courier new', courier, monospace;"] byte[] data = new byte[messagesize];
totalread = 0;
currentread = totalread = client.Receive(data, 0, data.Length - totalread, SocketFlags.None);
var received = Encoding.UTF8.GetChars(data);[/font]
[font="'courier new', courier, monospace;"] int diff = data.Length - totalread;[/font]
[font="'courier new', courier, monospace;"] while (totalread < messagesize && currentread > 0)
{
currentread = client.Receive(data, 0, data.Length - totalread, SocketFlags.None);
totalread += currentread;
for (var i = 0; i < received.Length; i++)
message.Add(received[i]);
}
string fName = "runlog.txt";
if (File.Exists(fName)) File.Delete(fName);[/font]
[font="'courier new', courier, monospace;"] BinaryWriter bWrite = new BinaryWriter(File.Open(fName, FileMode.Create));
bWrite.Write(data);
bWrite.Close();
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}[/font]
[font="'courier new', courier, monospace;"] // socket polling
static bool SocketConnected(Socket s, int ms)
{
return !(s.Poll(ms, SelectMode.SelectRead) & (s.Available == 0));
}[/font]
[font="'courier new', courier, monospace;"] }
}[/font]
Attached Files
-
runlog.txt 3.51KB 4 downloads
#51669 5v Power Supply?
Posted by
cce1911
on 24 July 2013 - 07:57 PM
in
Netduino Plus 2 (and Netduino Plus 1)
This is a great question, but I'm curious to know what people are using for battery packs. My N+2 is driving a single 4 channel relay board...
#51676 N+2 Socket problem
Posted by
cce1911
on 25 July 2013 - 03:15 AM
in
Netduino Plus 2 (and Netduino Plus 1)
If I look at the byte array data, after receiving all the data, every byte above 255 has a value of 0. It's as if it stops reading at 255. If I debug.print in the while loop filling "data", I get the following output:
client accepting data client.Receive sizeinfo: currentread = 4, totalread = 4 total message size = 3296 client.Receive data: currentread = 252, totalread = 252 client.Receive data: currentread = 256 totalread = 508 client.Receive data: currentread = 256 totalread = 764 client.Receive data: currentread = 256 totalread = 1020 client.Receive data: currentread = 256 totalread = 1276 client.Receive data: currentread = 256 totalread = 1532 client.Receive data: currentread = 256 totalread = 1788 client.Receive data: currentread = 256 totalread = 2044 client.Receive data: currentread = 256 totalread = 2300 client.Receive data: currentread = 256 totalread = 2556 client.Receive data: currentread = 256 totalread = 2812 client.Receive data: currentread = 256 totalread = 3068 client.Receive data: currentread = 228 totalread = 3296 client.Receive data final: currentread = 228 totalread = 3296
So it is accepting 256 bytes each time, but they are all zero. Obviously, I don't understand what's going on:(
#51764 N+2 Socket problem
Posted by
cce1911
on 29 July 2013 - 02:40 PM
in
Netduino Plus 2 (and Netduino Plus 1)
I found the problem with my code. In the server app, the 2nd while loop should have had totalread instead of 0 for the second parameter of the .receive call. I was overwriting the data each time. Maybe this will help someone in the future...
#51765 Using a Netdruino 2 as a PLC
Posted by
cce1911
on 29 July 2013 - 02:51 PM
in
Netduino Plus 2 (and Netduino Plus 1)
I'm in the process of converting a PLC application over to the Netduino in order to reduce cost. I've been using Crouzet PLC's but they are too expensive and have too little RAM. The Netduino with a keypad, 2 line LCD and a cheap 4 relay board will do what I need at a fraction of the cost.
#51766 Adafruit Motor shield v2 library
Posted by
cce1911
on 29 July 2013 - 02:53 PM
in
Netduino Plus 2 (and Netduino Plus 1)
#51796 Toolbox.NETMF.Hardware.DS1307 problem
Posted by
cce1911
on 30 July 2013 - 07:16 PM
in
Netduino Plus 2 (and Netduino Plus 1)
I purchased this RTC: http://www.adafruit.com/products/264
But when I go to set the time using the Toolbox.NETMF.Hardware.DS1307 I get the following error:
"Something went wrong setting the time. Did you use proper pull-up resistors and is there a 3V battery connected?"
The wiring is pretty simple and I've double checked it (see pic).The kit has the resistors and the battery, any ideas?
Here is the code where it fails:
DS1307 RTC = new DS1307();
RTC.SetTime(2013, 7, 29, 23, 14, 0);
here is the toolbox code where the call is throwing an exception
public void SetTime(DateTime Time)
{
// Writing 7 bytes to the buffer, starting at address 0
int BytesTransferred = this._Device.Write(new byte[] {
0x00,
(byte)Tools.Hex2Dec(Time.Second.ToString()),
(byte)Tools.Hex2Dec(Time.Minute.ToString()),
(byte)Tools.Hex2Dec(Time.Hour.ToString()),
(byte)Tools.Hex2Dec(((int)Time.DayOfWeek).ToString()),
(byte)Tools.Hex2Dec(Time.Day.ToString()),
(byte)Tools.Hex2Dec(Time.Month.ToString()),
(byte)Tools.Hex2Dec((Time.Year - 2000).ToString())
});
if (BytesTransferred != 8) throw new ApplicationException("Something went wrong setting the time. Did you use proper pull-up resistors and is there a 3V battery connected?");
}
#51812 Toolbox.NETMF.Hardware.DS1307 problem
Posted by
cce1911
on 31 July 2013 - 04:26 AM
in
Netduino Plus 2 (and Netduino Plus 1)
It looks like this wiring diagram may have been for the N+: http://netmftoolbox....ailable classes
The N+2 has pins SC and SD. When I wired my RTC to these pins, everything worked.
#52087 N+2 Socket problem
Posted by
cce1911
on 11 August 2013 - 12:52 PM
in
Netduino Plus 2 (and Netduino Plus 1)
Zero, so far I have only tested with a single client.
#52135 Failed allocation while writing text file
Posted by
cce1911
on 14 August 2013 - 01:42 AM
in
Netduino 2 (and Netduino 1)
In my N+2 app, I log things to a text file for later debugging. I use this code in a function:
using (var filestream = new FileStream(@"SDrunlog.txt",FileMode.Append)) { StreamWriter streamWriter = new StreamWriter(filestream); streamWriter.WriteLine(DateTime.Now.ToString("MM/dd/yy H:mm:ss.fff") + ": " + strMsg); streamWriter.Close(); //Debug.Print(DateTime.Now.ToString("MM/dd/yy H:mm:ss.fff") + ": " + strMsg); }
When my log file gets over 33k I get a failed allocation error when creating the new streamwriter:
StreamWriter streamWriter = new StreamWriter(filestream);
Any idea on what is causing this and how to avoid it?
#52165 Failed allocation while writing text file
Posted by
cce1911
on 14 August 2013 - 08:01 PM
in
Netduino 2 (and Netduino 1)
Val, thanks for the reply. I've decided to start a new log file at 25k, but I will give Debug.GC a try.
-Capel
#52260 Quick question about ND+2 Socket
Posted by
cce1911
on 21 August 2013 - 12:50 PM
in
Netduino Plus 2 (and Netduino Plus 1)
http://msdn.microsof...y/ee434782.aspx
socket.listen(backlog)
backlog = The maximum number of incoming connections that can be queued for acceptance. Try
serverSocket.Listen(10);
#52261 Date from netduino plus
Posted by
cce1911
on 21 August 2013 - 12:56 PM
in
Netduino Plus 2 (and Netduino Plus 1)
I used the DS1307 real time clock from Adafruit: http://www.adafruit.com/products/264
#52262 Interrupt event handler conflicts
Posted by
cce1911
on 21 August 2013 - 01:47 PM
in
Netduino Plus 2 (and Netduino Plus 1)
I have a N+2 driving 2 stepper motors with the Sparkfun Easydriver. I have wired up several external buttons
InterruptPort ipT1 = new InterruptPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);ipT1.OnInterrupt += Target_OnInterruptT1;InterruptPort ipT2 = new InterruptPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLow);ipT2.OnInterrupt += Target_OnInterruptT2;
?
Here are my event handlers
static void Target_OnInterruptT1(uint data1, uint data2, DateTime time) { if (dtLastHit.AddMilliseconds(intBounceWait) > time) return; // prevent bounce dtLastHit = time; Debug.Print("Hit T1 = " + DateTime.Now.ToString("MM/dd/yy H:mm:ss.fff")); } static void Target_OnInterruptT2(uint data1, uint data2, DateTime time) { if (dtLastHit.AddMilliseconds(intBounceWait) > time) return; // prevent bounce dtLastHit = time; Debug.Print("Hit T2 = " + DateTime.Now.ToString("MM/dd/yy H:mm:ss.fff")); }
My problem is that when I press button T1 it randomly executes Target_OnInterruptT2 or Target_OnInterruptT1. No rhyme or reason. The same thing happens if I press button T2.
What is odd is that I've used this same exact board with 5 buttons, in the past, and had no problems. Any idea what is happening? I thought it might be EMI from the Easy driver, but I still get the same behavior even if I disconnect power to the stepper motors.
I'm scratching my head...
#54131 Sparkfun Shift Register Breakout - 74HC595
Posted by
cce1911
on 17 November 2013 - 08:45 PM
in
Netduino Plus 2 (and Netduino Plus 1)
Can someone point me to an example of using this breakout board with the Netduino?
https://www.sparkfun.../products/10680
I would like to use the .Net Microframework Toolbox, but it's not obvious to me how to wire it up.
#54160 Sparkfun Shift Register Breakout - 74HC595
Posted by
cce1911
on 19 November 2013 - 02:38 AM
in
Netduino Plus 2 (and Netduino Plus 1)
Thanks Grant, I'll check this out when I get back from my out-of-town trip!
#54192 Sparkfun Shift Register Breakout - 74HC595
Posted by
cce1911
on 20 November 2013 - 02:48 PM
in
Netduino Plus 2 (and Netduino Plus 1)
#54200 Sparkfun Shift Register Breakout - 74HC595
Posted by
cce1911
on 20 November 2013 - 10:30 PM
in
Netduino Plus 2 (and Netduino Plus 1)
Thanks for the reply Grant. Yes, I figured this out myself after you pointed me in the right direction.
#54202 Sparkfun Shift Register Breakout - 74HC595
Posted by
cce1911
on 20 November 2013 - 10:40 PM
in
Netduino Plus 2 (and Netduino Plus 1)
#54229 How to drive multiple lasers?
Posted by
cce1911
on 22 November 2013 - 06:07 PM
in
Netduino Plus 2 (and Netduino Plus 1)
So I have gotten my shift register to work with my N+2, but the lasers I'm trying to drive require 300mA of current each. So to drive 9 of these, I need almost 3A at 2.5 - 4.5 vdc. This is way too much for the N+2 and the 74HC595. I've been looking at some transistor arrays, but I'm not sure how to wire them. Can anyone point me to a circuit that uses this 8ch Darlington Sink driver (or something similar)?
#54235 How to drive multiple lasers?
Posted by
cce1911
on 22 November 2013 - 08:06 PM
in
Netduino Plus 2 (and Netduino Plus 1)
Paul,
Thanks for this very informative post. I was trying to avoid adding 9 components to my system, but based on your observations, that may be unavoidable. Given this, would MOSFETs be a better choice than Darlington pairs?
-Capel
#54700 Button Interrupts
Posted by
cce1911
on 15 December 2013 - 03:32 PM
in
Netduino Plus 2 (and Netduino Plus 1)
I'm seeing some odd behavior for what should be a simple project. Maybe I'm missing something and someone can point out the error of my ways?
What I'm trying to do is capture a sensor input. To test my code I've simulated the sensor with a simple momentary push button. See the schematic attached.
The problem is when I push one button, it triggers the interrupt for the other buttons. Here is my code:
public class Program2 { static DateTime dtLastPress; static int intBounceWait = 200; public static void Main() { InterruptPort ipT1 = new InterruptPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow); ipT1.OnInterrupt += T_OnInterruptT1; InterruptPort ipT2 = new InterruptPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow); ipT2.OnInterrupt += T_OnInterruptT2; InterruptPort ipT3 = new InterruptPort(Pins.GPIO_PIN_D2, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow); ipT3.OnInterrupt += T_OnInterruptT3; InterruptPort ipT4 = new InterruptPort(Pins.GPIO_PIN_D3, false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow); ipT3.OnInterrupt += T_OnInterruptT4; Thread.Sleep(Timeout.Infinite); } static void T_OnInterruptT1(uint data1, uint data2, DateTime time) { if (dtLastPress.AddMilliseconds(intBounceWait) > time) // prevent bounce { Debug.Print("T1 = bounce wait"); return; // prevent bounce } dtLastPress = time; RecordPress(1, time); } static void T_OnInterruptT2(uint data1, uint data2, DateTime time) { if (dtLastPress.AddMilliseconds(intBounceWait) > time) // prevent bounce { Debug.Print("T2 = bounce wait"); return; // prevent bounce } dtLastPress = time; RecordPress(2, time); } static void T_OnInterruptT3(uint data1, uint data2, DateTime time) { if (dtLastPress.AddMilliseconds(intBounceWait) > time) // prevent bounce { Debug.Print("T3 = bounce wait"); return; // prevent bounce } dtLastPress = time; RecordPress(3, time); } static void T_OnInterruptT4(uint data1, uint data2, DateTime time) { if (dtLastPress.AddMilliseconds(intBounceWait) > time) // prevent bounce { Debug.Print("T4 = bounce wait"); return; // prevent bounce } dtLastPress = time; RecordPress(4, time); } static void RecordPress(int intTarget, DateTime time) { Debug.Print("T" + intTarget.ToString() + " = " + DateTime.Now.ToString("MM/dd/yy H:mm:ss.fff")); } }
If I run the code and press the buttons in order (T1, T2, T3, T4) I get the following output:
#54703 Button Interrupts
Posted by
cce1911
on 15 December 2013 - 04:48 PM
in
Netduino Plus 2 (and Netduino Plus 1)
CW2, thanks for your response. I made the changes you suggested and still had a problem. Then I realized that I had not tied the 3v button cell ground to the NP2 ground. Once I did that, everything seems to work just fine.
- Netduino Forums
- → cce1911's Content
- Privacy Policy