Skip to content

Commit

Permalink
Doplnění funkce "CmdGetOutputs" (Papouch.Spinel.Spinel97.Device.Quido).
Browse files Browse the repository at this point in the history
Přejmenování funkce "CmdSetRele" na "CmdSetOutput".
Rozšíření funkce "CmdSetOutput" o možnost nastavení stavu na určitou dobu.
Rozšíření ukázkového projektu "QuidoDemo" o čtení stavu výstupů.
  • Loading branch information
Papouchcom committed May 24, 2018
1 parent b1b7faf commit 3b2d7dd
Show file tree
Hide file tree
Showing 7 changed files with 430 additions and 39 deletions.
230 changes: 212 additions & 18 deletions .NET QuidoDemo/FormMain.Designer.cs

Large diffs are not rendered by default.

100 changes: 90 additions & 10 deletions .NET QuidoDemo/FormMain.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using System;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
//using System.Reflection;

using Papouch.Communication;
using Papouch.Spinel;
using Papouch.Spinel.Spinel97;
using Papouch.Utils;

using System.IO.Ports;

using System.Threading;


namespace QuidoDemo
{
public partial class FormMain : Form
Expand All @@ -37,6 +38,8 @@ private void FormMain_Load(object sender, EventArgs e)
if (val != null) textBoxDeviceString.Text = val.ToString();
key.Close();
}
reloadSerialPortNames(sender, e);
radioButtonProviderChange(sender, e);
}

private void FormMain_FormClosed(object sender, FormClosedEventArgs e)
Expand Down Expand Up @@ -90,10 +93,14 @@ private void checkFormControls()
buttonGetInfo.Enabled = bq;
buttonGetInfoCore.Enabled = bq;

buttonGetOutputs.Enabled = bq;
buttonSetOutputOn.Enabled = bq;
buttonSetOutputOff.Enabled = bq;
numericOutputIndex.Enabled = bq;
labelOutputIndex.Enabled = bq;
numericOutputTimer.Enabled = bq;
labelOutputTimer.Enabled = bq;


buttonGetInputs.Enabled = bq;

Expand Down Expand Up @@ -123,8 +130,15 @@ private void buttonCiCreate_Click(object sender, EventArgs e)
}
else
{
ci = new CiSerialPort();
ci.ConfigString = textBoxConnectionString.Text;
try
{
ci = new CiSerialPort();
ci.ConfigString = textBoxConnectionString.Text;
}
catch (Exception e)
{
LogMsg("Exception: {0}", e.Message);
}
}

LogMsg("CREATE CI");
Expand Down Expand Up @@ -255,13 +269,31 @@ private void buttonGetInfoCore_Click(object sender, EventArgs e)

#region Commands: Outputs

private void buttonGetOutputs_Click(object sender, EventArgs e)
{
if (quido != null)
{
LogMsg("*** GetOutputs ***");

bool[] outputs = null;
if (quido.CmdGetOutputs(out outputs))
{
for (int index = 0; index < outputs.Length; index++)
{
LogMsg("Output " + index.ToString() + " is " + ((outputs[index]) ? "ON" : "OFF"));
}
}
}
}

