public void _0004_ExpectPacketRate_GetSet() { var unconnected = new UnconnectedSalveDevice(Adapter); var connected = new ConnectedSalveDevice(Adapter, 0x00); ushort expectPacketRate = 0; byte[] bytes = null; try { unconnected.AllocateExplicitConnection(0x02); bytes = connected.GetAttribute(0x02, 5, 1, 9); expectPacketRate = BitConverter.ToUInt16(bytes, 0); Assert.AreEqual(2500, expectPacketRate); connected.SetAttribute(0x02, 5, 1, 9, BitConverter.GetBytes((ushort)0x82)); bytes = connected.GetAttribute(0x02, 5, 1, 9); expectPacketRate = BitConverter.ToUInt16(bytes, 0); Assert.AreEqual(0x82, expectPacketRate); } catch (Exception ex) { throw ex; } finally { unconnected.ReleaseExplicitConnection(0x02); } }
public void _0001_Allacate_Release() { var unconnected = new UnconnectedSalveDevice(Adapter); unconnected.AllocateExplicitConnection(0x02); unconnected.ReleaseExplicitConnection(0x02); }
public void _0003_Connected_GetProductName() { var unconnected = new UnconnectedSalveDevice(Adapter); var connected = new ConnectedSalveDevice(Adapter, 0x00); string porductName = string.Empty; try { unconnected.AllocateExplicitConnection(0x02); byte[] bytes = connected.GetAttribute(0x02, 1, 1, 7); porductName = Encoding.UTF8.GetString(bytes, 1, bytes[0]); } catch (Exception ex) { throw ex; } finally { unconnected.ReleaseExplicitConnection(0x02); } Assert.AreEqual("GRT1-DRT", porductName); }
public void _0002_Connected_GetProductCode() { var unconnected = new UnconnectedSalveDevice(Adapter); var connected = new ConnectedSalveDevice(Adapter, 0x00); unconnected.AllocateExplicitConnection(0x02); ushort porductCode = 0; try { porductCode = BitConverter.ToUInt16(connected.GetAttribute(0x02, 1, 1, 3), 0); } catch (Exception ex) { throw ex; } finally { unconnected.ReleaseExplicitConnection(0x02); } Assert.AreEqual(1388, porductCode); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { Stopwatch watch = new Stopwatch(); watch.Start(); Adapter.Write(new CanMessage[] { new CanMessage(0x0000, new byte[0]) }); Thread.Sleep(2000); for (int slaveMacId = 0; slaveMacId < 64; slaveMacId++) { try { if (BackgroundWorker.CancellationPending) { e.Cancel = true; break; } long timestamp = DateTime.Now.Ticks; bool isTimeout = false; CanMessage[] rxMsgBuffer = new CanMessage[1]; Adapter.Write(new CanMessage[] { new CanMessage(DeviceNetAddressing.GetCheckMacId(slaveMacId), new byte[0]) }); do { if (Adapter.Attributes.PendingRxMessages >= 1) { Adapter.Read(rxMsgBuffer, 0, 1); break; } isTimeout = DateTime.Now.Ticks - timestamp > 10 * 10000; } while (!isTimeout); CanMessage responseBuffer = rxMsgBuffer[0]; BackgroundWorker.ReportProgress((int)((slaveMacId / 63.0) * 100.0), "STATUS: " + slaveMacId.ToString() + "."); if (!isTimeout) { if (DeviceNetAddressing.IsMacIdCheckCanId(responseBuffer.ArbitrationId)) { ushort vendorId = BitConverter.ToUInt16(responseBuffer.Data, 1); uint serialNumber = BitConverter.ToUInt32(responseBuffer.Data, 2); var unconnected = new UnconnectedSalveDevice(Adapter); var connected = new ConnectedSalveDevice(Adapter, 0); unconnected.AllocateExplicitConnection(slaveMacId); ushort productCode = 0; try { productCode = BitConverter.ToUInt16(connected.GetAttribute(slaveMacId, 1, 1, 3), 0); Devices.Add(Devices.CreateDevice(slaveMacId, vendorId, productCode, serialNumber)); } catch (Exception ex) { throw ex; } finally { unconnected.ReleaseExplicitConnection(slaveMacId); } } } } catch (Exception ex) { e.Result = ex; } } watch.Stop(); if (!BackgroundWorker.CancellationPending) { BackgroundWorker.ReportProgress(0, "COMPLETE Elapsed:" + (watch.ElapsedMilliseconds / 1000.0).ToString() + "s"); //e.Result = data; } else { BackgroundWorker.ReportProgress(0, "ABORTED Elapsed:" + (watch.ElapsedMilliseconds / 1000.0).ToString() + "s"); } }