public void RemoteATCommand(ushort address, string command) { lock (uartLocker) { if (uart == null || Estado == Estados.PUERTO_CERRADO) { return; } // to do: el 0x00 al final de los strings. var data = Encoding.ASCII.GetBytes(command); var pdu = new XBeePDU(address, 0x17, data); tr_layer.Create(pdu, active_tx_timeout); var buf = pdu.ToByteArray(); try { STrace.Debug(GetType().FullName, "REMOTE AT"); Stack._writed_bytes += buf.GetLength(0); Write(buf); return; } catch (UnauthorizedAccessException e) { STrace.Exception(GetType().FullName, e); Estado = Estados.PUERTO_CERRADO; Stack._write_unautorized_access_exceptions++; return; } catch (IOException e) { STrace.Exception(GetType().FullName, e); Estado = Estados.PUERTO_CERRADO; Stack._write_io_exceptions++; return; } catch (InvalidOperationException e) { STrace.Exception(GetType().FullName, e); Estado = Estados.PUERTO_CERRADO; Stack._invalid_operation_exception++; return; } catch (TimeoutException e) { STrace.Exception(GetType().FullName, e); Estado = Estados.PUERTO_CERRADO; Stack._timeout_exceptions++; return; } } }
private void ATCommand(byte[] data) { lock (uartLocker) { if (uart == null || Estado == Estados.PUERTO_CERRADO) { return; } // to do: el 0x00 al final de los strings. var pdu = new XBeePDU(0, 0x08, data); tr_layer.Create(pdu, active_tx_timeout); var buf = pdu.ToByteArray(); try { STrace.Debug(GetType().FullName, "Enviando AT "); Stack._writed_bytes += buf.GetLength(0); Write(buf); return; } catch (UnauthorizedAccessException) { STrace.Debug(GetType().FullName, "Exception: UnauthorizedAccessException."); Estado = Estados.PUERTO_CERRADO; Stack._write_unautorized_access_exceptions++; return; } catch (IOException) { STrace.Debug(GetType().FullName, "Exception: IOException."); Estado = Estados.PUERTO_CERRADO; Stack._write_io_exceptions++; return; } catch (InvalidOperationException) { STrace.Debug(GetType().FullName, "Exception: InvalidOperationException."); Estado = Estados.PUERTO_CERRADO; Stack._invalid_operation_exception++; return; } catch (TimeoutException) { STrace.Debug(GetType().FullName, "Exception: TimeoutException."); Estado = Estados.PUERTO_CERRADO; Stack._timeout_exceptions++; return; } } }
public bool Send(byte[] data, ushort address) { lock (uartLocker) { try { if (uart == null || Estado == Estados.PUERTO_CERRADO) { return(false); } var pdu = new XBeePDU(address, 0x01, data); // tr_layer.Create(pdu, active_tx_timeout); var buf = pdu.ToByteArray(); STrace.Debug(GetType().FullName, String.Format("TX Request 16 bits, Enviando {0} bytes. (sin cabeceras)", buf.GetLength(0))); Stack._writed_bytes += buf.GetLength(0); Write(buf); //Write(buf); return(true); } catch (UnauthorizedAccessException e) { STrace.Exception(GetType().FullName, e); Estado = Estados.PUERTO_CERRADO; Stack._write_unautorized_access_exceptions++; return(false); } catch (IOException e) { STrace.Exception(GetType().FullName, e); Estado = Estados.PUERTO_CERRADO; Stack._write_io_exceptions++; return(false); } catch (Exception e) { STrace.Exception(GetType().FullName, e); Estado = Estados.PUERTO_CERRADO; Stack._write_unknow_exceptions++; return(false); } } }