private void buttonSetRele1On_Click(object sender, EventArgs e)
{
if (quido != null)
{
byte index = (byte)numericOutputIndex.Value;

if (quido.CmdSetRele(index, true))
byte timer = (byte)numericOutputTimer.Value;

if (quido.CmdSetOutput(index, true, timer))
{
LogMsg("Quido Rele {0} = on", index);
}
Expand All @@ -277,8 +309,9 @@ private void buttonSetRele1Off_Click(object sender, EventArgs e)
if (quido != null)
{
byte index = (byte)numericOutputIndex.Value;

if (quido.CmdSetRele(index, false))
byte timer = (byte)numericOutputTimer.Value;

if (quido.CmdSetOutput(index, false, timer))
{
LogMsg("Quido Rele {0} = off", index);
}
Expand Down Expand Up @@ -472,5 +505,52 @@ private void InputChange(Papouch.Spinel.Spinel97.Device.Quido.Quido quido, int i

#endregion

private void radioButtonProviderChange(object sender, EventArgs e)
{
textBoxTcpPort.Enabled = radioButtonTcpClient.Checked;
textBoxTcpHost.Enabled = radioButtonTcpClient.Checked;

comboBoxSerialPortName.Enabled = radioButtonSerialPort.Checked;
comboBoxSerialPortBaudRate.Enabled = radioButtonSerialPort.Checked;

providerSettingsChange(sender, e);
}
private void providerSettingsChange(object sender, EventArgs e)
{
string s = "";
if (radioButtonSerialPort.Checked)
{
s += "provider=SERIAL_PORT;";
s += "PortName=" + comboBoxSerialPortName.SelectedItem + ";";
s += "BaudRate=" + comboBoxSerialPortBaudRate.SelectedItem + ";";
}
else
if (radioButtonTcpClient.Checked)
{
s += "provider=TCP_CLIENT;";
s += "Host=" + textBoxTcpHost.Text + ";";
s += "Port=" + textBoxTcpPort.Text + ";";
}
textBoxConnectionString.Text = s;
}

private void reloadSerialPortNames(object sender, EventArgs e)
{
comboBoxSerialPortName.BeginUpdate();
try
{
comboBoxSerialPortName.Items.Clear();

string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)
{
comboBoxSerialPortName.Items.Add(port);
}
}
finally
{
comboBoxSerialPortName.EndUpdate();
}
}
}
}
15 changes: 11 additions & 4 deletions Papouch.Comunication/CsPropertyObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,21 @@ private void ParseCsItem(string s)

protected void ParseCs(string cs)
{
string[] sa = cs.Split(';');
foreach (string s in sa)
try
{
if (s != "")
string[] sa = cs.Split(';');
foreach (string s in sa)
{
ParseCsItem(s);
if (s != "")
{
ParseCsItem(s);
}
}
}
catch
{

}
}
#endregion
}
Expand Down
4 changes: 4 additions & 0 deletions Papouch.Spinel/Papouch.Spinel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
<Compile Include="Spinel97.SpinelStack.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Papouch.Comunication\Papouch.Comunication.csproj">
<Project>{22ac128a-2ff6-4d39-96af-ca023025bb4d}</Project>
<Name>Papouch.Comunication</Name>
</ProjectReference>
<ProjectReference Include="..\Papouch.Utils\Papouch.Utils.csproj">
<Project>{4e14856b-8b6d-4166-a736-1ecd5e54e2be}</Project>
<Name>Papouch.Utils</Name>
Expand Down
68 changes: 62 additions & 6 deletions Papouch.Spinel/Spinel97.Device.Quido.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Quido:Device
public byte S97_INST_QUIDO_SetCounterSettings = 0x6A; // Nastavení čítačů
public byte S97_INST_QUIDO_GetCounterSettings = 0x6B; // Čtení nastavení čítačů
public byte S97_INST_QUIDO_SetOutput = 0x20; // Nastavení výstupů
public byte S97_INST_QUIDO_SetOutputTimered = 0x23; // Nastavení výstupů na určitou dobu
public byte S97_INST_QUIDO_GetOutputs = 0x30; // Čtení výstupů

public int InputCount = -1; // Počet vstupů Quida
Expand All @@ -29,20 +30,42 @@ public Quido(ICommunicationInterface ci, byte spinelADR)
{

}


[Obsolete("Use method \"CmdSetOutput()\"")]
public Boolean CmdSetRele(byte rele, Boolean value, byte timer = 0)
{
return CmdSetOutput(rele, value, timer);
}

/// <summary>
/// Nastavení výstupu
/// </summary>
/// <param name="rele">výstup (indexováno od 1)</param>
/// <param name="value">požadovaný stav</param>
/// <param name="timer">čas po který bude výstup nastaven do požadovaného stavu, poté dojde ke změně na opačný stav. ( 1-255 * 0.5s )</param>
/// <returns>vrací True v případě potvrzení příkazu modulem</returns>
public Boolean CmdSetRele(byte rele, Boolean value)
public Boolean CmdSetOutput(byte rele, Boolean value, byte timer = 0)
{
PacketSpinel97 txPacket = new PacketSpinel97(S97_INST_QUIDO_SetOutput);
txPacket.ADR = this.ADR;
PacketSpinel97 txPacket = new PacketSpinel97();
byte[] data;

byte[] data = new byte[1];
data[0] = (byte)( ((value) ? 0x80 : 0x00) | ( rele & 0x7F) );
if (timer == 0)
{
txPacket.INST = S97_INST_QUIDO_SetOutput;

data = new byte[1];
data[0] = (byte)(((value) ? 0x80 : 0x00) | (rele & 0x7F));

} else {

txPacket.INST = S97_INST_QUIDO_SetOutputTimered;

data = new byte[2];
data[0] = timer;
data[1] = (byte)(((value) ? 0x80 : 0x00) | (rele & 0x7F));
}

txPacket.ADR = this.ADR;

txPacket.SDATA = data;

Expand All @@ -53,6 +76,39 @@ public Boolean CmdSetRele(byte rele, Boolean value)
return true;
}
return false;

}

