private void GetDynamicAttribut() { SoemInterrop.GetDeviceInfo(Id, DeviceInfoParam.State, sExchange); State = (SlaveState)(Convert.ToByte(sExchange.ToString()) & 0x1F); SoemInterrop.GetDeviceInfo(Id, (DeviceInfoParam)(-1), sExchange); }
//////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////// static void DeviceInfo() { StringBuilder sb = new StringBuilder(200); // Buffer large enough to get back slave parameters SoemInterrop.GetDeviceInfo(1, DeviceInfoParam.State, sb); SlaveState s = (SlaveState)Convert.ToUInt16(sb.ToString()); Console.WriteLine("State : " + s.ToString()); }
private void GetConstAttribut() { SoemInterrop.GetDeviceInfo(Id, DeviceInfoParam.Name, sExchange); Name = sExchange.ToString(); SoemInterrop.GetDeviceInfo(Id, DeviceInfoParam.OutputSize, sExchange); OutputSize = Convert.ToUInt16(sExchange.ToString()); if (OutputSize > 0) { OutputData = new byte[(OutputSize / 8) + (OutputSize % 8)]; } SoemInterrop.GetDeviceInfo(Id, DeviceInfoParam.InputSize, sExchange); InputSize = Convert.ToUInt16(sExchange.ToString()); if (InputSize > 0) { InputData = new byte[(InputSize / 8) + (InputSize % 8)]; } SoemInterrop.GetDeviceInfo(Id, DeviceInfoParam.Delay, sExchange); Delay = Convert.ToUInt16(sExchange.ToString()); SoemInterrop.GetDeviceInfo(Id, DeviceInfoParam.Config_Address, sExchange); Config_Address = Convert.ToUInt16(sExchange.ToString()); SoemInterrop.GetDeviceInfo(Id, DeviceInfoParam.ManufacturerId, sExchange); _ManufacturerId = Convert.ToUInt32(sExchange.ToString()); ManufacturerId = "0x" + _ManufacturerId.ToString("X8"); SoemInterrop.GetDeviceInfo(Id, DeviceInfoParam.TypeId, sExchange); _TypeId = Convert.ToUInt32(sExchange.ToString()); TypeId = "0x" + _TypeId.ToString("X8"); SoemInterrop.GetDeviceInfo(Id, DeviceInfoParam.Rev, sExchange); Revision = Convert.ToUInt32(sExchange.ToString()); // Maibox Protocol SoemInterrop.GetDeviceInfo(Id, DeviceInfoParam.MailboxProtocol, sExchange); ushort mbx = Convert.ToUInt16(sExchange.ToString()); StringBuilder sb = new StringBuilder(); foreach (MailBoxProto proto in Enum.GetValues(typeof(MailBoxProto))) { if ((mbx & (ushort)proto) != 0) { sb.Append(proto.ToString() + " "); } } MailboxProtocol = sb.ToString(); }
//////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////// static void Main(string[] args) { if (Open() == true) { StringBuilder sb = new StringBuilder(200); // Buffer to get back slave parameters // Assume two slave devices for (uint i = 1; i < 3; i++) { // We can get some information ... for nothing, just to show SoemInterrop.GetDeviceInfo(i, DeviceInfoParam.OutputSize, sb); SoemInterrop.GetDeviceInfo(i, DeviceInfoParam.InputSize, sb); SoemInterrop.GetDeviceInfo(i, DeviceInfoParam.Config_Address, sb); Console.WriteLine("Slave @ : ", sb.ToString()); } // Assume two devices, copy two bytes from the input into the other output // echange buffers with the SOEM stack byte[] bin1 = new byte[50]; // must be equal or more than InputSize in the corresponding slave byte[] bout2 = new byte[50]; // must be strikcly equal to OutputSize in the corresponding slave for (; ;) { // Get Input from the first slave SoemInterrop.GetInput(1, bin1); // Some action ! bout2[0] = bin1[0]; bout2[1] = bin1[1]; // Set Output in the second slave SoemInterrop.SetOutput(2, bout2); // Quite tired with this work Thread.Sleep(200); } } }