using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Matrox.MatroxImagingLibrary;
namespace McomCclinkSlave
{
class CclinkSlave
{
private MIL_ID _milIdCom = 0;
public CclinkSlave(MIL_ID milID)
{
_milIdCom = milID;
}
public bool IsSlaveStopped
{
get
{
bool state = false;
MIL.McomInquire(ComId: _milIdCom, InquireType: MIL.M_COM_GET_CONNECTION_STATE, UserVarPtr: ref state);
return !state;
}
}
public void WriteRegister(MIL_INT deviceNumber, ushort value)
{
MIL.McomWrite(ComId: _milIdCom, DataObjectEntryName: "RWr", Offset: deviceNumber, Size: 1, UserArrayPtr: BitConverter.GetBytes(value));
}
public ushort ReadRegister(MIL_INT deviceNumber)
{
byte[] result = { 0, 0 };
MIL.McomRead(ComId: _milIdCom, DataObjectEntryName: "RWw", Offset: deviceNumber, Size: 1, UserArrayPtr: result);
return BitConverter.ToUInt16(result, 0);
}
public void SetFlag(MIL_INT deviceNumber)
{
WriteFlag(deviceNumber, state: true);
}
public void ClearFlag(MIL_INT deviceNumber)
{
WriteFlag(deviceNumber, state: false);
}
public void WriteFlag(MIL_INT deviceNumber, bool state)
{
MIL.McomWrite(ComId: _milIdCom, DataObjectEntryName: "RX", Offset: deviceNumber, Size: 1, UserArrayPtr: BitConverter.GetBytes(state));
}
public bool ReadFlag(MIL_INT deviceNumber)
{
byte[] status = { 0 };
MIL.McomRead(ComId: _milIdCom, DataObjectEntryName: "RY", Offset: deviceNumber, Size: 1, UserArrayPtr: status);
return BitConverter.ToBoolean(status, 0);
}
}
}