mirror of
https://github.com/fbarresi/Sharp7.git
synced 2026-02-04 08:42:51 +00:00
solved all warnings for S7Client
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
#pragma warning disable 618
|
|
||||||
|
|
||||||
namespace Sharp7
|
namespace Sharp7
|
||||||
{
|
{
|
||||||
@@ -241,7 +240,7 @@ namespace Sharp7
|
|||||||
0x12, // Var spec.
|
0x12, // Var spec.
|
||||||
0x0a, // Length of remaining bytes
|
0x0a, // Length of remaining bytes
|
||||||
0x10, // Syntax ID
|
0x10, // Syntax ID
|
||||||
(byte)S7Consts.S7WLByte, // Transport Size idx=22
|
(byte)S7WordLength.Byte, // Transport Size idx=22
|
||||||
0x00,0x00, // Num Elements
|
0x00,0x00, // Num Elements
|
||||||
0x00,0x00, // DB Number (if any, else 0)
|
0x00,0x00, // DB Number (if any, else 0)
|
||||||
0x84, // Area Type
|
0x84, // Area Type
|
||||||
@@ -274,7 +273,7 @@ namespace Sharp7
|
|||||||
0x12, // Var spec.
|
0x12, // Var spec.
|
||||||
0x0a, // Length of remaining bytes
|
0x0a, // Length of remaining bytes
|
||||||
0x10, // Syntax ID
|
0x10, // Syntax ID
|
||||||
(byte)S7Consts.S7WLByte, // Transport Size idx=3
|
(byte)S7WordLength.Byte, // Transport Size idx=3
|
||||||
0x00,0x00, // Num Elements
|
0x00,0x00, // Num Elements
|
||||||
0x00,0x00, // DB Number (if any, else 0)
|
0x00,0x00, // DB Number (if any, else 0)
|
||||||
0x84, // Area Type
|
0x84, // Area Type
|
||||||
@@ -301,7 +300,7 @@ namespace Sharp7
|
|||||||
0x12, // Var spec.
|
0x12, // Var spec.
|
||||||
0x0a, // Length of remaining bytes
|
0x0a, // Length of remaining bytes
|
||||||
0x10, // Syntax ID
|
0x10, // Syntax ID
|
||||||
(byte)S7Consts.S7WLByte, // Transport Size idx=3
|
(byte)S7WordLength.Byte, // Transport Size idx=3
|
||||||
0x00,0x00, // Num Elements
|
0x00,0x00, // Num Elements
|
||||||
0x00,0x00, // DB Number (if any, else 0)
|
0x00,0x00, // DB Number (if any, else 0)
|
||||||
0x84, // Area Type
|
0x84, // Area Type
|
||||||
@@ -847,25 +846,25 @@ namespace Sharp7
|
|||||||
Time_ms = 0;
|
Time_ms = 0;
|
||||||
int Elapsed = Environment.TickCount;
|
int Elapsed = Environment.TickCount;
|
||||||
// Some adjustment
|
// Some adjustment
|
||||||
if (Area == S7Consts.S7AreaCT)
|
if (Area == (int)S7Area.CT)
|
||||||
WordLen = S7Consts.S7WLCounter;
|
WordLen = (int)S7WordLength.Counter;
|
||||||
if (Area == S7Consts.S7AreaTM)
|
if (Area == (int)S7Area.TM)
|
||||||
WordLen = S7Consts.S7WLTimer;
|
WordLen = (int)S7WordLength.Timer;
|
||||||
|
|
||||||
// Calc Word size
|
// Calc Word size
|
||||||
WordSize = WordLen.DataSizeByte();
|
WordSize = WordLen.DataSizeByte();
|
||||||
if (WordSize == 0)
|
if (WordSize == 0)
|
||||||
return S7Consts.errCliInvalidWordLen;
|
return S7Consts.errCliInvalidWordLen;
|
||||||
|
|
||||||
if (WordLen == S7Consts.S7WLBit)
|
if (WordLen == (int)S7WordLength.Bit)
|
||||||
Amount = 1; // Only 1 bit can be transferred at time
|
Amount = 1; // Only 1 bit can be transferred at time
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((WordLen != S7Consts.S7WLCounter) && (WordLen != S7Consts.S7WLTimer))
|
if ((WordLen != (int)S7WordLength.Counter) && (WordLen != (int)S7WordLength.Timer))
|
||||||
{
|
{
|
||||||
Amount = Amount * WordSize;
|
Amount = Amount * WordSize;
|
||||||
WordSize = 1;
|
WordSize = 1;
|
||||||
WordLen = S7Consts.S7WLByte;
|
WordLen = (int)S7WordLength.Byte;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -885,11 +884,11 @@ namespace Sharp7
|
|||||||
// Set DB Number
|
// Set DB Number
|
||||||
PDU[27] = (byte)Area;
|
PDU[27] = (byte)Area;
|
||||||
// Set Area
|
// Set Area
|
||||||
if (Area == S7Consts.S7AreaDB)
|
if (Area == (int)S7Area.DB)
|
||||||
PDU.SetWordAt(25, (ushort)DBNumber);
|
PDU.SetWordAt(25, (ushort)DBNumber);
|
||||||
|
|
||||||
// Adjusts Start and word length
|
// Adjusts Start and word length
|
||||||
if ((WordLen == S7Consts.S7WLBit) || (WordLen == S7Consts.S7WLCounter) || (WordLen == S7Consts.S7WLTimer))
|
if ((WordLen == (int)S7WordLength.Bit) || (WordLen == (int)S7WordLength.Counter) || (WordLen == (int)S7WordLength.Timer))
|
||||||
{
|
{
|
||||||
Address = Start;
|
Address = Start;
|
||||||
PDU[22] = (byte)WordLen;
|
PDU[22] = (byte)WordLen;
|
||||||
@@ -973,25 +972,25 @@ namespace Sharp7
|
|||||||
Time_ms = 0;
|
Time_ms = 0;
|
||||||
int Elapsed = Environment.TickCount;
|
int Elapsed = Environment.TickCount;
|
||||||
// Some adjustment
|
// Some adjustment
|
||||||
if (Area == S7Consts.S7AreaCT)
|
if (Area == (int)S7Area.CT)
|
||||||
WordLen = S7Consts.S7WLCounter;
|
WordLen = (int)S7WordLength.Counter;
|
||||||
if (Area == S7Consts.S7AreaTM)
|
if (Area == (int)S7Area.TM)
|
||||||
WordLen = S7Consts.S7WLTimer;
|
WordLen = (int)S7WordLength.Timer;
|
||||||
|
|
||||||
// Calc Word size
|
// Calc Word size
|
||||||
WordSize = WordLen.DataSizeByte();
|
WordSize = WordLen.DataSizeByte();
|
||||||
if (WordSize == 0)
|
if (WordSize == 0)
|
||||||
return S7Consts.errCliInvalidWordLen;
|
return S7Consts.errCliInvalidWordLen;
|
||||||
|
|
||||||
if (WordLen == S7Consts.S7WLBit) // Only 1 bit can be transferred at time
|
if (WordLen == (int)S7WordLength.Bit) // Only 1 bit can be transferred at time
|
||||||
Amount = 1;
|
Amount = 1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((WordLen != S7Consts.S7WLCounter) && (WordLen != S7Consts.S7WLTimer))
|
if ((WordLen != (int)S7WordLength.Counter) && (WordLen != (int)S7WordLength.Timer))
|
||||||
{
|
{
|
||||||
Amount = Amount * WordSize;
|
Amount = Amount * WordSize;
|
||||||
WordSize = 1;
|
WordSize = 1;
|
||||||
WordLen = S7Consts.S7WLByte;
|
WordLen = (int)S7WordLength.Byte;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1018,12 +1017,12 @@ namespace Sharp7
|
|||||||
PDU[17] = (byte)0x05;
|
PDU[17] = (byte)0x05;
|
||||||
// Set DB Number
|
// Set DB Number
|
||||||
PDU[27] = (byte)Area;
|
PDU[27] = (byte)Area;
|
||||||
if (Area == S7Consts.S7AreaDB)
|
if (Area == (int)S7Area.DB)
|
||||||
PDU.SetWordAt(25, (ushort)DBNumber);
|
PDU.SetWordAt(25, (ushort)DBNumber);
|
||||||
|
|
||||||
|
|
||||||
// Adjusts Start and word length
|
// Adjusts Start and word length
|
||||||
if ((WordLen == S7Consts.S7WLBit) || (WordLen == S7Consts.S7WLCounter) || (WordLen == S7Consts.S7WLTimer))
|
if ((WordLen == (int)S7WordLength.Bit) || (WordLen == (int)S7WordLength.Counter) || (WordLen == (int)S7WordLength.Timer))
|
||||||
{
|
{
|
||||||
Address = Start;
|
Address = Start;
|
||||||
Length = DataSize;
|
Length = DataSize;
|
||||||
@@ -1047,11 +1046,11 @@ namespace Sharp7
|
|||||||
// Transport Size
|
// Transport Size
|
||||||
switch (WordLen)
|
switch (WordLen)
|
||||||
{
|
{
|
||||||
case S7Consts.S7WLBit:
|
case (int)S7WordLength.Bit:
|
||||||
PDU[32] = TS_ResBit;
|
PDU[32] = TS_ResBit;
|
||||||
break;
|
break;
|
||||||
case S7Consts.S7WLCounter:
|
case (int)S7WordLength.Counter:
|
||||||
case S7Consts.S7WLTimer:
|
case (int)S7WordLength.Timer:
|
||||||
PDU[32] = TS_ResOctet;
|
PDU[32] = TS_ResOctet;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -1122,7 +1121,7 @@ namespace Sharp7
|
|||||||
Array.Copy(S7_MRD_ITEM, S7Item, S7Item.Length);
|
Array.Copy(S7_MRD_ITEM, S7Item, S7Item.Length);
|
||||||
S7Item[3] = (byte)Items[c].WordLen;
|
S7Item[3] = (byte)Items[c].WordLen;
|
||||||
S7Item.SetWordAt(4, (ushort)Items[c].Amount);
|
S7Item.SetWordAt(4, (ushort)Items[c].Amount);
|
||||||
if (Items[c].Area == S7Consts.S7AreaDB)
|
if (Items[c].Area == (int)S7Area.DB)
|
||||||
S7Item.SetWordAt(6, (ushort)Items[c].DBNumber);
|
S7Item.SetWordAt(6, (ushort)Items[c].DBNumber);
|
||||||
S7Item[8] = (byte)Items[c].Area;
|
S7Item[8] = (byte)Items[c].Area;
|
||||||
|
|
||||||
@@ -1241,18 +1240,18 @@ namespace Sharp7
|
|||||||
S7DataItem[0] = 0x00;
|
S7DataItem[0] = 0x00;
|
||||||
switch (Items[c].WordLen)
|
switch (Items[c].WordLen)
|
||||||
{
|
{
|
||||||
case S7Consts.S7WLBit:
|
case (int)S7WordLength.Bit:
|
||||||
S7DataItem[1] = TS_ResBit;
|
S7DataItem[1] = TS_ResBit;
|
||||||
break;
|
break;
|
||||||
case S7Consts.S7WLCounter:
|
case (int)S7WordLength.Counter:
|
||||||
case S7Consts.S7WLTimer:
|
case (int)S7WordLength.Timer:
|
||||||
S7DataItem[1] = TS_ResOctet;
|
S7DataItem[1] = TS_ResOctet;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
S7DataItem[1] = TS_ResByte; // byte/word/dword etc.
|
S7DataItem[1] = TS_ResByte; // byte/word/dword etc.
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
if ((Items[c].WordLen==S7Consts.S7WLTimer) || (Items[c].WordLen == S7Consts.S7WLCounter))
|
if ((Items[c].WordLen==(int)S7WordLength.Timer) || (Items[c].WordLen == (int)S7WordLength.Counter))
|
||||||
ItemDataSize = Items[c].Amount * 2;
|
ItemDataSize = Items[c].Amount * 2;
|
||||||
else
|
else
|
||||||
ItemDataSize = Items[c].Amount;
|
ItemDataSize = Items[c].Amount;
|
||||||
|
|||||||
Reference in New Issue
Block a user