/// <summary>
/// Čtení stavu výstupů / relé
/// </summary>
/// <param name="outputs"></param>
/// <returns>vrací True pokud je přijata a zpracována korektní odpověď</returns>
public Boolean CmdGetOutputs(out Boolean[] outputs)
{
outputs = null;

PacketSpinel97 txPacket = new PacketSpinel97(S97_INST_QUIDO_GetOutputs);
txPacket.ADR = this.ADR;
PacketSpinel97 rxPacket;

if (SendAndReceive(ref txPacket, out rxPacket) && (rxPacket.INST == S97_ACK_OK))
{
if (rxPacket.SDATA != null)
{
outputs = new Boolean[(InputCount > -1) ? InputCount : rxPacket.SDATA.Length * 8];

byte index = 0;
while ((index < outputs.Length) && ((index / 8) < rxPacket.SDATA.Length))
{
outputs[index] = (((rxPacket.SDATA[rxPacket.SDATA.Length - (index / 8) - 1]) & (1 << (index % 8))) != 0);
index++;
}

return true;
}
}
return false;
}

/// <summary>
Expand Down
41 changes: 41 additions & 0 deletions Performance1.psess
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<VSPerformanceSession Version="1.00">
<Options>
<Solution>Quido.NET.sln</Solution>
<CollectionMethod>Sampling</CollectionMethod>
<AllocationMethod>None</AllocationMethod>
<AddReport>true</AddReport>
<ResourceBasedAnalysisSelected>true</ResourceBasedAnalysisSelected>
<UniqueReport>Timestamp</UniqueReport>
<SamplingMethod>Cycles</SamplingMethod>
<CycleCount>10000000</CycleCount>
<PageFaultCount>10</PageFaultCount>
<SysCallCount>10</SysCallCount>
<SamplingCounter Name="" ReloadValue="00000000000f4240" DisplayName="" />
<RelocateBinaries>false</RelocateBinaries>
<HardwareCounters EnableHWCounters="false" />
<EtwSettings />
<PdhSettings>
<PdhCountersEnabled>false</PdhCountersEnabled>
<PdhCountersRate>500</PdhCountersRate>
<PdhCounters>
<PdhCounter>\Fyzick&amp;#253; disk(_Total)\Středn&amp;#237; d&amp;#233;lka fronty disku</PdhCounter>
<PdhCounter>\Paměť\Str&amp;#225;nky/s</PdhCounter>
<PdhCounter>\Procesor(_Total)\% času procesoru</PdhCounter>
</PdhCounters>
</PdhSettings>
</Options>
<ExcludeSmallFuncs>true</ExcludeSmallFuncs>
<JScriptProfilingEnabled>false</JScriptProfilingEnabled>
<PreinstrumentEvent>
<InstrEventExclude>false</InstrEventExclude>
</PreinstrumentEvent>
<PostinstrumentEvent>
<InstrEventExclude>false</InstrEventExclude>
</PostinstrumentEvent>
<Reports>
<Report>
<Path>Report170510.vspx</Path>
</Report>
</Reports>
</VSPerformanceSession>
11 changes: 10 additions & 1 deletion Quido.NET.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuidoDemo", ".NET QuidoDemo\QuidoDemo.csproj", "{83C08910-C5F6-402C-8542-120738E09436}"
EndProject
Expand All @@ -13,7 +13,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Papouch.Utils", "Papouch.Ut
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Communication Interface Demo", "Communication Interface Demo\Communication Interface Demo.csproj", "{F23CDD62-AE70-492B-A2DF-934F11088417}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EAB20BA0-D586-4E16-BE91-443620F819C8}"
ProjectSection(SolutionItems) = preProject
Changelog.txt = Changelog.txt
Performance1.psess = Performance1.psess
EndProjectSection
EndProject
Global
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Expand Down

0 comments on commit 3b2d7dd

Please sign in to comment.