HamBook – Diff between revs 27 and 38
?pathlinks?
Rev 27 | Rev 38 | |||
---|---|---|---|---|
Line 361... | Line 361... | |||
361 | { |
361 | { |
|
362 | _semaphoreSlim.Release(); |
362 | _semaphoreSlim.Release(); |
|
363 | } |
363 | } |
|
364 | } |
364 | } |
|
Line -... | Line 365... | |||
- | 365 | |
||
- | 366 | public async Task CatWriteAsync(string command, object[] param, CancellationToken cancellationToken) |
||
- | 367 | { |
||
- | 368 | await _semaphoreSlim.WaitAsync(cancellationToken); |
||
- | 369 | |
||
- | 370 | try |
||
- | 371 | { |
||
- | 372 | if (!_serialPort.IsOpen) |
||
- | 373 | { |
||
- | 374 | _serialPort.Open(); |
||
- | 375 | } |
||
- | 376 | |
||
- | 377 | try |
||
- | 378 | { |
||
- | 379 | if (_catCommands.TryGetValue(command, out var catCommand)) |
||
- | 380 | { |
||
- | 381 | var methodInfo = catCommand.GetType().GetMethod("WriteAsync"); |
||
- | 382 | if (methodInfo != null) |
||
- | 383 | { |
||
- | 384 | if (methodInfo.GetCustomAttribute<AsyncStateMachineAttribute>() != null) |
||
- | 385 | { |
||
- | 386 | var parameters = new List<object>(); |
||
- | 387 | parameters.AddRange(param); |
||
- | 388 | parameters.Add(cancellationToken); |
||
- | 389 | |
||
- | 390 | await (Task)methodInfo.Invoke(catCommand, parameters.ToArray()); |
||
- | 391 | |
||
- | 392 | return; |
||
- | 393 | } |
||
- | 394 | } |
||
- | 395 | |
||
- | 396 | throw new CatCommandException(Resources.CAT_command_method_not_found, command, "WriteAsync"); |
||
- | 397 | } |
||
- | 398 | |
||
- | 399 | throw new CatCommandException(Resources.CAT_command_not_found, command); |
||
- | 400 | } |
||
- | 401 | finally |
||
- | 402 | { |
||
- | 403 | if (_serialPort.IsOpen) |
||
- | 404 | { |
||
- | 405 | await _serialPort.FlushAsync(cancellationToken); |
||
- | 406 | } |
||
- | 407 | } |
||
- | 408 | } |
||
- | 409 | finally |
||
- | 410 | { |
||
- | 411 | _semaphoreSlim.Release(); |
||
- | 412 | } |
||
- | 413 | } |
||
365 | |
414 | |
|
366 | public T CatRead<T>(string command, object[] param) |
415 | public T CatRead<T>(string command, object[] param) |
|
367 | { |
416 | { |
|
Line 368... | Line 417... | |||
368 | _semaphoreSlim.Wait(); |
417 | _semaphoreSlim.Wait(); |