Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
bvtvusn committed Oct 29, 2023
2 parents 6dedb79 + 4f1ca42 commit 8c2900c
Show file tree
Hide file tree
Showing 11 changed files with 400 additions and 120 deletions.
142 changes: 142 additions & 0 deletions BV_Modbus_Client/AboutWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions BV_Modbus_Client/AboutWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BV_Modbus_Client
{
public partial class AboutWindow : Form
{
public AboutWindow()
{
InitializeComponent();
//Assembly ass = Assembly.GetExecutingAssembly();
Version version = Assembly.GetExecutingAssembly().GetName().Version;
string softwareVersion = version.ToString();
lblVersion.Text = $"{softwareVersion}";
//lblVersion.Text = ass.GetName().Version.ToString();
lblAuthor.Text = "Bjørn Vegard Tveraaen";
lblDescription.Text = "A program acting as a modbus master. Used to read and write to modbus slaves. Supporting both Modbus TCP and modbus RTU. Can view several different data types. Includes function for continuously storing data to csv file. Historical data is plotted.";
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close(); // Close the "About" window
}

private void lblAuthor_Click(object sender, EventArgs e)
{

}

private void lblVersion_Click(object sender, EventArgs e)
{

}

private void lblDescription_Click(object sender, EventArgs e)
{

}

private void label1_Click(object sender, EventArgs e)
{

}
}
}
60 changes: 60 additions & 0 deletions BV_Modbus_Client/AboutWindow.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
2 changes: 1 addition & 1 deletion BV_Modbus_Client/BusinessLayer/FcWrapperBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public virtual (string, string)[] GetDataAsString(bool UseRegOnMissingDescriptio
//ushort[] databuffer = ReadFromBuffer(startAddress, NumberOfRegisters);

string[] strvalues = GetValueStrings();
string[] descriptions = GetRegDescriptions();
string[] descriptions = GetRegDescriptions(UseRegOnMissingDescription);
// string[] strvalues = FormatConverter.GetStringRepresentation(databuffer, DisplayType, SwapBytes, SwapRegisters);
// Function translates Databuffer into a string array
(string, string)[] strData = new (string, string)[Math.Min(strvalues.Length, descriptions.Length)];
Expand Down
4 changes: 2 additions & 2 deletions BV_Modbus_Client/BusinessLayer/FormatContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ internal ushort[] StringToBinary(string[] stringValues, bool logValue = true )
{
if (valueCounter < stringValues.Length)
{
string stringValue = stringValues[valueCounter];
string stringValue = stringValues[item.Register];
ushort[] valueData = item.StringToBinary(stringValue, logValue);

if (swapRegisters)
Expand All @@ -139,7 +139,7 @@ internal ushort[] StringToBinary(string[] stringValues, bool logValue = true )
Array.Copy(valueData,0, ushorts, item.Register, item.Length);

}
valueCounter++;
valueCounter+=item.Length;

}
return ushorts;
Expand Down
24 changes: 14 additions & 10 deletions BV_Modbus_Client/BusinessLayer/FormatConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ internal static ushort[] GetBinaryRepresentation(string rawString, FormatName fo
string[] groupedArray = Enumerable.Range(0, (int)Math.Ceiling((double)rawString.Length / 4))
.Select(i => rawString.Substring(i * 4, Math.Min(4, rawString.Length - i * 4))).ToArray();

result = groupedArray.Select(x => Convert.ToUInt16(x, 16)).ToArray();

ushort[] tempresult = groupedArray.Select(x => Convert.ToUInt16(x, 16)).ToArray();
Array.Copy(tempresult,0,result,result.Length - tempresult.Length,tempresult.Length);
//groupedArray.Select(x => Convert.ToUInt16(rawString.Substring(x * 4, 4), 16)).ToArray();

//System.Collections.IEnumerable tmp = Enumerable.Range(0, (rawString.Length-1 / 4)+1);
Expand All @@ -312,19 +312,23 @@ internal static ushort[] GetBinaryRepresentation(string rawString, FormatName fo
{
throw new FormatException("To many characters");
}
result = Enumerable.Range(0, rawString.Length / 16) // Divide by 16 since each ushort is represented by 16 binary digits
.Select(x => Convert.ToUInt16(rawString.Substring(x * 16, 16), 2))
.ToArray();

string[] groupedArray = Enumerable.Range(0, (int)Math.Ceiling((double)rawString.Length / 16))
.Select(i => rawString.Substring(i * 16, Math.Min(16, rawString.Length - i * 16))).ToArray();
ushort[] tempresult = groupedArray.Select(x => Convert.ToUInt16(x, 2)).ToArray();

//ushort[] tempresult = Enumerable.Range(0, rawString.Length / 16) // Divide by 16 since each ushort is represented by 16 binary digits
// .Select(x => Convert.ToUInt16(rawString.Substring(x * 16, 16), 2))
// .ToArray();
Array.Copy(tempresult, 0, result, result.Length - tempresult.Length, tempresult.Length);
//result[0] = Convert.ToUInt16(rawString, 2);
}


else if (format == FormatName.Uint32)
{
UInt32 number = UInt32.Parse(rawString);
result[0] = (UInt16)(number & 0xFFFF); // Store the lower 16 bits
result[1] = (UInt16)((number >> 16) & 0xFFFF); // Store the upper 16 bits
result[1] = (UInt16)(number & 0xFFFF); // Store the lower 16 bits
result[0] = (UInt16)((number >> 16) & 0xFFFF); // Store the upper 16 bits

//if (i % 2 == 0)
//{
Expand All @@ -343,8 +347,8 @@ internal static ushort[] GetBinaryRepresentation(string rawString, FormatName fo
else if (format == FormatName.Int32)
{
Int32 number = Int32.Parse(rawString);
result[0] = (UInt16)(number & 0xFFFF); // Store the lower 16 bits
result[1] = (UInt16)((number >> 16) & 0xFFFF); // Store the upper 16 bits
result[1] = (UInt16)(number & 0xFFFF); // Store the lower 16 bits
result[0] = (UInt16)((number >> 16) & 0xFFFF); // Store the upper 16 bits

}
else if (format == FormatName.Float)
Expand Down
3 changes: 2 additions & 1 deletion BV_Modbus_Client/FcView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ private void btnExecute_Click(object sender, EventArgs e)
else
{
MessageBox.Show("Please connect to a Modbus slave");

}

}
Expand Down Expand Up @@ -300,7 +301,7 @@ private void FillPreviewTable()
}
string[] dataValues = fcCommand.GetValueStrings(true);

(string, string)[] data = fcCommand.GetDataAsString();
(string, string)[] data = fcCommand.GetDataAsString(true);
if (data.Length > maxDisplayLength)
{
data = ((string, string)[])data.Take(maxDisplayLength).ToArray();
Expand Down
Loading

0 comments on commit 8c2900c

Please sign in to comment.