/// <summary> /// Called whenever a timer ticks for a device search /// </summary> /// <param name="search">The device search</param> private void _searchTick(DeviceSearch search) { lock (_lock) { var node = _deviceSearches.Find(search); if (node != null) { search.Attempt++; if (search.Attempt >= DeviceSearchAttempts) { _deviceSearches.Remove(node); search.Callback.DeviceSearchTimedOut(); search.Dispose(); } else if (search.IsInstanceSearch) { _sendWhoIsForInstance(search.Instance); } else { _sendWhoIsForAddress(search.Address); } } } }
/// <summary> /// Initializes a new instance of the <see cref="AddDeviceSearchForm" /> class. /// </summary> public AddDeviceSearchForm() { InitializeComponent(); foreach (var driver in MainForm.CurrentSystem.Drivers) { cbxDriver.Items.Add(new ComboboxItem { Text = driver.Name, Value = driver.Type }); } DeviceSearchItem = new DeviceSearch(); }
/// <summary> /// Searches for a device (Sends a who-is request) /// </summary> /// <param name="address">The address of the device to search for</param> /// <param name="callback">The callback to invoke when the device is found</param> public void SearchForDevice(Address address, IDeviceSearchCallback callback) { lock (_lock) { var device = _devices.GetByAddress(address); if (device != null) { callback.DeviceFound(device); } else { DeviceSearch search = new DeviceSearch(this, address, callback); this._deviceSearches.AddLast(search); _sendWhoIsForAddress(address); } } }
/// <summary> /// Searches for a device (Sends a who-is request) /// </summary> /// <param name="instance">The instance of the device to search for</param> /// <param name="callback">The callback to invoke when the device is found</param> public void SearchForDevice(uint instance, IDeviceSearchCallback callback) { lock (_lock) { var device = _devices.Get(instance); if (device != null) { callback.DeviceFound(device); } else { DeviceSearch search = new DeviceSearch(this, instance, callback); this._deviceSearches.AddLast(search); _sendWhoIsForInstance(instance); } } }
internal void LoadDeviceView(string pluginTypeName, string deviceIds, string parameters) { Type typPluginType = Function.GetType(pluginTypeName); if (deviceIds != null && deviceIds.Length > 0) { DeviceSearch _Search = new DeviceSearch(base.Application); _Search.Filters.Add(new AC.Base.DeviceSearchs.IdFilter(deviceIds)); Device[] devices = _Search.Search(0).ToArray(); DevicePluginType _PluginType = base.Application.GetDevicePluginType(typPluginType, devices); if (parameters != null && parameters.Length > 1) { List <ParameterValue> lstParameterValues = new List <ParameterValue>(); string[] strParameters = parameters.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); for (int intIndex = 0; intIndex < strParameters.Length; intIndex += 2) { if (strParameters.Length >= intIndex + 2) { ParameterValue _ParameterValue = new ParameterValue(); _ParameterValue.Type = Function.GetType(strParameters[intIndex]); if (_ParameterValue.Type != null) { _ParameterValue.Value = strParameters[intIndex + 1]; lstParameterValues.Add(_ParameterValue); } } } this.Application.LoadView(_PluginType, devices, lstParameterValues.ToArray()); } else { this.Application.LoadView(_PluginType, devices); } } }
public IEnumerable <Device> GetDeviceList(DeviceSearch deviceSearch) { var deviceList = api.CallAsync <List <Device> >(GET, typeof(Device), new { search = deviceSearch }).Result; return(deviceList); }
/// <summary> /// This is a Geotab API example of downloading a device's logs. /// /// Steps: /// 1) Authenticate a user via login, password, database and server using the Geotab API object. /// 2) Search for a device by its serial number. /// 3) Get logs associated with the device for a given time period. /// /// A complete Geotab API object and method reference is available at the Geotab Developer page. /// </summary> static void Main(string[] args) { try { if (args.Length != 5) { Console.WriteLine(); Console.WriteLine("Command line parameters:"); Console.WriteLine("dotnet run <server> <database> <username> <password> <serialNumber>"); Console.WriteLine(); Console.WriteLine("Command line: dotnet run server database username password inputfile"); Console.WriteLine("server - The server name (Example: my.geotab.com)"); Console.WriteLine("database - The database name (Example: G560)"); Console.WriteLine("username - The Geotab user name"); Console.WriteLine("password - The Geotab password"); Console.WriteLine("serialNumber - Serial number of the device."); Console.WriteLine(); return; } // Process command line arguments string server = args[0]; string database = args[1]; string username = args[2]; string password = args[3]; string serialNumber = args[4]; // Create the Geotab API object used to make calls to the server // Note: server name should be the generic 'Federation' server as databases can be moved without notice. // For example; use "my.geotab.com" rather than "my3.geotab.com". var api = new API(username, password, null, database, server); try { // Authenticate user api.Authenticate(); Console.WriteLine("Successfully Authenticated"); } catch (InvalidUserException ex) { Console.WriteLine($"Invalid user: {ex}"); return; } catch (DbUnavailableException ex) { Console.WriteLine($"Database unavailable: {ex}"); return; } catch (Exception ex) { Console.WriteLine($"Failed to authenticate user: {ex}"); return; } // Get Device by serial number Device device = null; try { DeviceSearch deviceSearch = new DeviceSearch { SerialNumber = serialNumber }; IList <Device> devices = api.Call <IList <Device> >("Get", typeof(Device), new { search = deviceSearch }); if (devices.Count > 0) { Console.WriteLine("Device found"); device = devices[0]; } else { Console.WriteLine("Device not found"); return; } } catch (Exception ex) { Console.WriteLine($"Failed to get device: {ex}"); } // Get logs for the Device try { var toDate = DateTime.UtcNow; var fromDate = toDate.AddDays(-7); LogRecordSearch logRecordSearch = new LogRecordSearch { DeviceSearch = new DeviceSearch(device.Id), FromDate = fromDate, ToDate = toDate }; IList <LogRecord> logs = api.Call <IList <LogRecord> >("Get", typeof(LogRecord), new { search = logRecordSearch }); // Use a string builder for the results and limit the amount of data entered into the text box. StringBuilder stringBuilder = new StringBuilder(10000); if (logs.Count == 0) { stringBuilder.Append("No Logs Found"); } else { // We will display the Lat, Lon, and Date of each Log as a row. for (int i = 0; i < logs.Count; i++) { LogRecord logRecord = logs[i]; stringBuilder.Append("Lat: "); stringBuilder.Append(logRecord.Latitude); stringBuilder.Append(" Lon: "); stringBuilder.Append(logRecord.Longitude); stringBuilder.Append(" Date: "); stringBuilder.Append(logRecord.DateTime); stringBuilder.Append(Environment.NewLine); } } // Display results Console.WriteLine(stringBuilder); } catch (Exception ex) { Console.WriteLine($"Failed to get logs: {ex}"); } } catch (Exception ex) { // Show miscellaneous exceptions Console.WriteLine($"Unhandled exception: {ex}"); } finally { Console.WriteLine("Press any key to exit..."); Console.ReadKey(true); } }
/// <summary> /// 设备回调函数 /// </summary> /// <param name="deviceID">4位厂商编号+4位主设备编号+12位MAC地址数(或者唯一编号)共20位</param> /// <param name="cmd">命令字</param> /// <param name="json">设备上传的json数据</param> /// <param name="len">设备上传的json数据长度</param> /// <returns>无</returns> private bool mySmartDevice_CallBack(string deviceID, UInt16 cmd, string json, Int32 len) { bool bResult = true; UpdateMsg("接收数据:设备ID=" + deviceID + json); switch (cmd) { case SmartDeviceInterface.COM_HEARTBEAT_JS: { UpdateDeviceState(deviceID, 1); break; } case SmartDeviceInterface.COM_DEV_SEARCH_JS: { byte[] byteDefault = Encoding.Convert(Encoding.UTF8, Encoding.Default, UTF8Encoding.Default.GetBytes(json)); json = Encoding.Default.GetString(byteDefault); DeviceSearch ds = (DeviceSearch)JsonConvert.DeserializeObject <DeviceSearch>(json); GloablInfo.devMgr.AddDevice(ds.data[0]); UpdateDeviceTree(); break; } case SmartDeviceInterface.COM_UPLOAD_RECORD_JS: { byte[] byteDefault = Encoding.Convert(Encoding.UTF8, Encoding.Default, UTF8Encoding.Default.GetBytes(json)); json = Encoding.Default.GetString(byteDefault); RecordUploadSend rus = (RecordUploadSend)JsonConvert.DeserializeObject <RecordUploadSend>(json); ProcessRecord(rus.data[0]); break; } case SmartDeviceInterface.COM_UPLOAD_EVENT_JS: { byte[] byteDefault = Encoding.Convert(Encoding.UTF8, Encoding.Default, UTF8Encoding.Default.GetBytes(json)); json = Encoding.Default.GetString(byteDefault); EventReportSend ers = (EventReportSend)JsonConvert.DeserializeObject <EventReportSend>(json); ProcessEventRecord(ers.data[0]); break; } case SmartDeviceInterface.COM_UPLOAD_DEV_STATUS_JS: { byte[] byteDefault = Encoding.Convert(Encoding.UTF8, Encoding.Default, UTF8Encoding.Default.GetBytes(json)); json = Encoding.Default.GetString(byteDefault); ReportDeviceState rds = (ReportDeviceState)JsonConvert.DeserializeObject <ReportDeviceState>(json); foreach (DeviceState s in rds.state) { if (s.deviceType == 2) { switch (s.deviceStatus) { case 1: UpdateDeviceState(deviceID, 5); //开到位 break; case 2: UpdateDeviceState(deviceID, 4); //关到位 break; case 3: UpdateDeviceState(deviceID, 1); //运行中 break; } } if (s.deviceType == 0 || s.deviceType == 1) { if (s.deviceStatus == 0) { UpdateDeviceState(deviceID, 3); } else { UpdateDeviceState(deviceID, 1); } } } break; } } return(bResult); }