Hi guys,
I am having some troubles writing my code for a controller i'm building for an automated hydroponics project i'm working on. I have never used serial comms with the Netduino yet, so i'm kinda new at this thing. (I gave up on I2C, I guess i'm too stupid....) Excuse me for my terrible nomenclature, I've never had any programming training, but I will try my best.
I have two serial ports I need to communicate through. Both are just going to be sending commands, no Rx, RTS or CTS. Just one sending serial data to a Sparkfun serial enabled LCD, and the other to a LittleStep stepper controller. Should be straight forward...
This is the example I've been looking at for help.
http://blog.codeblac...with-RS232.aspx
Basically just trying to copy the code, but for some reason, the SerialPort class (nomenclature, not sure if this is actually a class...???) is not working properly... What am I doing wrong?
I also am having an issue with my Thread.Sleep(..) commands. Error: "The best overloaded method match for System.Threading.Thread.Sleep(int) has some invalid arguments." I basically want to turn the pump on for 30 mins, and off for 30 mins, and also control the lights ON and OFF timing.. The math converts hrs or mins to milliseconds. Anyway..Here's my code.. Thanks in advance guys!!!
Edit, just noticed in my code, uSec and notes say 'microseconds'. I realize its milliseconds, and the math should compute milliseconds... I guess that's what happens when you're tired.
using System;using System.Net;using System.Net.Sockets;using System.Threading;using System.IO.Ports;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.NetduinoPlus;namespace HydroControl{ public class Program { static SerialPort serialA; // Serial port on pins D0 & D1 for LCD comms static SerialPort serialB; // Serial port on pine D2 & D3 for Stepper Controller comms public static void Main() { Thread t1 = new Thread(Lights); t1.Start(); Thread t2 = new Thread(Pump); t2.Start(); Thread t3 = new Thread(Turn_Table); t3.Start(); Thread t4 = new Thread(Status); t4.Start(); } public static void Lights() { OutputPort Light_State = new OutputPort(Pins.GPIO_PIN_D2, false); // Define output for lights uint Light_ON_Time_min = 960; // In minutes, length of time lights are ON. 960 mins = 16 hrs **MUST BE WHOLE NUMBERS** uint Light_OFF_Time_min = 3600 - Light_ON_Time_min; // Calculates OFF time in minutes uint Light_ON_Time_uSec = (60 * 1000 * Light_ON_Time_min); // Calculates ON time in micro-seconds uint Light_OFF_Time_uSec = (60 * 1000 * Light_OFF_Time_min); // Calculates OFF time in micro-seconds Light_State.Write(true); Thread.Sleep(Light_ON_Time_uSec); Light_State.Write(false); Thread.Sleep(Light_OFF_Time_uSec); } public static void Pump() { OutputPort Pump_State = new OutputPort(Pins.GPIO_PIN_D3,false); // Define output for pump uint Cycle_Time_mins = 30; uint Cycle_Time_uSec = (Cycle_Time_mins * 60 * 1000); Pump_State.Write(true); Thread.Sleep(Cycle_Time_uSec); Pump_State.Write(false); Thread.Sleep(Cycle_Time_uSec); } public static void Status() { serialA = new SerialPort(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One); // Initialize COM1 serialA.Open(); serialA.Write("To Be Filled In Later.."); } public static void Turn_Table() { serialB = new SerialPort(SerialPorts.COM2, 9600, Parity.None, 8, StopBits.One); // Initialize COM2 serialB.Open(); serialB.Write("To Be Filled In Later.."); } }}