Microsoft ได้ ออก Net Micro Framework และมี Hardware Netduino ออกมา หลายรุ่น แล้ว และใช้ได้ กับ Visual studio ทั้ง Mac และ Windows
ต้อง Update Firmware เป็น ล่าสุด จะมี โปรแกรม neduinoDeploy
http://developer.wildernesslabs.co/Netduino
การใช้งาน ต้องลง NetMF SDK ก่อน
https://github.com/WildernessLabs/Netduino_SDK
เปิด Visual Studio และ เลือก Extension เป็น Micro Framework
สำหรับ
เมื่อลงแล้ว
ให้เลือก new project เป็น Micro framework console application
เลือก Reference
Microsoft.SPOT.Hardware
Microsoft.SPOT.IO
Microsoft.SPOT.Native
Microsoft.SPOT.Net
Secretlabs.NETMF.Hardware
Secretlabs.NETMF.Hardware.AnalogInput
Secretlabs.NETMF.Hardware.PWM
Secretlabs.NETMF.IO
ตัวอย่าง Code ที่ ใช้ใน Blink
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
namespace NetIot2
{
public class Program
{
public static void Main()
{
OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
int i = 0;
while(true)
{
led.Write(true);
Thread.Sleep(250);
led.Write(false);
Thread.Sleep(1250);
Debug.Print("count" + i.ToString());
i++;
}
}
}
}
ใน Visual studio Mac Run ได้เลย
ใน Visual studio Windows ต้อง แจ้ง Deployment เป็น USB ด้วย จึงจะ run ได้
วันเสาร์ที่ 24 พฤศจิกายน พ.ศ. 2561
วันพุธที่ 14 พฤศจิกายน พ.ศ. 2561
โปรแกรม Slide STL โดยใช้ Free Steel
/*
* Created by SharpDevelop.
* User: Administrator
* Date: 5/1/2014
* Time: 11:17 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Security.Cryptography;
using System.Diagnostics;
using System.Reflection;
//css_reference "c:/sls/Newtonsoft.Json.dll"
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Data.OleDb;
#if true
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using Platform = Autodesk.AutoCAD;
using PlatformDb = Autodesk.AutoCAD;
using PPCad;
using PPGenInput;
using Autodesk.AutoCAD.Windows;
#else
using Teigha.DatabaseServices;
using Teigha.Runtime;
using Teigha.Geometry;
using HostMgd.ApplicationServices;
using HostMgd.EditorInput;
using acadApp = HostMgd.ApplicationServices.Application;
using Platform = HostMgd;
using PlatformDb = Teigha;
using PPCad;
using PPGenInput;
using HostMgd.Windows;
#endif
using System.Data.OleDb;
using System.Net;
using System.Xml.Linq;
using Autodesk.AutoCAD.PlottingServices;
namespace PCivil5
{
class MyAcad
{
static double g_dia = 0.1;
public static void SlideM()
{
AcadUtil.SetVarInt("BACKGROUNDPLOT", 0);
// g_dia = AcadUtil.qGetDouble("Dia", g_dia);
g_dia = 0.1;
double zLevel = AcadUtil.qGetDouble("start Level:");
double zLevel2 = AcadUtil.qGetDouble("end Level:");
string fname = util.qGetFileDlg("Select STl", "", ".stl", false);
if (fname == "") return;
int i =0;
string prefix ="C:/temp/A";
AcadUtil.SetVarInt("TILEMODE", 1);
for (double dv = zLevel; dv < zLevel2; dv += 0.1)
{
AcadUtil.Msg(dv.ToString());
ObjectIdCollection ids = doSingleSlide(fname,dv,g_dia);
// hpglPlot(prefix + i.ToString());
AcadUtil.SetVarInt("TILEMODE", 0);
PlotALayout(prefix + i.ToString("##0"));
AcadUtil.SetVarInt("TILEMODE", 1);
foreach (ObjectId eId in ids)
{
AcadUtil.eraseEntity(eId);
}
i++;
}
// JSon2C.RootObject mydata= Newtonsoft.Json.JsonConvert.DeserializeObject<JSon2C.RootObject>(returntext);
}
public static void SimplePlot()
{
PlotALayout("c:/temp/aplot");
}
public static void PlotALayout(string fname )
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Transaction tr =
db.TransactionManager.StartTransaction();
using (tr)
{
// We'll be plotting the current layout
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(
db.CurrentSpaceId,
OpenMode.ForRead
);
Layout lo =
(Layout)tr.GetObject(
btr.LayoutId,
OpenMode.ForRead
);
// We need a PlotInfo object
// linked to the layout
PlotInfo pi = new PlotInfo();
pi.Layout = btr.LayoutId;
// We need a PlotSettings object
// based on the layout settings
// which we then customize
PlotSettings ps =
new PlotSettings(lo.ModelType);
ps.CopyFrom(lo);
// The PlotSettingsValidator helps
// create a valid PlotSettings object
PlotSettingsValidator psv =
PlotSettingsValidator.Current;
// We'll plot the extents, centered and
// scaled to fit
psv.SetPlotType(
ps,
Autodesk.AutoCAD.DatabaseServices.PlotType.Extents
);
psv.SetUseStandardScale(ps, true);
psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
psv.SetPlotCentered(ps, true);
// We'll use the standard DWF PC3, as
// for today we're just plotting to file
psv.SetPlotConfigurationName(
ps,
"7475A.pc3", "ANSI_A_(11.00_x_8.50_Inches)"
// "ISO A4 (297.00 x 210.00 MM)"
);
// We need to link the PlotInfo to the
// PlotSettings and then validate it
pi.OverrideSettings = ps;
PlotInfoValidator piv =
new PlotInfoValidator();
piv.MediaMatchingPolicy =
MatchingPolicy.MatchEnabled;
piv.Validate(pi);
// A PlotEngine does the actual plotting
// (can also create one for Preview)
if (PlotFactory.ProcessPlotState ==
ProcessPlotState.NotPlotting)
{
PlotEngine pe =
PlotFactory.CreatePublishEngine();
using (pe)
{
// Create a Progress Dialog to provide info
// and allow thej user to cancel
PlotProgressDialog ppd =
new PlotProgressDialog(false, 1, true);
using (ppd)
{
ppd.set_PlotMsgString(
PlotMessageIndex.DialogTitle,
"Custom Plot Progress"
);
ppd.set_PlotMsgString(
PlotMessageIndex.CancelJobButtonMessage,
"Cancel Job"
);
ppd.set_PlotMsgString(
PlotMessageIndex.CancelSheetButtonMessage,
"Cancel Sheet"
);
ppd.set_PlotMsgString(
PlotMessageIndex.SheetSetProgressCaption,
"Sheet Set Progress"
);
ppd.set_PlotMsgString(
PlotMessageIndex.SheetProgressCaption,
"Sheet Progress"
);
ppd.LowerPlotProgressRange = 0;
ppd.UpperPlotProgressRange = 100;
ppd.PlotProgressPos = 0;
// Let's start the plot, at last
ppd.OnBeginPlot();
ppd.IsVisible = true;
pe.BeginPlot(ppd, null);
// We'll be plotting a single document
pe.BeginDocument(
pi,
doc.Name,
null,
1,
true, // Let's plot to file
fname
);
// Which contains a single sheet
ppd.OnBeginSheet();
ppd.LowerSheetProgressRange = 0;
ppd.UpperSheetProgressRange = 100;
ppd.SheetProgressPos = 0;
PlotPageInfo ppi = new PlotPageInfo();
pe.BeginPage(
ppi,
pi,
true,
null
);
pe.BeginGenerateGraphics(null);
pe.EndGenerateGraphics(null);
// Finish the sheet
pe.EndPage(null);
ppd.SheetProgressPos = 100;
ppd.OnEndSheet();
// Finish the document
pe.EndDocument(null);
// And finish the plot
ppd.PlotProgressPos = 100;
ppd.OnEndPlot();
pe.EndPlot(null);
}
}
}
else
{
ed.WriteMessage(
"\nAnother plot is in progress."
);
}
}
}
public static void hpglPlot(string afile)
{
/* Point3d pt1 = AcadUtil.qGetPoint("Lower Left");
Point3d pt2 = new Point3d();
AcadUtil.getCorner(ref pt2, pt1);
string p1Str= pt1.X.ToString()+","+pt1.Y.ToString();
string p2Str = pt2.X.ToString()+","+pt2.Y.ToString();
*/
// string afile = "c:/temp/afile.plt";
string uIcon="";
string[] plWs = {
"-Plot",
"y",
"Model",
"7475A",
"ISO A4 (297.00 x 210.00 MM)",
"Inches",
"Landscape",
"No",
"Display",
// p1Str,
// p2Str,
"Fit",
"",
"no",
".",
"no",
"",
"y",
afile,
"n",
"y",
};
foreach (string s in plWs)
{
AcadUtil.SendCommand(s + "\n");
}
}
private static ObjectIdCollection doSingleSlide(string fname, double zLevel, double g_dia)
{
string doSlideTxt = gSlide(zLevel, g_dia, fname);
// JObject o2 = (JObject)JToken.FromObject(doSlideTxt);
JObject o2 = JObject.Parse(doSlideTxt);
SliceSTL2.RootObject obj1 = o2.ToObject<SliceSTL2.RootObject>();
ObjectIdCollection listId = new ObjectIdCollection();
ObjectIdCollection ids = new ObjectIdCollection(); // to hatch
for (int j = 0; j < obj1.polygons.Count; j++)
{
Polyline pl1 = new Polyline();
try
{
for (int i = 0; i < obj1.polygons[j].points.Count; i++)
{
pl1.AddVertexAt(i, new Point2d(obj1.polygons[j].points[i][0], obj1.polygons[j].points[i][1]), 0, 0, 0);
}
pl1.Elevation = zLevel;
// AcadUtil.Append2Dwg(pl1);
ObjectId ida = AcadUtil.Append2Dwg(pl1);
listId.Add(ida);
ids.Add(ida);
// AcadUtil.drawHatchPoly(ida, "SOLID", 1, 0);
}
catch { }
}
ObjectId idH = drawHatchPolys(ids, "SOLID", 1, 0);
if (idH != ObjectId.Null) listId.Add(idH);
return listId;
}
public static ObjectId drawHatchPolys(ObjectIdCollection mid, string hatchname, double hscale, double rotate)
{
ObjectId idret = ObjectId.Null;
Hatch ahatch = new Hatch();
ahatch.SetDatabaseDefaults();
try
{
ahatch.SetHatchPattern(HatchPatternType.PreDefined, hatchname);
}
catch
{
ahatch.SetHatchPattern(HatchPatternType.CustomDefined, hatchname);
}
Angle ang1 = new Angle(rotate);
Matrix3d m1 = Matrix3d.Rotation(ang1.rad, Vector3d.ZAxis, Point3d.Origin);
Matrix3d m2 = Matrix3d.Scaling(hscale, Point3d.Origin);
ahatch.TransformBy(m1 * m2);
// ahatch.ColorIndex = 1;
try
{
foreach (ObjectId id in mid)
{
ObjectIdCollection ids = new ObjectIdCollection();
ids.Add(id);
ahatch.AppendLoop(HatchLoopTypes.Default, ids);
}
ahatch.Associative = false;
ahatch.EvaluateHatch(true);
idret = AcadUtil.Append2DwgAuto(ahatch);
}
catch { }
return idret;
}
public static void singleSlide()
{
g_dia = AcadUtil.qGetDouble("Dia", g_dia);
double zLevel = AcadUtil.qGetDouble("Enter Level");
string fname = util.qGetFileDlg("Select STl", "", ".stl", false);
string doSlideTxt = gSlide(zLevel, g_dia, fname);
// JObject o2 = (JObject)JToken.FromObject(doSlideTxt);
JObject o2 = JObject.Parse(doSlideTxt);
SliceSTL2.RootObject obj1 = o2.ToObject<SliceSTL2.RootObject>();
ObjectIdCollection ids = new ObjectIdCollection();
for (int j = 0; j < obj1.polygons.Count; j++)
{
Polyline pl1 = new Polyline();
for (int i = 0; i < obj1.polygons[j].points.Count; i++)
{
pl1.AddVertexAt(i, new Point2d(obj1.polygons[j].points[i][0], obj1.polygons[j].points[i][1]), 0, 0, 0);
}
pl1.Elevation = zLevel;
ObjectId ida= AcadUtil.Append2Dwg(pl1);
ids.Add(ida);
}
drawHatchPolys(ids, "SOLID", 1, 0);
}
public static void testHatch()
{
ObjectId[] ids = PPCadJava.commonSelectSS();
ObjectIdCollection iddd = new ObjectIdCollection();
foreach(ObjectId id in ids)
{
iddd.Add(id);
}
drawHatchPolys(iddd,"SOLID",1,0);
}
static public string gSlide(double zLevel, double dia, string stlfile)
{ //insert image for autocad 2010-13 x64
string cPath = @"C:\Program Files (x86)\Freesteel Slicer\dist\";
string option = " -z" + zLevel.ToString() + " -l0.1 -r" + dia.ToString() + " -f0 " + stlfile;
Process cmd = new Process();
cmd.StartInfo.FileName = cPath + "slice.exe";
cmd.StartInfo.Arguments = option;
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.RedirectStandardError = true;
cmd.Start();
//* Read the output (or the error)
string output = cmd.StandardOutput.ReadToEnd();
// AcadUtil.Msg(output);
return output;
}
}
}
namespace SliceSTL2
{
// Json
public class Polygon
{
public List<List<double>> points { get; set; }
public string type { get; set; }
}
public class RootObject
{
public double z { get; set; }
public List<Polygon> polygons { get; set; }
}
}
สมัครสมาชิก:
บทความ (Atom)