Skip to content

Commit

Permalink
Fix SetBit
Browse files Browse the repository at this point in the history
  • Loading branch information
franklupo committed Feb 24, 2019
1 parent e85c59b commit c6fc0b4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>0.1.4</Version>
<Version>0.1.5</Version>
<Company>Corsinvest Srl</Company>
<Authors>Daniele Corsini</Authors>
<Copyright>Corsinvest Srl</Copyright>
Expand Down
56 changes: 28 additions & 28 deletions src/Corsinvest.AllenBradley.PLC.Api/NativeMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,90 +11,90 @@ internal static class NativeMethod
internal static extern int plc_tag_create([MarshalAs(UnmanagedType.LPStr)] string lpString, int timeout);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_destroy", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_destroy(int tag);
internal static extern int plc_tag_destroy(int tagId);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_abort", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_abort(int tag);
internal static extern int plc_tag_abort(int tagId);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_status", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_status(int tag);
internal static extern int plc_tag_status(int tagId);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_get_size", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_get_size(int tag);
internal static extern int plc_tag_get_size(int tagId);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_decode_error", CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr plc_tag_decode_error(int error);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_read", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_read(int tag, int timeout);
internal static extern int plc_tag_read(int tagId, int timeout);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_write", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_write(int tag, int timeout);
internal static extern int plc_tag_write(int tagId, int timeout);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_get_uint16", CallingConvention = CallingConvention.Cdecl)]
internal static extern ushort plc_tag_get_uint16(int tag, int offset);
internal static extern ushort plc_tag_get_uint16(int tagId, int offset);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_get_int16", CallingConvention = CallingConvention.Cdecl)]
internal static extern short plc_tag_get_int16(int tag, int offset);
internal static extern short plc_tag_get_int16(int tagId, int offset);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_set_uint16", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_set_uint16(int tag, int offset, ushort val);
internal static extern int plc_tag_set_uint16(int tagId, int offset, ushort val);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_set_int16", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_set_int16(int tag, int offset, short val);
internal static extern int plc_tag_set_int16(int tagId, int offset, short val);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_get_uint8", CallingConvention = CallingConvention.Cdecl)]
internal static extern byte plc_tag_get_uint8(int tag, int offset);
internal static extern byte plc_tag_get_uint8(int tagId, int offset);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_get_int8", CallingConvention = CallingConvention.Cdecl)]
internal static extern sbyte plc_tag_get_int8(int tag, int offset);
internal static extern sbyte plc_tag_get_int8(int tagId, int offset);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_set_uint8", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_set_uint8(int tag, int offset, byte val);
internal static extern int plc_tag_set_uint8(int tagId, int offset, byte val);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_set_int8", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_set_int8(int tag, int offset, sbyte val);
internal static extern int plc_tag_set_int8(int tagId, int offset, sbyte val);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_get_float32", CallingConvention = CallingConvention.Cdecl)]
internal static extern float plc_tag_get_float32(int tag, int offset);
internal static extern float plc_tag_get_float32(int tagId, int offset);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_set_float32", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_set_float32(int tag, int offset, float val);
internal static extern int plc_tag_set_float32(int tagId, int offset, float val);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_get_float64", CallingConvention = CallingConvention.Cdecl)]
internal static extern double plc_tag_get_float64(int tag, int offset);
internal static extern double plc_tag_get_float64(int tagId, int offset);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_set_float64", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_set_float64(int tag, int offset, double val);
internal static extern int plc_tag_set_float64(int tagId, int offset, double val);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_get_uint32", CallingConvention = CallingConvention.Cdecl)]
internal static extern uint plc_tag_get_uint32(int tag, int offset);
internal static extern uint plc_tag_get_uint32(int tagId, int offset);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_get_int32", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_get_int32(int tag, int offset);
internal static extern int plc_tag_get_int32(int tagId, int offset);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_set_uint32", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_set_uint32(int tag, int offset, uint val);
internal static extern int plc_tag_set_uint32(int tagId, int offset, uint val);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_set_int32", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_set_int32(int tag, int offset, int val);
internal static extern int plc_tag_set_int32(int tagId, int offset, int val);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_get_uint64", CallingConvention = CallingConvention.Cdecl)]
internal static extern ulong plc_tag_get_uint64(int tag, int offset);
internal static extern ulong plc_tag_get_uint64(int tagId, int offset);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_get_int64", CallingConvention = CallingConvention.Cdecl)]
internal static extern long plc_tag_get_int64(int tag, int offset);
internal static extern long plc_tag_get_int64(int tagId, int offset);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_set_uint64", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_set_uint64(int tag, int offset, ulong val);
internal static extern int plc_tag_set_uint64(int tagId, int offset, ulong val);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_set_int64", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_set_int64(int tag, int offset, long val);
internal static extern int plc_tag_set_int64(int tagId, int offset, long val);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_lock", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_lock(int tag);
internal static extern int plc_tag_lock(int tagId);

[DllImport(DLL_NAME, EntryPoint = "plc_tag_unlock", CallingConvention = CallingConvention.Cdecl)]
internal static extern int plc_tag_unlock(int tag);
internal static extern int plc_tag_unlock(int tagId);
}
}
11 changes: 6 additions & 5 deletions src/Corsinvest.AllenBradley.PLC.Api/TagValueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,13 @@ public void SetString(string value, int offset = 0)
public void SetBit(int index, bool value)
{
if (_tag.Size * 8 <= index) { throw new IndexOutOfRangeException("Index out of bound!"); }
var index2 = (ulong)Math.Pow(2, index);

var currValue = GetNumvericValue();
var uCurrValue = Convert.ToUInt64(currValue);
var newValue = value ? uCurrValue | index2 : uCurrValue ^ index2;
Set(Convert.ChangeType(newValue, currValue.GetType()));
var bits = GetBits();
bits.Set(index, value);
var data = new int[1];
bits.CopyTo(data, 0);

Set(data[0]);
}

/// <summary>
Expand Down

0 comments on commit c6fc0b4

Please sign in to comment.