RMCLink.Interop .NET Assembly RMCLink.ReadBitField Method |
Reads a bit field (range of bits) from an integer (L) register in the RMC, and converts the binary value of the bits to a long integer. ReadBitField is typically used to read the value of a multiple-bit parameter in the RMC70, RMC150, or RMC200.
Visual Basic (Declaration) |
Public Function ReadBitField ( _ file As Integer, _ element As Integer, _ fieldStart As Integer, _ fieldLen As Integer _ ) As Integer |
Visual Basic (Usage) |
Dim instance As RMCLink Dim file As Integer Dim element As Integer Dim fieldStart As Integer Dim fieldLen As Integer Dim returnValue As Integer
returnValue = instance.ReadBitField(file, element, fieldStart, fieldLen) |
C# |
public int ReadBitField ( int file, int element, int fieldStart, int fieldLen ) |
Visual C++/CLI |
public: int ReadBitField ( int file, int element, int fieldStart, int fieldLen ) |
file
File number of the register with the bit to be read. See the RMCLink Register Reference for details.
element
Element number of the register with the bit to be read. See the RMCLink Register Reference for details.
fieldStart
Number of the least significant bit (0-31) of the register's bit field. Bits are numbered from least to most significant.
fieldLen
Total number of bits in the bit field (1-32).
The value of the bit field is returned.
This method is synchronous, which means that it will not return until the read is completed, which may take several seconds. If this method is called on the main thread, then the application will likely be unresponsive until this method completes. For applications where this is not acceptable, this and other synchronous methods should be called from a worker thread, and may use the CancelRequest method to cancel an in progress request.
Exception Type |
Condition |
The bit field overruns a 32-bit integer. That is, fieldStart plus fieldLen must be less than or equal to 32.. |
|
One of the file, element, fieldStart, and fieldLen is out of range. Ensure that file and element are between 0 and 65535, fieldStart is between 0 and 31, and that fieldLen is between 1 and 32. |
|
This read was cancelled by a call on another thread to one of the Disconnect and CancelRequest methods. |
|
The link is not currently connected. The Connect method must be called before attempting to read from the controller. |
|
The read failed due to a communication failure. Check that the remote device is powered up, check the communication wiring, and check the communication configuration of both the local and remote devices. Check the Message property of the exception for a description of the communication failure. |
The following code example illustrates the use of the ReadBitField method.
Visual Basic |
Imports RMCLinkNET
Module Example
Sub Main()
' Create the object itself.
Dim rmc As RMCLink = RMCLink.CreateSerialLink(DeviceType.RMC70, "COM1")
' Connect to the controller.
rmc.Connect()
' Read and display Axis 0's 2-bit Target State field (L8:0/10-11).
Dim targetState As Integer = rmc.ReadBitField(FileNumber70.fn70StatusAxis0,0,10,2)
Console.WriteLine("Axis0 Target State = " & targetState)
' Disconnect from the controller.
rmc.Disconnect()
End Sub
End Module
|
C# |
using System;
using RMCLinkNET;
namespace Example
{
public class Program
{
static void Main()
{
// Create the object itself.
RMCLink rmc = RMCLink.CreateSerialLink(DeviceType.RMC70, "COM1");
// Connect to the controller.
rmc.Connect();
// Read and display Axis 0's 2-bit Target State field (L8:0/10-11).
int targetState = rmc.ReadBitField(FileNumber70.fn70StatusAxis0,0,10,2);
Console.WriteLine("Axis0 Target State = " + targetState);
// Disconnect from the controller.
rmc.Disconnect();
}
}
}
|
Visual C++/CLI |
using namespace System;
using namespace RMCLinkNET;
int main()
{
// Create the object itself.
RMCLink^ rmc = RMCLink::CreateSerialLink(DeviceType::RMC70, "COM1");
// Connect to the controller.
rmc->Connect();
// Read and display Axis 0's 2-bit Target State field (L8:0/10-11).
int targetState = rmc->ReadBitField(FileNumber70::fn70StatusAxis0,0,10,2);
Console::WriteLine("Axis0 Target State = " + targetState);
// Disconnect from the controller.
rmc->Disconnect();
return 0;
}
|
See Also
RMCLink.Interop .NET Assembly | RMCLinkNET Namespace | RMCLink Class
Copyright (c) 2024 Delta Computer Systems, Inc. dba Delta Motion