Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. function serial_connection(body, username) {
  2.  
  3. require("./start_configuration/eltex_configuration_file")(body, username); // creating the configuration file
  4.  
  5. var SerialPort = require('serialport');
  6. var port = new SerialPort('COM' + body.serial_port_number, {
  7. baudRate: 115200,
  8. flowControl: false,
  9. dataBits: 8
  10. });
  11.  
  12. // Open errors will be emitted as an error event
  13. port.on('error', function (err) {
  14. console.log('Error: ', err.message);
  15. })
  16.  
  17. // Switches the port into "flowing mode"
  18. port.on('data', function (data) {
  19. console.log('Data1:', data.toString('utf-8'));
  20. });
  21.  
  22. /*
  23. // Дополнительный способ загрузки старотовых конфигураций в оборудование, набором команд
  24. var start_configuration =
  25. "exit\nexit\nexit\n" +
  26. "ip ssh server\n" +
  27. "interface vlan " + body.vlan_number + "\n" +
  28. "ip address " + body.ip_address + " " + body.net_mask + "\n" +
  29. "no ip address dhcp\n" +
  30. "exit\n" +
  31. "ip route 0.0.0.0 0.0.0.0 " + body.ip_default_gateway + "\n" +
  32. "exit\nexit\nexit\n";
  33. port.write(start_configuration, function (err) {
  34. if (err) {
  35. return console.log("Err: ", err.message);
  36. }
  37. else {
  38. port.close();
  39. }
  40. });
  41. */
  42. var ip_tftp_server = "172.16.0.215"; // address of tftp server
  43. // создание загрузка настроек
  44. port.write('exit\nen\ncopy tftp://' + ip_tftp_server + '/' + username + '/config' + ' running-config\n');
  45. }
  46.  
  47. module.exports = serial_connection;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement