Skip to content

Commit 01ba761

Browse files
authored
Merge pull request #1 from lucidcode/feature/500-ms-relay
Power relay off again after 500 ms
2 parents 1aa9cf7 + 142a3ea commit 01ba761

4 files changed

Lines changed: 122 additions & 116 deletions

File tree

Installer/Lucid Scribe Yocto PowerRelay.vdproj

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
{
1616
"Entry"
1717
{
18-
"MsmKey" = "8:_4210C5B26664BD7B4C21B3A1C66C3BE8"
18+
"MsmKey" = "8:_6239A709E7B8EB359ACA205220692EEC"
1919
"OwnerKey" = "8:_8A04AA9B98A94963AADF2135268ACC52"
2020
"MsmSig" = "8:_UNDEFINED"
2121
}
@@ -27,14 +27,14 @@
2727
}
2828
"Entry"
2929
{
30-
"MsmKey" = "8:_8A04AA9B98A94963AADF2135268ACC52"
31-
"OwnerKey" = "8:_UNDEFINED"
30+
"MsmKey" = "8:_823A42A1945F7319A7E9BB9BD7A9F128"
31+
"OwnerKey" = "8:_8A04AA9B98A94963AADF2135268ACC52"
3232
"MsmSig" = "8:_UNDEFINED"
3333
}
3434
"Entry"
3535
{
36-
"MsmKey" = "8:_963A2D1A0879D2BFCF882C976AB0FF59"
37-
"OwnerKey" = "8:_8A04AA9B98A94963AADF2135268ACC52"
36+
"MsmKey" = "8:_8A04AA9B98A94963AADF2135268ACC52"
37+
"OwnerKey" = "8:_UNDEFINED"
3838
"MsmSig" = "8:_UNDEFINED"
3939
}
4040
"Entry"
@@ -52,19 +52,19 @@
5252
"Entry"
5353
{
5454
"MsmKey" = "8:_UNDEFINED"
55-
"OwnerKey" = "8:_963A2D1A0879D2BFCF882C976AB0FF59"
55+
"OwnerKey" = "8:_8A04AA9B98A94963AADF2135268ACC52"
5656
"MsmSig" = "8:_UNDEFINED"
5757
}
5858
"Entry"
5959
{
6060
"MsmKey" = "8:_UNDEFINED"
61-
"OwnerKey" = "8:_8A04AA9B98A94963AADF2135268ACC52"
61+
"OwnerKey" = "8:_6239A709E7B8EB359ACA205220692EEC"
6262
"MsmSig" = "8:_UNDEFINED"
6363
}
6464
"Entry"
6565
{
6666
"MsmKey" = "8:_UNDEFINED"
67-
"OwnerKey" = "8:_4210C5B26664BD7B4C21B3A1C66C3BE8"
67+
"OwnerKey" = "8:_823A42A1945F7319A7E9BB9BD7A9F128"
6868
"MsmSig" = "8:_UNDEFINED"
6969
}
7070
}
@@ -164,21 +164,26 @@
164164
{
165165
"Name" = "8:.NET Framework"
166166
"Message" = "8:[VSDNETMSG]"
167-
"FrameworkVersion" = "8:3.5.30729 "
167+
"FrameworkVersion" = "8:3.5.30729 "
168168
"AllowLaterVersions" = "11:FALSE"
169169
"InstallUrl" = "8:http://go.microsoft.com/fwlink/?LinkId=76617"
170170
}
171171
}
172172
}
173173
"File"
174174
{
175-
"{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_4210C5B26664BD7B4C21B3A1C66C3BE8"
175+
"{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_6239A709E7B8EB359ACA205220692EEC"
176176
{
177177
"AssemblyRegister" = "3:1"
178178
"AssemblyIsInGAC" = "11:FALSE"
179179
"AssemblyAsmDisplayName" = "8:YocoWrapper, Version=1.0.0.0, Culture=neutral, processorArchitecture=x86"
180180
"ScatterAssemblies"
181181
{
182+
"_6239A709E7B8EB359ACA205220692EEC"
183+
{
184+
"Name" = "8:YocoWrapper.dll"
185+
"Attributes" = "3:512"
186+
}
182187
}
183188
"SourcePath" = "8:YocoWrapper.dll"
184189
"TargetName" = "8:"
@@ -218,13 +223,18 @@
218223
"IsDependency" = "11:FALSE"
219224
"IsolateTo" = "8:"
220225
}
221-
"{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_963A2D1A0879D2BFCF882C976AB0FF59"
226+
"{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_823A42A1945F7319A7E9BB9BD7A9F128"
222227
{
223228
"AssemblyRegister" = "3:1"
224229
"AssemblyIsInGAC" = "11:FALSE"
225230
"AssemblyAsmDisplayName" = "8:lucidcode.LucidScribe.Plugout.Interface, Version=1.0.3.0, Culture=neutral, processorArchitecture=MSIL"
226231
"ScatterAssemblies"
227232
{
233+
"_823A42A1945F7319A7E9BB9BD7A9F128"
234+
{
235+
"Name" = "8:lucidcode.LucidScribe.Plugout.Interface.dll"
236+
"Attributes" = "3:512"
237+
}
228238
}
229239
"SourcePath" = "8:lucidcode.LucidScribe.Plugout.Interface.dll"
230240
"TargetName" = "8:"
@@ -351,15 +361,15 @@
351361
{
352362
"Name" = "8:Microsoft Visual Studio"
353363
"ProductName" = "8:Lucid Scribe Yocto PowerRelay"
354-
"ProductCode" = "8:{C0F6BB14-216A-488B-A66B-7A73027764E7}"
355-
"PackageCode" = "8:{7D9E5DE7-A71F-4D41-919E-A9E8106B97BE}"
364+
"ProductCode" = "8:{8D76F4E4-A6AF-44C0-B8F1-1E481EBFFD9C}"
365+
"PackageCode" = "8:{104BFE63-3750-4531-814D-C6F684DD45CC}"
356366
"UpgradeCode" = "8:{F7366005-EA41-478D-BED9-08441C13A31E}"
357367
"AspNetVersion" = "8:4.0.30319.0"
358368
"RestartWWWService" = "11:FALSE"
359369
"RemovePreviousVersions" = "11:TRUE"
360370
"DetectNewerInstalledVersion" = "11:TRUE"
361371
"InstallAllUsers" = "11:TRUE"
362-
"ProductVersion" = "8:1.0.4"
372+
"ProductVersion" = "8:1.0.5"
363373
"Manufacturer" = "8:lucidcode"
364374
"ARPHELPTELEPHONE" = "8:"
365375
"ARPHELPLINK" = "8:http://www.lucidcode.com/Contact"

Yocto PowerRelay/PlugoutHandler.cs

Lines changed: 90 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,117 @@
11
using System;
2-
using System.Diagnostics;
3-
using System.IO.Ports;
42
using System.Threading;
53
using System.Windows.Forms;
6-
using System.Collections.Generic;
7-
using System.Runtime.InteropServices;
8-
using System.Drawing;
9-
using System.Linq;
10-
using System.IO;
11-
using System.Xml;
12-
using System.Net;
134

145
namespace lucidcode.LucidScribe.Plugout.Yocto.PowerRelay
156
{
16-
public class PlugoutHandler : lucidcode.LucidScribe.Interface.LucidPlugoutBase
17-
{
18-
19-
private Boolean Failed = false;
20-
private Boolean On = false;
21-
22-
private Thread SwitchOffThread;
23-
private Boolean SwitchingOff = false;
24-
25-
private Boolean AllowToSwitchOn = true;
26-
private Thread AllowToSwitchBackOnThread;
27-
28-
public override string Name
7+
public class PlugoutHandler : Interface.LucidPlugoutBase
298
{
30-
get { return "Yocto PowerRelay"; }
31-
}
32-
33-
public override bool Initialize()
34-
{
35-
return true;
36-
}
37-
38-
public override void Dispose()
39-
{
40-
return;
41-
}
429

43-
public override void Trigger()
44-
{
45-
try
46-
{
47-
if (Failed) return;
10+
private Boolean Failed = false;
11+
private Boolean On = false;
4812

49-
if (On) return;
13+
private Thread SwitchOffThread;
14+
private Boolean SwitchingOff = false;
5015

51-
if (!AllowToSwitchOn) return;
16+
private Boolean AllowToSwitchOn = true;
17+
private Thread AllowToSwitchBackOnThread;
5218

53-
YocoWrapper.YRelay relay;
54-
string errorMessage = "";
19+
public override string Name
20+
{
21+
get { return "Yocto PowerRelay"; }
22+
}
5523

56-
if (YocoWrapper.YAPI.RegisterHub("usb", ref errorMessage) != YocoWrapper.YAPI.SUCCESS)
24+
public override bool Initialize()
5725
{
58-
Failed = true;
59-
MessageBox.Show("RegisterHub Exception: " + errorMessage, "Yocto PowerRelay Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
26+
return true;
6027
}
6128

62-
relay = YocoWrapper.YRelay.FirstRelay();
63-
if (relay == null)
29+
public override void Dispose()
6430
{
65-
Failed = true;
66-
MessageBox.Show("No module connected (check USB cable).", "Yocto PowerRelay Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
31+
return;
6732
}
6833

69-
if (relay.isOnline())
34+
public override void Trigger()
7035
{
71-
if (relay.get_state() == YocoWrapper.YRelay.STATE_A)
72-
{
73-
relay.set_state(YocoWrapper.YRelay.STATE_B);
74-
}
75-
else
76-
{
77-
relay.set_state(YocoWrapper.YRelay.STATE_A);
78-
}
79-
80-
On = true;
81-
82-
if (!SwitchingOff)
83-
{
84-
// Turn it off in a minute
85-
SwitchOffThread = new Thread(SwitchOff);
86-
SwitchOffThread.Start();
87-
88-
// And allow it to turn back on in 10
89-
AllowToSwitchBackOnThread = new Thread(AllowToSwitchBackOn);
90-
AllowToSwitchBackOnThread.Start();
91-
}
36+
try
37+
{
38+
if (Failed) return;
39+
40+
if (On) return;
41+
42+
if (!AllowToSwitchOn) return;
43+
44+
YocoWrapper.YRelay relay;
45+
string errorMessage = "";
46+
47+
if (YocoWrapper.YAPI.RegisterHub("usb", ref errorMessage) != YocoWrapper.YAPI.SUCCESS)
48+
{
49+
Failed = true;
50+
MessageBox.Show("RegisterHub Exception: " + errorMessage, "Yocto PowerRelay Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
51+
}
52+
53+
relay = YocoWrapper.YRelay.FirstRelay();
54+
if (relay == null)
55+
{
56+
Failed = true;
57+
MessageBox.Show("No module connected (check USB cable).", "Yocto PowerRelay Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
58+
}
59+
60+
if (!relay.isOnline())
61+
{
62+
Failed = true;
63+
MessageBox.Show("tACS RegisterHub error: Module not connected (check USB cable).", "Yocto PowerRelay Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
64+
return;
65+
}
66+
67+
if (relay.get_state() == YocoWrapper.YRelay.STATE_A)
68+
{
69+
relay.set_state(YocoWrapper.YRelay.STATE_B);
70+
}
71+
else
72+
{
73+
relay.set_state(YocoWrapper.YRelay.STATE_A);
74+
}
75+
76+
On = true;
77+
78+
if (SwitchingOff)
79+
{
80+
return;
81+
}
82+
83+
// Turn it off in 500 ms
84+
SwitchOffThread = new Thread(SwitchOff);
85+
SwitchOffThread.Start();
86+
87+
// And allow it to turn back on in 1 second
88+
AllowToSwitchBackOnThread = new Thread(AllowToSwitchBackOn);
89+
AllowToSwitchBackOnThread.Start();
90+
}
91+
catch (Exception ex)
92+
{
93+
Failed = true;
94+
MessageBox.Show(ex.Message, "Yocto PowerRelay Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
95+
}
9296
}
93-
else
97+
98+
public void SwitchOff()
9499
{
95-
MessageBox.Show("tACS RegisterHub error: Module not connected (check USB cable).", "Yocto PowerRelay Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
100+
Thread.Sleep(500);
101+
On = false;
102+
SwitchingOff = true;
103+
Trigger();
104+
SwitchingOff = false;
105+
On = false;
106+
AllowToSwitchOn = false;
96107
}
97-
}
98-
catch (Exception ex)
99-
{
100-
Failed = true;
101-
MessageBox.Show(ex.Message, "Yocto PowerRelay Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
102-
}
103-
}
104108

105-
public void SwitchOff()
106-
{
107-
Thread.Sleep(1000 * 60);
108-
On = false;
109-
SwitchingOff = true;
110-
Trigger();
111-
SwitchingOff = false;
112-
On = false;
113-
AllowToSwitchOn = false;
114-
}
109+
public void AllowToSwitchBackOn()
110+
{
111+
Thread.Sleep(1000);
112+
AllowToSwitchOn = true;
113+
}
115114

116-
public void AllowToSwitchBackOn()
117-
{
118-
Thread.Sleep(1000 * 60 * 10);
119-
AllowToSwitchOn = true;
120115
}
121116

122-
}
123-
124117
}

Yocto PowerRelay/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("lucidcode")]
1212
[assembly: AssemblyProduct("Lucid Scribe Yocto PowerRelay Plugout")]
13-
[assembly: AssemblyCopyright("Copyright © lucidcode 2014")]
13+
[assembly: AssemblyCopyright("Copyright © lucidcode 2014-2026")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.4.0")]
36-
[assembly: AssemblyFileVersion("1.0.4.0")]
35+
[assembly: AssemblyVersion("1.0.5.0")]
36+
[assembly: AssemblyFileVersion("1.0.5.0")]

Yocto PowerRelay/Yocto PowerRelay.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
55
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -10,7 +10,7 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>lucidcode.LucidScribe.Plugout.Yocto.PowerRelay</RootNamespace>
1212
<AssemblyName>lucidcode.LucidScribe.Plugout.Yocto.PowerRelay</AssemblyName>
13-
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
1515
<FileUpgradeFlags>
1616
</FileUpgradeFlags>
@@ -31,6 +31,7 @@
3131
<IsWebBootstrapper>false</IsWebBootstrapper>
3232
<UseApplicationTrust>false</UseApplicationTrust>
3333
<BootstrapperEnabled>true</BootstrapperEnabled>
34+
<TargetFrameworkProfile />
3435
</PropertyGroup>
3536
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
3637
<DebugSymbols>true</DebugSymbols>
@@ -41,6 +42,7 @@
4142
<ErrorReport>prompt</ErrorReport>
4243
<WarningLevel>4</WarningLevel>
4344
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
45+
<Prefer32Bit>false</Prefer32Bit>
4446
</PropertyGroup>
4547
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
4648
<DebugType>pdbonly</DebugType>
@@ -51,6 +53,7 @@
5153
<WarningLevel>4</WarningLevel>
5254
<PlatformTarget>AnyCPU</PlatformTarget>
5355
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
56+
<Prefer32Bit>false</Prefer32Bit>
5457
</PropertyGroup>
5558
<ItemGroup>
5659
<Reference Include="lucidcode.LucidScribe.Plugout.Interface">

0 commit comments

Comments
 (0)