public static neodevice_t new_neodevice_t_array(int nelements) { global::System.IntPtr cPtr = icsneocsharpPINVOKE.new_neodevice_t_array(nelements); neodevice_t ret = (cPtr == global::System.IntPtr.Zero) ? null : new neodevice_t(cPtr, false); return(ret); }
void PrintDeviceEvents(neodevice_t device) { neoevent_t events = icsneocsharp.new_neoevent_t_array(99); int eventCount = 99; if (icsneocsharp.icsneo_getDeviceEvents(device, events, ref eventCount)) { if (eventCount == 1) { neoevent_t evt = icsneocsharp.neoevent_t_array_getitem(events, 0); System.Console.WriteLine("1 device event found!"); System.Console.WriteLine("Event 0x" + evt.eventNumber + ": " + evt.description); } else { System.Console.WriteLine(eventCount + " device events found!"); for (var i = 0; i < eventCount; ++i) { neoevent_t evt = icsneocsharp.neoevent_t_array_getitem(events, i); System.Console.WriteLine("Event 0x" + evt.eventNumber + ": " + evt.description); } } } else { System.Console.WriteLine("Failed to get API events!"); } icsneocsharp.delete_neoevent_t_array(events); }
public static void neodevice_t_array_setitem(neodevice_t ary, int index, neodevice_t value) { icsneocsharpPINVOKE.neodevice_t_array_setitem(neodevice_t.getCPtr(ary), index, neodevice_t.getCPtr(value)); if (icsneocsharpPINVOKE.SWIGPendingException.Pending) { throw icsneocsharpPINVOKE.SWIGPendingException.Retrieve(); } }
private uint ScanNewDevices() { neodevice_t newDevices = icsneocsharp.new_neodevice_t_array(99); int count = 10; icsneocsharp.icsneo_findAllDevices(newDevices, ref count); numDevices += (uint)count; for (int i = 0; i < numDevices; i++) { devices.Add(icsneocsharp.neodevice_t_array_getitem(newDevices, i)); } icsneocsharp.delete_neodevice_t_array(newDevices); return((uint)count); }
public static bool icsneo_setPollingMessageLimit(neodevice_t device, uint newLimit) { bool ret = icsneocsharpPINVOKE.icsneo_setPollingMessageLimit(neodevice_t.getCPtr(device), newLimit); return(ret); }
public static void delete_neodevice_t_array(neodevice_t ary) { icsneocsharpPINVOKE.delete_neodevice_t_array(neodevice_t.getCPtr(ary)); }
public static void icsneo_discardDeviceEvents(neodevice_t device) { icsneocsharpPINVOKE.icsneo_discardDeviceEvents(neodevice_t.getCPtr(device)); }
public static bool icsneo_getTimestampResolution(neodevice_t device, SWIGTYPE_p_unsigned_short resolution) { bool ret = icsneocsharpPINVOKE.icsneo_getTimestampResolution(neodevice_t.getCPtr(device), SWIGTYPE_p_unsigned_short.getCPtr(resolution)); return(ret); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(neodevice_t obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public static bool icsneo_settingsApplyDefaultsTemporary(neodevice_t device) { bool ret = icsneocsharpPINVOKE.icsneo_settingsApplyDefaultsTemporary(neodevice_t.getCPtr(device)); return(ret); }
public static bool icsneo_transmitMessages(neodevice_t device, neomessage_t messages, uint count) { bool ret = icsneocsharpPINVOKE.icsneo_transmitMessages(neodevice_t.getCPtr(device), neomessage_t.getCPtr(messages), count); return(ret); }
public static bool icsneo_isOnline(neodevice_t device) { bool ret = icsneocsharpPINVOKE.icsneo_isOnline(neodevice_t.getCPtr(device)); return(ret); }
public static bool icsneo_setFDBaudrate(neodevice_t device, ushort netid, long newBaudrate) { bool ret = icsneocsharpPINVOKE.icsneo_setFDBaudrate(neodevice_t.getCPtr(device), netid, newBaudrate); return(ret); }
public static bool icsneo_transmit(neodevice_t device, neomessage_t message) { bool ret = icsneocsharpPINVOKE.icsneo_transmit(neodevice_t.getCPtr(device), neomessage_t.getCPtr(message)); return(ret); }
public static long icsneo_getFDBaudrate(neodevice_t device, ushort netid) { long ret = icsneocsharpPINVOKE.icsneo_getFDBaudrate(neodevice_t.getCPtr(device), netid); return(ret); }
public static bool icsneo_settingsApplyStructureTemporary(neodevice_t device, SWIGTYPE_p_void structure, uint structureSize) { bool ret = icsneocsharpPINVOKE.icsneo_settingsApplyStructureTemporary(neodevice_t.getCPtr(device), SWIGTYPE_p_void.getCPtr(structure), structureSize); return(ret); }
public static int icsneo_settingsReadStructure(neodevice_t device, SWIGTYPE_p_void structure, uint structureSize) { int ret = icsneocsharpPINVOKE.icsneo_settingsReadStructure(neodevice_t.getCPtr(device), SWIGTYPE_p_void.getCPtr(structure), structureSize); return(ret); }
public static neodevice_t neodevice_t_array_getitem(neodevice_t ary, int index) { neodevice_t ret = new neodevice_t(icsneocsharpPINVOKE.neodevice_t_array_getitem(neodevice_t.getCPtr(ary), index), true); return(ret); }
public void Run() { neoversion_t version = icsneocsharp.icsneo_getVersion(); System.Console.WriteLine("ICS icsneocsharp.dll version " + version.major + "." + version.minor + "." + version.patch); System.Console.WriteLine(); while (true) { PrintMainMenu(); System.Console.WriteLine(); char input = GetCharInput(new List <char> { 'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'X', 'x' }); System.Console.WriteLine(); switch (input) { // List current devices case 'A': goto case 'a'; case 'a': PrintAllDevices(); System.Console.WriteLine(); break; // Scan for new devices case 'B': goto case 'b'; case 'b': { var numNewDevices = ScanNewDevices(); if (numNewDevices == 1) { System.Console.WriteLine("1 new device found!"); } else { System.Console.WriteLine(numNewDevices + " new devices found!"); } PrintAllDevices(); System.Console.WriteLine(); break; } // Open/close a device case 'C': goto case 'c'; case 'c': { // Select a device and get its description if (numDevices == 0) { System.Console.WriteLine("No devices found! Please scan for new devices.\n"); break; } selectedDevice = SelectDevice(); // Get the product description for the device System.Text.StringBuilder description = new System.Text.StringBuilder(icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION); int maxLength = icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION; icsneocsharp.icsneo_describeDevice(selectedDevice, description, ref maxLength); System.Console.WriteLine("Would you like to open or close " + description + "?"); System.Console.WriteLine("[1] Open\n[2] Close\n[3] Cancel\n"); char option = GetCharInput(new List <char> { '1', '2', '3' }); System.Console.WriteLine(); switch (option) { case '1': // Attempt to open the selected device if (icsneocsharp.icsneo_openDevice(selectedDevice)) { System.Console.WriteLine(description + " successfully opened!\n"); } else { System.Console.WriteLine(description + " failed to open!\n"); PrintLastError(); System.Console.WriteLine(); } break; case '2': // Attempt to close the device if (icsneocsharp.icsneo_closeDevice(selectedDevice)) { numDevices--; System.Console.WriteLine("Successfully closed " + description + "!\n"); devices.Remove(selectedDevice); selectedDevice = null; } else { System.Console.WriteLine("Failed to close " + description.ToString() + "!\n"); PrintLastError(); System.Console.WriteLine(); } break; default: System.Console.WriteLine("Canceling!\n"); break; } break; } // Go online/offline case 'D': goto case 'd'; case 'd': { // Select a device and get its description if (numDevices == 0) { System.Console.WriteLine("No devices found! Please scan for new devices.\n"); break; } selectedDevice = SelectDevice(); // Get the product description for the device System.Text.StringBuilder description = new System.Text.StringBuilder(icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION); int maxLength = icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION; icsneocsharp.icsneo_describeDevice(selectedDevice, description, ref maxLength); System.Console.WriteLine("Would you like to have " + description.ToString() + " go online or offline?"); System.Console.WriteLine("[1] Online\n[2] Offline\n[3] Cancel\n"); char option = GetCharInput(new List <char> { '1', '2', '3' }); System.Console.WriteLine(); switch (option) { case '1': // Attempt to go online if (icsneocsharp.icsneo_goOnline(selectedDevice)) { System.Console.WriteLine(description + " successfully went online!\n"); } else { System.Console.WriteLine(description + " failed to go online!\n"); PrintLastError(); System.Console.WriteLine(); } break; case '2': // Attempt to go offline if (icsneocsharp.icsneo_goOffline(selectedDevice)) { System.Console.WriteLine(description + " successfully went offline!\n"); } else { System.Console.WriteLine(description + " failed to go offline!\n"); PrintLastError(); System.Console.WriteLine(); } break; default: System.Console.WriteLine("Canceling!\n"); break; } break; } // Enable/disable message polling case 'E': goto case 'e'; case 'e': { // Select a device and get its description if (numDevices == 0) { System.Console.WriteLine("No devices found! Please scan for new devices.\n"); break; } selectedDevice = SelectDevice(); // Get the product description for the device System.Text.StringBuilder description = new System.Text.StringBuilder(icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION); int maxLength = icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION; icsneocsharp.icsneo_describeDevice(selectedDevice, description, ref maxLength); System.Console.WriteLine("Would you like to enable or disable message polling for " + description.ToString() + "?"); System.Console.WriteLine("[1] Enable\n[2] Disable\n[3] Cancel\n"); char option = GetCharInput(new List <char> { '1', '2', '3' }); System.Console.WriteLine(); switch (option) { case '1': // Attempt to enable message polling if (icsneocsharp.icsneo_enableMessagePolling(selectedDevice)) { System.Console.WriteLine("Successfully enabled message polling for " + description.ToString() + "!\n"); } else { System.Console.WriteLine("Failed to enable message polling for " + description.ToString() + "!\n"); PrintLastError(); System.Console.WriteLine(); } // Manually setting the polling message limit as done below is optional // It will default to 20k if not set // Attempt to set the polling message limit if (icsneocsharp.icsneo_setPollingMessageLimit(selectedDevice, msgLimit)) { System.Console.WriteLine("Successfully set message polling limit for " + description.ToString() + "!\n"); } else { System.Console.WriteLine("Failed to set polling message limit for " + description.ToString() + "!\n"); PrintLastError(); System.Console.WriteLine(); } break; case '2': // Attempt to disable message polling if (icsneocsharp.icsneo_disableMessagePolling(selectedDevice)) { System.Console.WriteLine("Successfully disabled message polling for " + description.ToString() + "!\n"); } else { System.Console.WriteLine("Failed to disable message polling for " + description.ToString() + "!\n"); PrintLastError(); System.Console.WriteLine(); } break; default: System.Console.WriteLine("Canceling!\n"); break; } } break; case 'F': goto case 'f'; case 'f': { // Select a device and get its description if (numDevices == 0) { System.Console.WriteLine("No devices found! Please scan for new devices.\n"); break; } selectedDevice = SelectDevice(); // Get the product description for the device System.Text.StringBuilder description = new System.Text.StringBuilder(icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION); int maxLength = icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION; icsneocsharp.icsneo_describeDevice(selectedDevice, description, ref maxLength); // Prepare the neomessage_t array and size for reading in the messages neomessage_t msgs = icsneocsharp.new_neomessage_t_array((int)msgLimit); int msgCount = (int)msgLimit; if (!icsneocsharp.icsneo_getMessages(selectedDevice, msgs, ref msgCount, 0)) { System.Console.WriteLine("Failed to get messages for " + description.ToString() + "!\n"); PrintLastError(); icsneocsharp.delete_neomessage_t_array(msgs); System.Console.WriteLine(); break; } if (msgCount == 1) { System.Console.WriteLine("1 message received from " + description.ToString() + "!"); } else { System.Console.WriteLine(msgCount + " messages received from " + description.ToString() + "!"); } // Print out the received messages for (int i = 0; i < msgCount; i++) { neomessage_t msg = icsneocsharp.neomessage_t_array_getitem(msgs, i); if (msg.type == icsneocsharp.ICSNEO_NETWORK_TYPE_CAN) { System.Console.Write("\t0x" + "{0:x}" + " [" + msg.length + "] ", icsneocsharp.neomessage_can_t_cast(msg).arbid); for (int j = 0; j < msg.length; j++) { System.Console.Write("{0:x} ", icsneocsharp.neomessage_can_t_cast(msg).data[j]); } System.Console.WriteLine("(" + msg.timestamp + ")"); } else { if (msg.netid != 0) { System.Console.WriteLine("\tMessage on netid " + msg.netid + " with length " + msg.length); } } } icsneocsharp.delete_neomessage_t_array(msgs); break; } // Send message case 'G': goto case 'g'; case 'g': { // Select a device and get its description if (numDevices == 0) { System.Console.WriteLine("No devices found! Please scan for new devices.\n"); break; } selectedDevice = SelectDevice(); // Get the product description for the device System.Text.StringBuilder description = new System.Text.StringBuilder(icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION); int maxLength = icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION; icsneocsharp.icsneo_describeDevice(selectedDevice, description, ref maxLength); // Start generating sample msg neomessage_can_t msg = new neomessage_can_t(); msg.arbid = 0x120; msg.length = 6; msg.netid = (ushort)icsneocsharp.ICSNEO_NETID_HSCAN; msg.data = new byte[6] { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; msg.status.canfdFDF = 0; msg.status.extendedFrame = 0; msg.status.canfdBRS = 0; // End generating sample msg // Attempt to transmit the sample msg if (icsneocsharp.icsneo_transmit(selectedDevice, icsneocsharp.from_can_neomessage_t_cast(msg))) { System.Console.WriteLine("Message transmit successful!"); } else { System.Console.WriteLine("Failed to transmit message to " + description.ToString() + "!\n"); PrintLastError(); System.Console.WriteLine(); } break; } // Get events case 'H': goto case 'h'; case 'h': PrintAPIEvents(); System.Console.WriteLine(); break; // Set HS CAN to 250k case 'I': goto case 'i'; case 'i': { // Select a device and get its description if (numDevices == 0) { System.Console.WriteLine("No devices found! Please scan for new devices.\n"); break; } selectedDevice = SelectDevice(); // Get the product description for the device System.Text.StringBuilder description = new System.Text.StringBuilder(icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION); int maxLength = icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION; icsneocsharp.icsneo_describeDevice(selectedDevice, description, ref maxLength); // Attempt to set baudrate and apply settings if (icsneocsharp.icsneo_setBaudrate(selectedDevice, (ushort)icsneocsharp.ICSNEO_NETID_HSCAN, 250000) && icsneocsharp.icsneo_settingsApply(selectedDevice)) { System.Console.WriteLine("Successfully set HS CAN baudrate for " + description.ToString() + "to 250k!\n"); } else { System.Console.WriteLine("Failed to set HS CAN for " + description.ToString() + " to 250k!\n"); PrintLastError(); System.Console.WriteLine(); } break; } // Set HS CAN to 500k case 'J': goto case 'j'; case 'j': { // Select a device and get its description if (numDevices == 0) { System.Console.WriteLine("No devices found! Please scan for new devices.\n"); break; } selectedDevice = SelectDevice(); // Get the product description for the device System.Text.StringBuilder description = new System.Text.StringBuilder(icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION); int maxLength = icsneocsharp.ICSNEO_DEVICETYPE_LONGEST_DESCRIPTION; icsneocsharp.icsneo_describeDevice(selectedDevice, description, ref maxLength); // Attempt to set baudrate and apply settings if (icsneocsharp.icsneo_setBaudrate(selectedDevice, (ushort)icsneocsharp.ICSNEO_NETID_HSCAN, 500000) && icsneocsharp.icsneo_settingsApply(selectedDevice)) { System.Console.WriteLine("Successfully set HS CAN baudrate for " + description.ToString() + "to 500k!\n"); } else { System.Console.WriteLine("Failed to set HS CAN for " + description.ToString() + " to 500k!\n"); PrintLastError(); System.Console.WriteLine(); } break; } case 'X': goto case 'x'; case 'x': System.Console.WriteLine("Exiting program"); return; default: System.Console.WriteLine("Unexpected input, exiting!"); return; } } }
public static void icsneo_findAllDevices(neodevice_t devices, ref int count) { icsneocsharpPINVOKE.icsneo_findAllDevices(neodevice_t.getCPtr(devices), ref count); }
public static uint icsneo_getPollingMessageLimit(neodevice_t device) { uint ret = icsneocsharpPINVOKE.icsneo_getPollingMessageLimit(neodevice_t.getCPtr(device)); return(ret); }
public static bool icsneo_isMessagePollingEnabled(neodevice_t device) { bool ret = icsneocsharpPINVOKE.icsneo_isMessagePollingEnabled(neodevice_t.getCPtr(device)); return(ret); }
public static bool icsneo_getDeviceEvents(neodevice_t device, neoevent_t events, ref int size) { bool ret = icsneocsharpPINVOKE.icsneo_getDeviceEvents(neodevice_t.getCPtr(device), neoevent_t.getCPtr(events), ref size); return(ret); }
public static void icsneo_setWriteBlocks(neodevice_t device, bool blocks) { icsneocsharpPINVOKE.icsneo_setWriteBlocks(neodevice_t.getCPtr(device), blocks); }
public static bool icsneo_settingsRefresh(neodevice_t device) { bool ret = icsneocsharpPINVOKE.icsneo_settingsRefresh(neodevice_t.getCPtr(device)); return(ret); }
public static bool icsneo_describeDevice(neodevice_t device, System.Text.StringBuilder str, ref int maxLength) { bool ret = icsneocsharpPINVOKE.icsneo_describeDevice(neodevice_t.getCPtr(device), str, ref maxLength); return(ret); }
public static bool icsneo_getMessages(neodevice_t device, neomessage_t messages, ref int items, ulong timeout) { bool ret = icsneocsharpPINVOKE.icsneo_getMessages(neodevice_t.getCPtr(device), neomessage_t.getCPtr(messages), ref items, timeout); return(ret); }