Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a couple modbus samples #58

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions Source/Meadow.Samples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CellularSample", "ProjectLa
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalSignalAnalyzer", "Meadow F7\IO\DigitalSignalAnalyzer\DigitalSignalAnalyzer.csproj", "{55594F06-C48C-46C0-84BA-23C364842E7F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StepperMotor_Sample", "Modbus\StepperMotor\StepperMotor_Sample.csproj", "{3F8BB18D-517E-4C3D-B140-F076A496055B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Motors.StepperOnline", "..\..\Meadow.Foundation\Source\Meadow.Foundation.Peripherals\Motors.StepperOnline\Driver\Motors.StepperOnline.csproj", "{319CC18B-525B-4833-8D8D-B280E37B6A08}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModbusStepperMotor_Sample", "ProjectLab\ModbusStepperMotor\ModbusStepperMotor_Sample.csproj", "{C1F7C00C-5130-442E-B6B4-EB588F9CBB7F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sensors.Environmental.Keller.XLine", "..\..\Meadow.Foundation\Source\Meadow.Foundation.Peripherals\Sensors.Environmental.Keller.XLine\Driver\Sensors.Environmental.Keller.XLine.csproj", "{C16D6D8B-F53B-4B6F-A41C-6DAD02BB12D2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KellerXLine_Sample", "Modbus\KellerXLine\KellerXLine_Sample.csproj", "{278CDA85-E114-4113-AC78-76103FFF8C47}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KellerXLineSample", "ProjectLab\KellerXLine\KellerXLineSample.csproj", "{72180A60-F721-42BD-93C9-DC58544CEDD9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -2615,6 +2627,48 @@ Global
{55594F06-C48C-46C0-84BA-23C364842E7F}.Simulation|Any CPU.ActiveCfg = Debug|Any CPU
{55594F06-C48C-46C0-84BA-23C364842E7F}.Simulation|Any CPU.Build.0 = Debug|Any CPU
{55594F06-C48C-46C0-84BA-23C364842E7F}.Simulation|Any CPU.Deploy.0 = Debug|Any CPU
{3F8BB18D-517E-4C3D-B140-F076A496055B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3F8BB18D-517E-4C3D-B140-F076A496055B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F8BB18D-517E-4C3D-B140-F076A496055B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F8BB18D-517E-4C3D-B140-F076A496055B}.Release|Any CPU.Build.0 = Release|Any CPU
{3F8BB18D-517E-4C3D-B140-F076A496055B}.Simulation|Any CPU.ActiveCfg = Debug|Any CPU
{3F8BB18D-517E-4C3D-B140-F076A496055B}.Simulation|Any CPU.Build.0 = Debug|Any CPU
{319CC18B-525B-4833-8D8D-B280E37B6A08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{319CC18B-525B-4833-8D8D-B280E37B6A08}.Debug|Any CPU.Build.0 = Debug|Any CPU
{319CC18B-525B-4833-8D8D-B280E37B6A08}.Release|Any CPU.ActiveCfg = Release|Any CPU
{319CC18B-525B-4833-8D8D-B280E37B6A08}.Release|Any CPU.Build.0 = Release|Any CPU
{319CC18B-525B-4833-8D8D-B280E37B6A08}.Simulation|Any CPU.ActiveCfg = Debug|Any CPU
{319CC18B-525B-4833-8D8D-B280E37B6A08}.Simulation|Any CPU.Build.0 = Debug|Any CPU
{C1F7C00C-5130-442E-B6B4-EB588F9CBB7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1F7C00C-5130-442E-B6B4-EB588F9CBB7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1F7C00C-5130-442E-B6B4-EB588F9CBB7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1F7C00C-5130-442E-B6B4-EB588F9CBB7F}.Release|Any CPU.Build.0 = Release|Any CPU
{C1F7C00C-5130-442E-B6B4-EB588F9CBB7F}.Simulation|Any CPU.ActiveCfg = Debug|Any CPU
{C1F7C00C-5130-442E-B6B4-EB588F9CBB7F}.Simulation|Any CPU.Build.0 = Debug|Any CPU
{C16D6D8B-F53B-4B6F-A41C-6DAD02BB12D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C16D6D8B-F53B-4B6F-A41C-6DAD02BB12D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C16D6D8B-F53B-4B6F-A41C-6DAD02BB12D2}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{C16D6D8B-F53B-4B6F-A41C-6DAD02BB12D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C16D6D8B-F53B-4B6F-A41C-6DAD02BB12D2}.Release|Any CPU.Build.0 = Release|Any CPU
{C16D6D8B-F53B-4B6F-A41C-6DAD02BB12D2}.Release|Any CPU.Deploy.0 = Release|Any CPU
{C16D6D8B-F53B-4B6F-A41C-6DAD02BB12D2}.Simulation|Any CPU.ActiveCfg = Debug|Any CPU
{C16D6D8B-F53B-4B6F-A41C-6DAD02BB12D2}.Simulation|Any CPU.Build.0 = Debug|Any CPU
{C16D6D8B-F53B-4B6F-A41C-6DAD02BB12D2}.Simulation|Any CPU.Deploy.0 = Debug|Any CPU
{278CDA85-E114-4113-AC78-76103FFF8C47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{278CDA85-E114-4113-AC78-76103FFF8C47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{278CDA85-E114-4113-AC78-76103FFF8C47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{278CDA85-E114-4113-AC78-76103FFF8C47}.Release|Any CPU.Build.0 = Release|Any CPU
{278CDA85-E114-4113-AC78-76103FFF8C47}.Simulation|Any CPU.ActiveCfg = Debug|Any CPU
{278CDA85-E114-4113-AC78-76103FFF8C47}.Simulation|Any CPU.Build.0 = Debug|Any CPU
{72180A60-F721-42BD-93C9-DC58544CEDD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72180A60-F721-42BD-93C9-DC58544CEDD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72180A60-F721-42BD-93C9-DC58544CEDD9}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{72180A60-F721-42BD-93C9-DC58544CEDD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72180A60-F721-42BD-93C9-DC58544CEDD9}.Release|Any CPU.Build.0 = Release|Any CPU
{72180A60-F721-42BD-93C9-DC58544CEDD9}.Release|Any CPU.Deploy.0 = Release|Any CPU
{72180A60-F721-42BD-93C9-DC58544CEDD9}.Simulation|Any CPU.ActiveCfg = Debug|Any CPU
{72180A60-F721-42BD-93C9-DC58544CEDD9}.Simulation|Any CPU.Build.0 = Debug|Any CPU
{72180A60-F721-42BD-93C9-DC58544CEDD9}.Simulation|Any CPU.Deploy.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2893,6 +2947,12 @@ Global
{44E9AEA0-C0E6-4C5F-93FD-3210255320B6} = {A809F07D-DD94-4375-8776-23FBE73591A5}
{9628FF7D-2852-41F9-A8C4-2B5B0012B0FA} = {DA0CC626-D072-457F-89B7-C22427D4C775}
{55594F06-C48C-46C0-84BA-23C364842E7F} = {0B3C904B-B328-4314-9BAC-E6E3D7B523CC}
{3F8BB18D-517E-4C3D-B140-F076A496055B} = {3B2ADC8C-1ACB-49F3-8A3C-4F453FF9FE75}
{319CC18B-525B-4833-8D8D-B280E37B6A08} = {A809F07D-DD94-4375-8776-23FBE73591A5}
{C1F7C00C-5130-442E-B6B4-EB588F9CBB7F} = {DA0CC626-D072-457F-89B7-C22427D4C775}
{C16D6D8B-F53B-4B6F-A41C-6DAD02BB12D2} = {A809F07D-DD94-4375-8776-23FBE73591A5}
{278CDA85-E114-4113-AC78-76103FFF8C47} = {3B2ADC8C-1ACB-49F3-8A3C-4F453FF9FE75}
{72180A60-F721-42BD-93C9-DC58544CEDD9} = {DA0CC626-D072-457F-89B7-C22427D4C775}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E3F002EA-1A25-487F-9A5D-93D1E7EC6E31}
Expand Down
14 changes: 14 additions & 0 deletions Source/Modbus/KellerXLine/KellerXLine_Sample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>10.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Peripherals\Sensors.Environmental.Keller.XLine\Driver\Sensors.Environmental.Keller.XLine.csproj" />
<ProjectReference Include="..\..\..\..\Meadow.Modbus\src\Meadow.Modbus\Meadow.Modbus.csproj" />
</ItemGroup>
</Project>
36 changes: 36 additions & 0 deletions Source/Modbus/KellerXLine/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Meadow.Foundation.Sensors.Environmental;
using Meadow.Hardware;
using Meadow.Modbus;

namespace KellerXLine_Sample;

internal class Program
{
private static async Task Main(string[] _)
{
await Test();
}

private static async Task Test()
{

var serialPort = "COM12";

using (var port = new SerialPortShim(serialPort, KellerTransducer.DefaultBaudRate, Parity.None, 8, StopBits.One))
{
port.ReadTimeout = TimeSpan.FromSeconds(15);
port.Open();

var client = new ModbusRtuClient(port);
var sensor = new KellerTransducer(client, KellerTransducer.DefaultModbusAddress);

while (true)
{
var pressure = await sensor.ReadPressure(PressureChannel.P1);
Console.WriteLine($"Pressure: {pressure.Millibar} mbar");

await Task.Delay(1000);
}
}
}
}
36 changes: 36 additions & 0 deletions Source/Modbus/StepperMotor/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Meadow.Foundation.MotorControllers.StepperOnline;
using Meadow.Foundation.Motors.StepperOnline;
using Meadow.Hardware;
using Meadow.Modbus;

namespace StepperMotor_Sample;

internal class Program
{
private static async Task Main(string[] _)
{
var serialPort = "COM12";
byte controllerAddress = BLD510B.DefaultModbusAddress;

using (var port = new SerialPortShim(serialPort, BLD510B.DefaultBaudRate, Parity.None, 8, StopBits.One))
{
port.ReadTimeout = TimeSpan.FromSeconds(15);
port.Open();

var client = new ModbusRtuClient(port);
var controller = new BLD510B(client);
var motor = new F55B150_24GL_30S(controller);
motor.SetSpeed(new Meadow.Units.AngularVelocity(500, Meadow.Units.AngularVelocity.UnitType.RevolutionsPerMinute));

while (true)
{
await motor.RunFor(TimeSpan.FromSeconds(5), Meadow.Peripherals.RotationDirection.Clockwise);
await motor.Stop();
await Task.Delay(1000);
await motor.RunFor(TimeSpan.FromSeconds(5), Meadow.Peripherals.RotationDirection.CounterClockwise);
await motor.Stop();
await Task.Delay(1000);
}
}
}
}
14 changes: 14 additions & 0 deletions Source/Modbus/StepperMotor/StepperMotor_Sample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>10.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Peripherals\Motors.StepperOnline\Driver\Motors.StepperOnline.csproj" />
<ProjectReference Include="..\..\..\..\Meadow.Modbus\src\Meadow.Modbus\Meadow.Modbus.csproj" />
</ItemGroup>
</Project>
24 changes: 24 additions & 0 deletions Source/ProjectLab/KellerXLine/KellerXLineSample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Meadow.Sdk/1.1.0">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<OutputType>Library</OutputType>
<AssemblyName>App</AssemblyName>
<LangVersion>10.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Peripherals\Sensors.Environmental.Keller.XLine\Driver\Sensors.Environmental.Keller.XLine.csproj" />
<ProjectReference Include="..\..\..\..\Meadow.ProjectLab\Source\Meadow.ProjectLab\Meadow.ProjectLab.csproj" />
<ProjectReference Include="..\..\..\..\Meadow.Modbus\src\Meadow.Modbus\Meadow.Modbus.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="app.build.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="app.config.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
43 changes: 43 additions & 0 deletions Source/ProjectLab/KellerXLine/MeadowApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Meadow;
using Meadow.Devices;
using Meadow.Foundation.Sensors.Environmental;
using System;
using System.Threading.Tasks;

namespace KellerXLine_Sample;

// Change ProjectLabCoreComputeApp to ProjectLabFeatherApp for ProjectLab v2
public class MeadowApp : ProjectLabCoreComputeApp
{
private IKellerTransducer sensor;

public override Task Initialize()
{
Resolver.Log.Info("Initialize...");

Resolver.Log.Info($"Running on ProjectLab Hardware {Hardware.RevisionString}");

var client = Hardware.GetModbusRtuClient(KellerTransducer.DefaultBaudRate);
sensor = new KellerTransducer(client, KellerTransducer.DefaultModbusAddress);

return base.Initialize();
}

public override async Task Run()
{
while (true)
{
try
{
var pressure = await sensor.ReadPressure(PressureChannel.P1);
Resolver.Log.Info($"Pressure: {pressure.Millibar} mbar");
}
catch (Exception ex)
{
Resolver.Log.Info($"Error: {ex.Message}");
}

await Task.Delay(1000);
}
}
}
2 changes: 2 additions & 0 deletions Source/ProjectLab/KellerXLine/app.build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Deploy:
NoLink: [ ProjectLab ]
21 changes: 21 additions & 0 deletions Source/ProjectLab/KellerXLine/app.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Uncomment additional options as needed.
# To learn more about these config options, including custom application configuration settings, check out the Application Settings Configuration documentation.
# http://developer.wildernesslabs.co/Meadow/Meadow.OS/Configuration/Application_Settings_Configuration/

# App lifecycle configuration.
Lifecycle:

# Control whether Meadow will restart when an unhandled app exception occurs. Combine with Lifecycle > AppFailureRestartDelaySeconds to control restart timing.
RestartOnAppFailure: false

# When app set to restart automatically on app failure,
AppFailureRestartDelaySeconds: 15

# Logging configuration.
Logging:

# Adjust the level of logging detail.
LogLevel:

# Trace, Debug, Information, Warning, or Error
Default: Trace
41 changes: 41 additions & 0 deletions Source/ProjectLab/ModbusStepperMotor/MeadowApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Meadow;
using Meadow.Devices;
using Meadow.Foundation.MotorControllers.StepperOnline;
using Meadow.Foundation.Motors.StepperOnline;
using System;
using System.Threading.Tasks;

namespace StepperMotor_Sample;

// Change ProjectLabCoreComputeApp to ProjectLabFeatherApp for ProjectLab v2
public class MeadowApp : ProjectLabCoreComputeApp
{
private F55B150_24GL_30S motor;

public override Task Initialize()
{
Resolver.Log.Info("Initialize...");

Resolver.Log.Info($"Running on ProjectLab Hardware {Hardware.RevisionString}");

var client = Hardware.GetModbusRtuClient(BLD510B.DefaultBaudRate);
var controller = new BLD510B(client, BLD510B.DefaultModbusAddress);
motor = new F55B150_24GL_30S(controller);
motor.SetSpeed(new Meadow.Units.AngularVelocity(500, Meadow.Units.AngularVelocity.UnitType.RevolutionsPerMinute));

return base.Initialize();
}

public override async Task Run()
{
while (true)
{
await motor.RunFor(TimeSpan.FromSeconds(5), Meadow.Peripherals.RotationDirection.Clockwise);
await motor.Stop();
await Task.Delay(1000);
await motor.RunFor(TimeSpan.FromSeconds(5), Meadow.Peripherals.RotationDirection.CounterClockwise);
await motor.Stop();
await Task.Delay(1000);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Meadow.Sdk/1.1.0">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<OutputType>Library</OutputType>
<AssemblyName>App</AssemblyName>
<LangVersion>10.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\Meadow.ProjectLab\Source\Meadow.ProjectLab\Meadow.ProjectLab.csproj" />
<ProjectReference Include="..\..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Peripherals\Motors.StepperOnline\Driver\Motors.StepperOnline.csproj" />
<ProjectReference Include="..\..\..\..\Meadow.Modbus\src\Meadow.Modbus\Meadow.Modbus.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="app.build.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="app.config.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions Source/ProjectLab/ModbusStepperMotor/app.build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Deploy:
NoLink: [ ProjectLab, Motors.StepperOnline ]
21 changes: 21 additions & 0 deletions Source/ProjectLab/ModbusStepperMotor/app.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Uncomment additional options as needed.
# To learn more about these config options, including custom application configuration settings, check out the Application Settings Configuration documentation.
# http://developer.wildernesslabs.co/Meadow/Meadow.OS/Configuration/Application_Settings_Configuration/

# App lifecycle configuration.
Lifecycle:

# Control whether Meadow will restart when an unhandled app exception occurs. Combine with Lifecycle > AppFailureRestartDelaySeconds to control restart timing.
RestartOnAppFailure: false

# When app set to restart automatically on app failure,
AppFailureRestartDelaySeconds: 15

# Logging configuration.
Logging:

# Adjust the level of logging detail.
LogLevel:

# Trace, Debug, Information, Warning, or Error
Default: Trace
Loading