How to use serial method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

p5.serialport.js

Source:p5.serialport.js Github

copy

Full Screen

1/*! p5.serialport.js v0.0.1 2015-07-23 */2/**3 * @module p5.serialport4 * @submodule p5.serialport5 * @for p5.serialport6 * @main7 */8/**9 * p5.serialport10 * Shawn Van Every (Shawn.Van.Every@nyu.edu)11 * ITP/NYU12 * LGPL13 * 14 * https://github.com/vanevery/p5.serialport15 *16 */17(function(root, factory) {18 if (typeof define === 'function' && define.amd)19 define('p5.serialport', ['p5'], function(p5) {20 (factory(p5));21 });22 else if (typeof exports === 'object')23 factory(require('../p5'));24 else25 factory(root['p5']);26}(this, function(p5) {27 // =============================================================================28 // p5.SerialPort29 // =============================================================================30 /**31 * Base class for a serial port. Creates an instance of the serial library and prints "hostname":"serverPort" in the console.32 *33 * @class p5.SerialPort34 * @constructor35 * @param {String} [hostname] Name of the host. Defaults to 'localhost'.36 * @param {Number} [serverPort] Port number. Defaults to 8081.37 * @example38 * var portName = '/dev/cu.usbmodem1411'; //enter your portName39 * 40 * function setup() {41 * createCanvas(400, 300);42 * serial = new p5.SerialPort()43 * serial.open(portName);44 * }45 */46 p5.SerialPort = function(_hostname, _serverport) {47 var self = this;48 this.bufferSize = 1; // How much to buffer before sending data event49 this.serialBuffer = [];50 //this.maxBufferSize = 1024;51 this.serialConnected = false;52 this.serialport = null;53 this.serialoptions = null;54 this.emitQueue = [];55 this.clientData = {};56 this.serialportList = [];57 if (typeof _hostname === 'string') {58 this.hostname = _hostname;59 } else {60 this.hostname = "localhost";61 }62 if (typeof _serverport === 'number') {63 this.serverport = _serverport;64 } else {65 this.serverport = 8081;66 }67 try {68 this.socket = new WebSocket("ws://" + this.hostname + ":" + this.serverport);69 console.log(("ws://" + this.hostname + ":" + this.serverport));70 } catch (err) {71 if (typeof self.errorCallback !== "undefined") {72 self.errorCallback("Couldn't connect to the server, is it running?");73 }74 }75 this.socket.onopen = function(event) {76 console.log('opened socket');77 serialConnected = true;78 if (typeof self.connectedCallback !== "undefined") {79 self.connectedCallback();80 }81 82 if (self.emitQueue.length > 0) {83 for (var i = 0; i < self.emitQueue.length; i ++){84 self.emit(self.emitQueue[i]);85 }86 self.emitQueue = [];87 }88 };89 this.socket.onmessage = function(event) {90 var messageObject = JSON.parse(event.data);91 // MESSAGE ROUTING92 if (typeof messageObject.method !== "undefined") {93 if (messageObject.method == 'echo') {94 } else if (messageObject.method === "openserial") {95 if (typeof self.openCallback !== "undefined") {96 self.openCallback();97 }98 } else if (messageObject.method === "data") {99 // Add to buffer, assuming this comes in byte by byte100 self.serialBuffer.push(messageObject.data);101 if (typeof self.dataCallback !== "undefined") {102 // Hand it to sketch103 if (self.serialBuffer.length >= self.bufferSize) {104 self.dataCallback();105 }106 }107 if (typeof self.rawDataCallback !== "undefined") {108 self.rawDataCallback(messageObject.data);109 }110 } else if (messageObject.method === 'list') {111 self.serialportList = messageObject.data;112 if (typeof self.listCallback !== "undefined") {113 self.listCallback(messageObject.data);114 }115 } else if (messageObject.method === 'registerClient') {116 self.clientData = messageObject.data;117 if (typeof self.registerCallback !== "undefined") {118 self.registerCallback(messageObject.data);119 }120 } else if (messageObject.method === "close") {121 if (typeof self.closeCallback !== "undefined") {122 self.closeCallback();123 }124 } else if (messageObject.method === "write") {125 // Success Callback?126 } else if (messageObject.method === "error") {127 //console.log(messageObject.data);128 if (typeof self.errorCallback !== "undefined") {129 self.errorCallback(messageObject.data);130 }131 } else {132 // Got message from server without known method133 console.log("Unknown Method: " + messageObject);134 }135 } else {136 console.log("Method Undefined: " + messageObject);137 }138 };139 this.socket.onclose = function(event) {140 if (typeof self.closeCallback !== "undefined") {141 self.closeCallback();142 }143 };144 this.socket.onerror = function(event) {145 if (typeof self.errorCallback !== "undefined") {146 self.errorCallback();147 }148 };149 };150/** 151 *152 * @method emit153 * @private154 * @return155 * @example156 * 157 */158 p5.SerialPort.prototype.emit = function(data) {159 if (this.socket.readyState == WebSocket.OPEN) {160 this.socket.send(JSON.stringify(data));161 } else {162 this.emitQueue.push(data);163 }164 };165/**166 * Tells you whether p5 is connected to the serial port. 167 *168 * @method isConnected169 * @return {Boolean} true or false170 * @example171 * var serial; // variable to hold an instance of the serialport library172 * var portName = '/dev/cu.usbmodem1411';173 * 174 * function setup() {175 * createCanvas(400, 300);176 * serial = new p5.SerialPort();177 * serial.open(portName);178 * println(serial.isConnected());179 * }180 */181 p5.SerialPort.prototype.isConnected = function() {182 if (self.serialConnected) { return true; }183 else { return false; }184 };185/**186 * Lists serial ports available to the server.187 * Synchronously returns cached list, asynchronously returns updated list via callback.188 * Must be called within the p5 setup() function.189 * Doesn't work with the p5 editor's "Run in Browser" mode.190 *191 * @method list192 * @return {Array} array of available serial ports193 * @example194 * function setup() {195 * createCanvas(windowWidth, windowHeight);196 * serial = new p5.SerialPort();197 * serial.list();198 * serial.open("/dev/cu.usbmodem1411");199 * }200 *201 * For full example: <a href="https://itp.nyu.edu/physcomp/labs/labs-serial-communication/two-way-duplex-serial-communication-using-p5js/">Link</a>202 * @example203 * function printList(portList) {204 * // portList is an array of serial port names205 * for (var i = 0; i < portList.length; i++) {206 * // Display the list the console:207 * println(i + " " + portList[i]);208 * }209 * }210 */211 p5.SerialPort.prototype.list = function(cb) {212 if (typeof cb === 'function') {213 this.listCallback = cb;214 }215 this.emit({216 method: 'list',217 data: {}218 });219 return this.serialportList;220 };221/**222 * Opens the serial port to enable data flow.223 * Use the {[serialOptions]} parameter to set the baudrate if it's different from the p5 default, 9600.224 * 225 * @method open226 * @param {String} serialPort Name of the serial port, something like '/dev/cu.usbmodem1411'227 * @param {Object} [serialOptions] Object with optional options as {key: value} pairs.228 * Options include 'baudrate'.229 * @param {Function} [serialCallback] Callback function when open completes230 * @example231 * // Change this to the name of your arduino's serial port232 * serial.open("/dev/cu.usbmodem1411");233 *234 * @example235 * // All of the following are valid:236 * serial.open(portName);237 * serial.open(portName, {}, onOpen);238 * serial.open(portName, {baudrate: 9600}, onOpen)239 * 240 * function onOpen() {241 * print('opened the serial port!');242 * }243 */244 p5.SerialPort.prototype.open = function(_serialport, _serialoptions, cb) {245 if (typeof cb === 'function') {246 this.openCallback = cb;247 }248 this.serialport = _serialport;249 if (typeof _serialoptions === 'object') {250 this.serialoptions = _serialoptions;251 } else {252 //console.log("typeof _serialoptions " + typeof _serialoptions + " setting to {}");253 this.serialoptions = {};254 }255 // If our socket is connected, we'll do this now, 256 // otherwise it will happen in the socket.onopen callback257 this.emit({258 method: 'openserial',259 data: {260 serialport: this.serialport,261 serialoptions: this.serialoptions262 }263 });264 };265/**266 * Sends a byte to a webSocket server which sends the same byte out through a serial port.267 * @method write268 * @param {String, Number, Array} Data Writes bytes, chars, ints, bytes[], and strings to the serial port.269 * @example270 * You can use this with the included Arduino example called PhysicalPixel.271 * Works with P5 editor as the socket/serial server, version 0.5.5 or later.272 * Written 2 Oct 2015 by Tom Igoe. For full example: <a href="https://github.com/vanevery/p5.serialport/tree/master/examples/writeExample">Link</a>273 * 274 * function mouseReleased() {275 * serial.write(outMessage);276 * if (outMessage === 'H') {277 * outMessage = 'L';278 * } else {279 * outMessage = 'H';280 * }281 * }282 *283 * For full example: <a href="https://itp.nyu.edu/physcomp/labs/labs-serial-communication/lab-serial-output-from-p5-js/">Link</a>284 * @example 285 * function mouseDragged() {286 * // map the mouseY to a range from 0 to 255:287 * outByte = int(map(mouseY, 0, height, 0, 255));288 * // send it out the serial port:289 * serial.write(outByte);290 * }291 */292 p5.SerialPort.prototype.write = function(data) {293 //Writes bytes, chars, ints, bytes[], Strings to the serial port294 var toWrite = null;295 if (typeof data == "number") {296 // This is the only one I am treating differently, the rest of the clauses are meaningless297 toWrite = [data];298 } else if (typeof data == "string") {299 toWrite = data;300 } else if (Array.isArray(data)) {301 toWrite = data;302 } else {303 toWrite = data;304 }305 this.emit({306 method: 'write',307 data: toWrite308 });309 };310/**311 * Returns a number between 0 and 255 for the next byte that's waiting in the buffer. 312 * Returns -1 if there is no byte, although this should be avoided by first checking available() to see if data is available.313 *314 * @method read315 * @return {Number} Value of the byte waiting in the buffer. Returns -1 if there is no byte.316 * @example317 * function serialEvent() {318 * inByte = int(serial.read());319 * byteCount++;320 * }321 *322 * @example323 * function serialEvent() {324 * // read a byte from the serial port:325 * var inByte = serial.read();326 * // store it in a global variable:327 * inData = inByte;328 * }329 */330 p5.SerialPort.prototype.read = function() {331 if (this.serialBuffer.length > 0) {332 return this.serialBuffer.shift();333 } else {334 return -1;335 }336 };337/**338 * Returns the next byte in the buffer as a char. 339 * 340 * @method readChar341 * @return {String} Value of the Unicode-code unit character byte waiting in the buffer, converted from bytes. Returns -1 or 0xffff if there is no byte.342 * @example343 * var inData;344 * 345 * function setup() {346 * // callback for when new data arrives347 * serial.on('data', serialEvent); 348 * 349 * function serialEvent() {350 * // read a char from the serial port:351 * inData = serial.readChar();352 * }353 */354 p5.SerialPort.prototype.readChar = function() {355 if (this.serialBuffer.length > 0) {356 /*var currentByte = this.serialBuffer.shift();357 console.log("p5.serialport.js: " + currentByte);358 var currentChar = String.fromCharCode(currentByte);359 console.log("p5.serialport.js: " + currentChar);360 return currentChar;361 */362 return String.fromCharCode(this.serialBuffer.shift());363 } else {364 return -1;365 }366 };367/**368 * Returns a number between 0 and 255 for the next byte that's waiting in the buffer, and then clears the buffer of data. Returns -1 if there is no byte, although this should be avoided by first checking available() to see if data is available.369 * @method readBytes370 * @return {Number} Value of the byte waiting in the buffer. Returns -1 if there is no byte.371 * @example372 * var inData;373 * 374 * function setup() {375 * // callback for when new data arrives376 * serial.on('data', serialEvent); 377 * 378 * function serialEvent() {379 * // read bytes from the serial port:380 * inData = serial.readBytes();381 * }382 */383 p5.SerialPort.prototype.readBytes = function() {384 if (this.serialBuffer.length > 0) {385 var returnBuffer = this.serialBuffer.slice();386 // Clear the array387 this.serialBuffer.length = 0;388 return returnBuffer;389 } else {390 return -1;391 }392 };393/**394 * Returns all of the data available, up to and including a particular character.395 * If the character isn't in the buffer, 'null' is returned. 396 * The version without the byteBuffer parameter returns a byte array of all data up to and including the interesting byte. 397 * This is not efficient, but is easy to use. 398 * 399 * The version with the byteBuffer parameter is more efficient in terms of time and memory. 400 * It grabs the data in the buffer and puts it into the byte array passed in and returns an integer value for the number of bytes read. 401 * If the byte buffer is not large enough, -1 is returned and an error is printed to the message area. 402 * If nothing is in the buffer, 0 is returned.403 *404 * @method readBytesUntil405 * @param {[byteBuffer]} 406 * @return {[Number]} [Number of bytes read]407 * @example408 * // All of the following are valid:409 * charToFind.charCodeAt();410 * charToFind.charCodeAt(0);411 * charToFind.charCodeAt(0, );412 */413 p5.SerialPort.prototype.readBytesUntil = function(charToFind) {414 console.log("Looking for: " + charToFind.charCodeAt(0));415 var index = this.serialBuffer.indexOf(charToFind.charCodeAt(0));416 if (index !== -1) {417 // What to return418 var returnBuffer = this.serialBuffer.slice(0, index + 1);419 // Clear out what was returned420 this.serialBuffer = this.serialBuffer.slice(index, this.serialBuffer.length + index);421 return returnBuffer;422 } else {423 return -1;424 }425 };426/**427 * Returns all the data from the buffer as a String. 428 * This method assumes the incoming characters are ASCII. 429 * If you want to transfer Unicode data: first, convert the String to a byte stream in the representation of your choice (i.e. UTF8 or two-byte Unicode data). 430 * Then, send it as a byte array.431 *432 * @method readString433 * @return434 * @example435 * 436 *437 *438 * 439 */440 p5.SerialPort.prototype.readString = function() {441 //var returnBuffer = this.serialBuffer;442 var stringBuffer = [];443 //console.log("serialBuffer Length: " + this.serialBuffer.length);444 for (var i = 0; i < this.serialBuffer.length; i++) {445 //console.log("push: " + String.fromCharCode(this.serialBuffer[i]));446 stringBuffer.push(String.fromCharCode(this.serialBuffer[i]));447 }448 // Clear the buffer449 this.serialBuffer.length = 0;450 return stringBuffer.join("");451 };452/**453 * Returns all of the data available as an ASCII-encoded string.454 *455 * @method readStringUntil456 * @param {String} stringToFind String to read until.457 * @return {String} ASCII-encoded string until and not including the stringToFind.458 * @example459 *460 * For full example: <a href="https://github.com/tigoe/p5.serialport/blob/master/examples/twoPortRead/sketch.js">Link</a>461 * 462 * var serial1 = new p5.SerialPort();463 * var serial2 = new p5.SerialPort();464 * var input1 = '';465 * var input2 = '';466 * 467 * function serialEvent(){468 * data = serial1.readStringUntil('\r\n');469 * if (data.length > 0){470 * input1 = data;471 * }472 * }473 * 474 * function serial2Event() {475 * var data = serial2.readStringUntil('\r\n');476 * if (data.length > 0){477 * input2 = data;478 * }479 * }480 */481 p5.SerialPort.prototype.readStringUntil = function(stringToFind) {482 var stringBuffer = [];483 //console.log("serialBuffer Length: " + this.serialBuffer.length);484 for (var i = 0; i < this.serialBuffer.length; i++) {485 //console.log("push: " + String.fromCharCode(this.serialBuffer[i]));486 stringBuffer.push(String.fromCharCode(this.serialBuffer[i]));487 }488 stringBuffer = stringBuffer.join("");489 //console.log("stringBuffer: " + stringBuffer);490 var returnString = "";491 var foundIndex = stringBuffer.indexOf(stringToFind);492 //console.log("found index: " + foundIndex);493 if (foundIndex > -1) {494 returnString = stringBuffer.substr(0, foundIndex);495 this.serialBuffer = this.serialBuffer.slice(foundIndex + stringToFind.length);496 }497 //console.log("Sending: " + returnString);498 return returnString;499 };500/**501 * Returns all of the data available as an ASCII-encoded string until a line break is encountered.502 * 503 * @method readLine504 * @return {String} ASCII-encoded string505 * @example506 * 507 * You can use this with the included Arduino example called AnalogReadSerial.508 * Works with P5 editor as the socket/serial server, version 0.5.5 or later.509 * Written 2 Oct 2015 by Tom Igoe. For full example: <a href="https://github.com/vanevery/p5.serialport/tree/master/examples/readAndAnimate">Link</a>510 * 511 * function gotData() {512 * var currentString = serial.readLine(); // read the incoming data513 * trim(currentString); // trim off trailing whitespace514 * 515 * if (!currentString) return; { // if the incoming string is empty, do no more 516 * console.log(currentString);517 * }518 * 519 * if (!isNaN(currentString)) { // make sure the string is a number (i.e. NOT Not a Number (NaN))520 * textXpos = currentString; // save the currentString to use for the text position in draw()521 * }522 * }523 */524 p5.SerialPort.prototype.readLine = function() {525 return this.readStringUntil("\r\n");526 }; 527/**528 * Returns the number of bytes available.529 *530 * @method available531 * @return {Number} The length of the serial buffer array, in terms of number of bytes in the buffer.532 * @example533 * function draw() {534 * // black background, white text:535 * background(0);536 * fill(255);537 * // display the incoming serial data as a string:538 * var displayString = "inByte: " + inByte + "\t Byte count: " + byteCount;539 * displayString += " available: " + serial.available();540 * text(displayString, 30, 60);541 * }542 * */543 p5.SerialPort.prototype.available = function() {544 return this.serialBuffer.length;545 };546/**547 * Returns the last byte of data from the buffer.548 *549 * @method last550 * @return {Number}551 * @example552 * 553 * */554 p5.SerialPort.prototype.last = function() {555 //Returns last byte received556 var last = this.serialBuffer.pop();557 this.serialBuffer.length = 0;558 return last;559 };560/**561 * Returns the last byte of data from the buffer as a char.562 *563 * @method lastChar564 * @example565 * 566 * */567 p5.SerialPort.prototype.lastChar = function() {568 return String.fromCharCode(this.last());569 };570/**571 * Clears the underlying serial buffer.572 *573 * @method clear574 * @example575 */576 p5.SerialPort.prototype.clear = function() {577 //Empty the buffer, removes all the data stored there.578 this.serialBuffer.length = 0;579 };580/**581 * Stops data communication on this port. 582 * Use to shut the connection when you're finished with the Serial.583 *584 * @method stop585 * @example586 * 587 */588 p5.SerialPort.prototype.stop = function() {589 };590/**591 * Tell server to close the serial port. This functions the same way as serial.on('close', portClose).592 * 593 * @method close594 * @param {String} name of callback595 * @example596 * 597 * var inData;598 * 599 * function setup() {600 * serial.open(portOpen);601 * serial.close(portClose); 602 * }603 * 604 * function portOpen() {605 * println('The serial port is open.');606 * } 607 * 608 * function portClose() {609 * println('The serial port closed.');610 * } 611 */612 p5.SerialPort.prototype.close = function(cb) {613 // 614 if (typeof cb === 'function') {615 this.closeCallback = cb;616 }617 this.emit({618 method: 'close',619 data: {}620 });621 };622/**623 * Register clients that connect to the serial server. 624 * 625 * This is for use with the p5 Serial Control application so the application 626 * can access and render the names of clients who have connected. Note that 627 * calling this method does not log the list of registered clients. To do that, 628 * you'd use:629 * serial.on('registerClient', logClientData)630 *631 * The example demonstates the registerClient method, as well as how you'd log632 * the list of clients.633 * 634 * @method registerClient635 * @example636 * 637 * function setup() {638 * // Create a new p5 Serial Port object639 * serial = new p5.SerialPort();640 * // List the available ports641 * serial.list();642 * // On port open, call the gotOpen callback643 * serial.on('open', gotOpen);644 * // Register the clients that have connected to the server645 * serial.registerClient();646 * // After registerClient method is done, call the logClientData callback647 * serial.on('registerClient', logClientData)648 * }649 * 650 * // Callback to log the client data651 * function logClientData(data) {652 * console.log("Client data: ", data)653 * }654 * 655 * // Callback to log a message when the port is opened656 * function gotOpen() {657 * console.log("Serial port is open.")658 * }659 */660 p5.SerialPort.prototype.registerClient = function(cb) {661 if (typeof cb === 'function') {662 this.registerCallback = cb;663 }664 this.emit({665 method: 'registerClient',666 data: {}667 });668 return this.clientData;669 }; 670/**671 * // Register callback methods from sketch672 * 673 */674 p5.SerialPort.prototype.onData = function(_callback) {675 this.on('data',_callback);676 };677 p5.SerialPort.prototype.onOpen = function(_callback) {678 this.on('open',_callback);679 };680 p5.SerialPort.prototype.onClose = function(_callback) {681 this.on('close',_callback);682 };683 p5.SerialPort.prototype.onError = function(_callback) {684 this.on('error',_callback);685 };686 p5.SerialPort.prototype.onList = function(_callback) {687 this.on('list',_callback);688 };689 p5.SerialPort.prototype.onConnected = function(_callback) {690 this.on('connected',_callback);691 };692 p5.SerialPort.prototype.onRawData = function(_callback) {693 this.on('rawdata',_callback);694 };695 p5.SerialPort.prototype.onRegisterClient = function(_callback) {696 this.on('registerClient', _callback);697 };698 // Version 2699 p5.SerialPort.prototype.on = function(_event, _callback) {700 if (_event == 'open') {701 this.openCallback = _callback;702 } else if (_event == 'data') {703 this.dataCallback = _callback;704 } else if (_event == 'close') {705 this.closeCallback = _callback;706 } else if (_event == 'error') {707 this.errorCallback = _callback;708 } else if (_event == 'list') {709 this.listCallback = _callback;710 } else if (_event == 'connected') {711 this.connectedCallback = _callback;712 } else if (_event == 'rawdata') {713 this.rawDataCallback = _callback;714 } else if (_event == 'registerClient') {715 this.registerCallback = _callback;716 }717 };...

Full Screen

Full Screen

safari_serial.py

Source:safari_serial.py Github

copy

Full Screen

...65 self.thread.daemon = True66 67 def on_serial_connection_button_clicked(self, arg):68 if self.serial_connected:69 self.disconnect_serial()70 else:71 self.connect_serial(self.selected_serial_port, self.BAUD)72 73 def on_serial_scan_button_clicked(self, arg):74 self.serial_ports = self.__serial_port_scan()75 76 if len(self.serial_ports) == 0:77 self.serial_ports.append("No Serial Cable Connected")78 79 self.serial_port_list.options = self.serial_ports80 81 def on_data_collect_button_clicked(self, arg):82 if not self.data_collection_in_progress:83 self.data_collection_start()84 self.data_collection_in_progress = True85 self.data_collect_button.description = "Stop Data Collection"86 else:87 self.data_collection_stop()88 self.data_collection_in_progress = False89 self.data_collect_button.description = "Start Data Collection"90 # Function for opening a serial connection on the specified port91 def connect_serial(self, port, baud):92 """ The function initiates the Connection to the UART device with the specified Port.93 :param port: Serial port to connect to.94 :param baud: Baud rate of the serial connection.95 :returns:96 0 if the serial connection is successfully opened.97 -1 if the connection fails to open.98 """99 try:100 self.serial = pyserial.Serial(port, baud, timeout=0, writeTimeout=0) # ensure non-blocking101 self.serial_connected = True102 self.serial_port_list.disabled = True103 self.serial_connection_button.disabled = True104 self.serial_scan_button.disabled = True105 106 # Start a thread to handle receiving serial data107 if not self.thread.is_alive():108 self.thread.start()109 # Kill any running processes110 self.__serial_ctrl_c()111 time.sleep(0.25)112 self.__login()113 time.sleep(0.25)114 self.serial.write(str("\n").encode('utf-8'))115 return 0116 except Exception as e:117 logging.exception(e)118 print("Cant Open Specified Port")119 return -1120 121 def disconnect_serial(self):122 """ This function is for disconnecting and quitting the application.123 Sometimes the application throws a couple of errors while it is being shut down, the fix isn't out yet124 :returns:125 0 if the serial connection is successfully closed.126 -1 if the connection fails to close.127 """128 try:129 self.serial_connected = False130 self.serial.close()131 self.serial_port_list.disabled = False132 self.serial_scan_button.disabled = False133 self.data_collect_button.disabled = True134 self.serial_connection_button.description = "Connect"135 return 0136 except Exception as e:137 logging.exception(e)138 return -1139 140 def write_serial(self, string):141 string = string + "\n"142 self.serial.write(string.encode('utf-8'))143 144 def write_file_to_meerkat(self, file):145 self.serial.write(str("rm /root/python/" + file + "\n").encode('utf-8'))146 f = open(file, "r")147 for line in f:148 #Remove excess newline character since we will insert one line at a time149 line = line.rstrip('\n')150 #print(str("echo '" + line + "' >> /root/python/" + file + "\n").encode('utf-8'))151 self.serial.write(str("echo \"" + line + "\" >> /root/python/" + file + "\n").encode('utf-8'))152 f.close()153 154 def write_file_to_meerkat(self, src_file, dst_file):155 self.serial.write(str("rm /root/python/" + dst_file + "\n").encode('utf-8'))156 f = open(src_file, "r")157 for line in f:158 #Remove excess newline character since we will insert one line at a time159 line = line.rstrip('\n')160 #print(str("echo '" + line + "' >> /root/python/" + file + "\n").encode('utf-8'))161 self.serial.write(str("echo \"" + line + "\" >> /root/python/" + dst_file + "\n").encode('utf-8'))162 f.close()163 def read_serial(self):164 # Infinite loop is okay since this is running in it's own thread.165 while True:166 # Only try to read the serial port if connected167 if self.serial_connected:168 try:169 c = self.serial.read().decode('unicode_escape') # attempt to read a character from Serial170 # was anything read?171 if len(c) == 0:172 pass173 # check if character is a delimeter174 if c == '\r':175 c = '' # don't want returns. chuck it176 if c == '\n':177 self.serial_buffer += "\n" # add the newline to the buffer...

Full Screen

Full Screen

test_rfc1982.py

Source:test_rfc1982.py Github

copy

Full Screen

1# Copyright (c) Twisted Matrix Laboratories.2# See LICENSE for details.3"""4Test cases for L{twisted.names.rfc1982}.5"""6from __future__ import division, absolute_import7import calendar8from datetime import datetime9from functools import partial10from twisted.names._rfc1982 import SerialNumber11from twisted.trial import unittest12class SerialNumberTests(unittest.TestCase):13 """14 Tests for L{SerialNumber}.15 """16 def test_serialBitsDefault(self):17 """18 L{SerialNumber.serialBits} has default value 32.19 """20 self.assertEqual(SerialNumber(1)._serialBits, 32)21 def test_serialBitsOverride(self):22 """23 L{SerialNumber.__init__} accepts a C{serialBits} argument whose value is24 assigned to L{SerialNumber.serialBits}.25 """26 self.assertEqual(SerialNumber(1, serialBits=8)._serialBits, 8)27 def test_repr(self):28 """29 L{SerialNumber.__repr__} returns a string containing number and30 serialBits.31 """32 self.assertEqual(33 '<SerialNumber number=123 serialBits=32>',34 repr(SerialNumber(123, serialBits=32))35 )36 def test_str(self):37 """38 L{SerialNumber.__str__} returns a string representation of the current39 value.40 """41 self.assertEqual(str(SerialNumber(123)), '123')42 def test_int(self):43 """44 L{SerialNumber.__int__} returns an integer representation of the current45 value.46 """47 self.assertEqual(int(SerialNumber(123)), 123)48 def test_hash(self):49 """50 L{SerialNumber.__hash__} allows L{SerialNumber} instances to be hashed51 for use as dictionary keys.52 """53 self.assertEqual(hash(SerialNumber(1)), hash(SerialNumber(1)))54 self.assertNotEqual(hash(SerialNumber(1)), hash(SerialNumber(2)))55 def test_convertOtherSerialBitsMismatch(self):56 """57 L{SerialNumber._convertOther} raises L{TypeError} if the other58 SerialNumber instance has a different C{serialBits} value.59 """60 s1 = SerialNumber(0, serialBits=8)61 s2 = SerialNumber(0, serialBits=16)62 self.assertRaises(63 TypeError,64 s1._convertOther,65 s266 )67 def test_eq(self):68 """69 L{SerialNumber.__eq__} provides rich equality comparison.70 """71 self.assertEqual(SerialNumber(1), SerialNumber(1))72 def test_eqForeignType(self):73 """74 == comparison of L{SerialNumber} with a non-L{SerialNumber} instance75 raises L{TypeError}.76 """77 self.assertRaises(TypeError, lambda: SerialNumber(1) == object())78 def test_ne(self):79 """80 L{SerialNumber.__ne__} provides rich equality comparison.81 """82 self.assertFalse(SerialNumber(1) != SerialNumber(1))83 self.assertNotEqual(SerialNumber(1), SerialNumber(2))84 def test_neForeignType(self):85 """86 != comparison of L{SerialNumber} with a non-L{SerialNumber} instance87 raises L{TypeError}.88 """89 self.assertRaises(TypeError, lambda: SerialNumber(1) != object())90 def test_le(self):91 """92 L{SerialNumber.__le__} provides rich <= comparison.93 """94 self.assertTrue(SerialNumber(1) <= SerialNumber(1))95 self.assertTrue(SerialNumber(1) <= SerialNumber(2))96 def test_leForeignType(self):97 """98 <= comparison of L{SerialNumber} with a non-L{SerialNumber} instance99 raises L{TypeError}.100 """101 self.assertRaises(TypeError, lambda: SerialNumber(1) <= object())102 def test_ge(self):103 """104 L{SerialNumber.__ge__} provides rich >= comparison.105 """106 self.assertTrue(SerialNumber(1) >= SerialNumber(1))107 self.assertTrue(SerialNumber(2) >= SerialNumber(1))108 def test_geForeignType(self):109 """110 >= comparison of L{SerialNumber} with a non-L{SerialNumber} instance111 raises L{TypeError}.112 """113 self.assertRaises(TypeError, lambda: SerialNumber(1) >= object())114 def test_lt(self):115 """116 L{SerialNumber.__lt__} provides rich < comparison.117 """118 self.assertTrue(SerialNumber(1) < SerialNumber(2))119 def test_ltForeignType(self):120 """121 < comparison of L{SerialNumber} with a non-L{SerialNumber} instance122 raises L{TypeError}.123 """124 self.assertRaises(TypeError, lambda: SerialNumber(1) < object())125 def test_gt(self):126 """127 L{SerialNumber.__gt__} provides rich > comparison.128 """129 self.assertTrue(SerialNumber(2) > SerialNumber(1))130 def test_gtForeignType(self):131 """132 > comparison of L{SerialNumber} with a non-L{SerialNumber} instance133 raises L{TypeError}.134 """135 self.assertRaises(TypeError, lambda: SerialNumber(2) > object())136 def test_add(self):137 """138 L{SerialNumber.__add__} allows L{SerialNumber} instances to be summed.139 """140 self.assertEqual(SerialNumber(1) + SerialNumber(1), SerialNumber(2))141 def test_addForeignType(self):142 """143 Addition of L{SerialNumber} with a non-L{SerialNumber} instance raises144 L{TypeError}.145 """146 self.assertRaises(TypeError, lambda: SerialNumber(1) + object())147 def test_addOutOfRangeHigh(self):148 """149 L{SerialNumber} cannot be added with other SerialNumber values larger150 than C{_maxAdd}.151 """152 maxAdd = SerialNumber(1)._maxAdd153 self.assertRaises(154 ArithmeticError,155 lambda: SerialNumber(1) + SerialNumber(maxAdd + 1))156 def test_maxVal(self):157 """158 L{SerialNumber.__add__} returns a wrapped value when s1 plus the s2159 would result in a value greater than the C{maxVal}.160 """161 s = SerialNumber(1)162 maxVal = s._halfRing + s._halfRing - 1163 maxValPlus1 = maxVal + 1164 self.assertTrue(SerialNumber(maxValPlus1) > SerialNumber(maxVal))165 self.assertEqual(SerialNumber(maxValPlus1), SerialNumber(0))166 def test_fromRFC4034DateString(self):167 """168 L{SerialNumber.fromRFC4034DateString} accepts a datetime string argument169 of the form 'YYYYMMDDhhmmss' and returns an L{SerialNumber} instance170 whose value is the unix timestamp corresponding to that UTC date.171 """172 self.assertEqual(173 SerialNumber(1325376000),174 SerialNumber.fromRFC4034DateString('20120101000000')175 )176 def test_toRFC4034DateString(self):177 """178 L{DateSerialNumber.toRFC4034DateString} interprets the current value as179 a unix timestamp and returns a date string representation of that date.180 """181 self.assertEqual(182 '20120101000000',183 SerialNumber(1325376000).toRFC4034DateString()184 )185 def test_unixEpoch(self):186 """187 L{SerialNumber.toRFC4034DateString} stores 32bit timestamps relative to188 the UNIX epoch.189 """190 self.assertEqual(191 SerialNumber(0).toRFC4034DateString(),192 '19700101000000'193 )194 def test_Y2106Problem(self):195 """196 L{SerialNumber} wraps unix timestamps in the year 2106.197 """198 self.assertEqual(199 SerialNumber(-1).toRFC4034DateString(),200 '21060207062815'201 )202 def test_Y2038Problem(self):203 """204 L{SerialNumber} raises ArithmeticError when used to add dates more than205 68 years in the future.206 """207 maxAddTime = calendar.timegm(208 datetime(2038, 1, 19, 3, 14, 7).utctimetuple())209 self.assertEqual(210 maxAddTime,211 SerialNumber(0)._maxAdd,212 )213 self.assertRaises(214 ArithmeticError,215 lambda: SerialNumber(0) + SerialNumber(maxAddTime + 1))216def assertUndefinedComparison(testCase, s1, s2):217 """218 A custom assertion for L{SerialNumber} values that cannot be meaningfully219 compared.220 "Note that there are some pairs of values s1 and s2 for which s1 is not221 equal to s2, but for which s1 is neither greater than, nor less than, s2.222 An attempt to use these ordering operators on such pairs of values produces223 an undefined result."224 @see: U{https://tools.ietf.org/html/rfc1982#section-3.2}225 @param testCase: The L{unittest.TestCase} on which to call assertion226 methods.227 @type testCase: L{unittest.TestCase}228 @param s1: The first value to compare.229 @type s1: L{SerialNumber}230 @param s2: The second value to compare.231 @type s2: L{SerialNumber}232 """233 testCase.assertFalse(s1 == s2)234 testCase.assertFalse(s1 <= s2)235 testCase.assertFalse(s1 < s2)236 testCase.assertFalse(s1 > s2)237 testCase.assertFalse(s1 >= s2)238serialNumber2 = partial(SerialNumber, serialBits=2)239class SerialNumber2BitTests(unittest.TestCase):240 """241 Tests for correct answers to example calculations in RFC1982 5.1.242 The simplest meaningful serial number space has SERIAL_BITS == 2. In this243 space, the integers that make up the serial number space are 0, 1, 2, and 3.244 That is, 3 == 2^SERIAL_BITS - 1.245 https://tools.ietf.org/html/rfc1982#section-5.1246 """247 def test_maxadd(self):248 """249 In this space, the largest integer that it is meaningful to add to a250 sequence number is 2^(SERIAL_BITS - 1) - 1, or 1.251 """252 self.assertEqual(SerialNumber(0, serialBits=2)._maxAdd, 1)253 def test_add(self):254 """255 Then, as defined 0+1 == 1, 1+1 == 2, 2+1 == 3, and 3+1 == 0.256 """257 self.assertEqual(serialNumber2(0) + serialNumber2(1), serialNumber2(1))258 self.assertEqual(serialNumber2(1) + serialNumber2(1), serialNumber2(2))259 self.assertEqual(serialNumber2(2) + serialNumber2(1), serialNumber2(3))260 self.assertEqual(serialNumber2(3) + serialNumber2(1), serialNumber2(0))261 def test_gt(self):262 """263 Further, 1 > 0, 2 > 1, 3 > 2, and 0 > 3.264 """265 self.assertTrue(serialNumber2(1) > serialNumber2(0))266 self.assertTrue(serialNumber2(2) > serialNumber2(1))267 self.assertTrue(serialNumber2(3) > serialNumber2(2))268 self.assertTrue(serialNumber2(0) > serialNumber2(3))269 def test_undefined(self):270 """271 It is undefined whether 2 > 0 or 0 > 2, and whether 1 > 3 or 3 > 1.272 """273 assertUndefinedComparison(self, serialNumber2(2), serialNumber2(0))274 assertUndefinedComparison(self, serialNumber2(0), serialNumber2(2))275 assertUndefinedComparison(self, serialNumber2(1), serialNumber2(3))276 assertUndefinedComparison(self, serialNumber2(3), serialNumber2(1))277serialNumber8 = partial(SerialNumber, serialBits=8)278class SerialNumber8BitTests(unittest.TestCase):279 """280 Tests for correct answers to example calculations in RFC1982 5.2.281 Consider the case where SERIAL_BITS == 8. In this space the integers that282 make up the serial number space are 0, 1, 2, ... 254, 255. 255 ==283 2^SERIAL_BITS - 1.284 https://tools.ietf.org/html/rfc1982#section-5.2285 """286 def test_maxadd(self):287 """288 In this space, the largest integer that it is meaningful to add to a289 sequence number is 2^(SERIAL_BITS - 1) - 1, or 127.290 """291 self.assertEqual(SerialNumber(0, serialBits=8)._maxAdd, 127)292 def test_add(self):293 """294 Addition is as expected in this space, for example: 255+1 == 0,295 100+100 == 200, and 200+100 == 44.296 """297 self.assertEqual(298 serialNumber8(255) + serialNumber8(1), serialNumber8(0))299 self.assertEqual(300 serialNumber8(100) + serialNumber8(100), serialNumber8(200))301 self.assertEqual(302 serialNumber8(200) + serialNumber8(100), serialNumber8(44))303 def test_gt(self):304 """305 Comparison is more interesting, 1 > 0, 44 > 0, 100 > 0, 100 > 44,306 200 > 100, 255 > 200, 0 > 255, 100 > 255, 0 > 200, and 44 > 200.307 """308 self.assertTrue(serialNumber8(1) > serialNumber8(0))309 self.assertTrue(serialNumber8(44) > serialNumber8(0))310 self.assertTrue(serialNumber8(100) > serialNumber8(0))311 self.assertTrue(serialNumber8(100) > serialNumber8(44))312 self.assertTrue(serialNumber8(200) > serialNumber8(100))313 self.assertTrue(serialNumber8(255) > serialNumber8(200))314 self.assertTrue(serialNumber8(100) > serialNumber8(255))315 self.assertTrue(serialNumber8(0) > serialNumber8(200))316 self.assertTrue(serialNumber8(44) > serialNumber8(200))317 def test_surprisingAddition(self):318 """319 Note that 100+100 > 100, but that (100+100)+100 < 100. Incrementing a320 serial number can cause it to become "smaller". Of course, incrementing321 by a smaller number will allow many more increments to be made before322 this occurs. However this is always something to be aware of, it can323 cause surprising errors, or be useful as it is the only defined way to324 actually cause a serial number to decrease.325 """326 self.assertTrue(327 serialNumber8(100) + serialNumber8(100) > serialNumber8(100))328 self.assertTrue(329 serialNumber8(100) + serialNumber8(100) + serialNumber8(100)330 < serialNumber8(100))331 def test_undefined(self):332 """333 The pairs of values 0 and 128, 1 and 129, 2 and 130, etc, to 127 and 255334 are not equal, but in each pair, neither number is defined as being335 greater than, or less than, the other.336 """337 assertUndefinedComparison(self, serialNumber8(0), serialNumber8(128))338 assertUndefinedComparison(self, serialNumber8(1), serialNumber8(129))339 assertUndefinedComparison(self, serialNumber8(2), serialNumber8(130))...

Full Screen

Full Screen

serial_8h.js

Source:serial_8h.js Github

copy

Full Screen

1var serial_8h =2[3 [ "EMBER_SERIAL_BUFFER", "group__serial.html#gac4245c7ba24addf61a174d4684d560e9", null ],4 [ "EMBER_SERIAL_FIFO", "group__serial.html#gaa8305e0960f14a47b6f6e5e68e00b433", null ],5 [ "EMBER_SERIAL_LOWLEVEL", "group__serial.html#ga5fb0daf83349cf27be1a371776296ff7", null ],6 [ "EMBER_SERIAL_UNUSED", "group__serial.html#ga44fab93c5555efea947b6e78d28405a4", null ],7 [ "FIFO_DEQUEUE", "group__serial.html#gaa9ed21755e12d502f03e0fa08618618c", null ],8 [ "FIFO_ENQUEUE", "group__serial.html#ga950bcbeecd3f4118871b596bd2e51a36", null ],9 [ "halInternalUart1FlowControlRxIsEnabled", "group__serial.html#ga4475715bcb768aba26c89a5c677b9e68", null ],10 [ "halInternalUart1TxIsIdle", "group__serial.html#ga25a98a82cdeddf2f892d0232b864d790", null ],11 [ "halInternalUart1XonRefreshDone", "group__serial.html#gac70ec510e77ca4a7efc984471eac879a", null ],12 [ "halInternalUartFlowControl", "group__serial.html#gaa980a0d0e1c49f0f043a1f5dd48efa4d", null ],13 [ "halInternalUartRxPump", "group__serial.html#ga005ec617ad0592a9bf174f578387ade2", null ],14 [ "SerialBaudRate", "group__serial.html#ga79e9d2305515318a1ae0ab5aaffd6fcb", [15 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],16 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],17 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],18 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],19 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],20 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],21 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],22 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],23 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],24 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],25 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],26 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],27 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],28 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],29 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],30 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],31 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],32 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ],33 [ "DEFINE_BAUD", "group__serial.html#gga79e9d2305515318a1ae0ab5aaffd6fcbaddd7d1b8d46d2e29d36ba073b1ea8dcd", null ]34 ] ],35 [ "SerialParity", "group__serial.html#ga2c48912c12fd98a4f4faffbc7f20a9f6", [36 [ "DEFINE_PARITY", "group__serial.html#gga2c48912c12fd98a4f4faffbc7f20a9f6a9569a17323e2dd2a5bb1db6a96621815", null ],37 [ "DEFINE_PARITY", "group__serial.html#gga2c48912c12fd98a4f4faffbc7f20a9f6a9569a17323e2dd2a5bb1db6a96621815", null ],38 [ "DEFINE_PARITY", "group__serial.html#gga2c48912c12fd98a4f4faffbc7f20a9f6a9569a17323e2dd2a5bb1db6a96621815", null ]39 ] ],40 [ "emLoadSerialTx", "group__serial.html#gafcfc22a24cfcc5893d2eb2ed97c4fd82", null ],41 [ "emSerialBufferNextBlockIsr", "group__serial.html#ga83a1e3e5c2b2967c543ab533641408ed", null ],42 [ "emSerialBufferNextMessageIsr", "group__serial.html#ga278383057324400921c0d3ec8f9319f2", null ],43 [ "halHostEnqueueTx", "group__serial.html#gabff9b5c70adebfe64b6d0116d9a155bf", null ],44 [ "halHostFlushBuffers", "group__serial.html#ga8d2d93d79500c2f106b09e0ac7b49c79", null ],45 [ "halHostFlushTx", "group__serial.html#ga456af71802cd14910d2c4084b2bf27b1", null ],46 [ "halInternalForceReadUartByte", "group__serial.html#ga731dd7236b357ae604368029cfe3492a", null ],47 [ "halInternalForceWriteUartData", "group__serial.html#ga3706baabfda05b7856f71295294ea0a4", null ],48 [ "halInternalPowerDownUart", "group__serial.html#ga7ac65cff3fc25dd920ddf870f0128f54", null ],49 [ "halInternalPowerUpUart", "group__serial.html#gaa23c94239635acd17fd1ca42c3e20dea", null ],50 [ "halInternalRestartUart", "group__serial.html#ga5e9274cfa859ea19f66592117742ceef", null ],51 [ "halInternalStartUartTx", "group__serial.html#ga57cd95148c6b9421d1084bf27c3133ec", null ],52 [ "halInternalStopUartTx", "group__serial.html#gab07f42ec9a362d2729585b91ef38dc41", null ],53 [ "halInternalUartFlowControlRxIsEnabled", "group__serial.html#ga2184eb97de15b6738e5ca11b40decdf1", null ],54 [ "halInternalUartInit", "group__serial.html#gaab61a51a0303d086e456010e087d9e3e", null ],55 [ "halInternalUartTxIsIdle", "group__serial.html#gaf0dee46577b66b28822d8a0d0f9c39f8", null ],56 [ "halInternalUartXonRefreshDone", "group__serial.html#gaffe915169918aa8359b63972126c56f0", null ],57 [ "halInternalWaitUartTxComplete", "group__serial.html#ga3524b7efe60c7a79938bc14f2bd7e5ca", null ],58 [ "halStackReceiveVuartMessage", "group__serial.html#gaaa462705765e53133edf705e12e8cfad", null ],59 [ "serialCopyFromRx", "group__serial.html#ga32d84751c1d7b33d771378e4732023c6", null ],60 [ "serialDropPacket", "group__serial.html#gab994f4b392102158f3632d6fe5e0e4ca", null ]...

Full Screen

Full Screen

stock_assign_serial_numbers.py

Source:stock_assign_serial_numbers.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# Part of Odoo. See LICENSE file for full copyright and licensing details.3from collections import Counter4from odoo import _, api, fields, models5from odoo.exceptions import UserError6class StockAssignSerialNumbers(models.TransientModel):7 _inherit = 'stock.assign.serial'8 production_id = fields.Many2one('mrp.production', 'Production')9 expected_qty = fields.Float('Expected Quantity', digits='Product Unit of Measure')10 serial_numbers = fields.Text('Produced Serial Numbers')11 produced_qty = fields.Float('Produced Quantity', digits='Product Unit of Measure')12 show_apply = fields.Boolean(help="Technical field to show the Apply button")13 show_backorders = fields.Boolean(help="Technical field to show the Create Backorder and No Backorder buttons")14 def generate_serial_numbers_production(self):15 if self.next_serial_number and self.next_serial_count:16 generated_serial_numbers = "\n".join(self.env['stock.production.lot'].generate_lot_names(self.next_serial_number, self.next_serial_count))17 self.serial_numbers = "\n".join([self.serial_numbers, generated_serial_numbers]) if self.serial_numbers else generated_serial_numbers18 self._onchange_serial_numbers()19 action = self.env["ir.actions.actions"]._for_xml_id("mrp.act_assign_serial_numbers_production")20 action['res_id'] = self.id21 return action22 def _get_serial_numbers(self):23 if self.serial_numbers:24 return list(filter(lambda serial_number: len(serial_number.strip()) > 0, self.serial_numbers.split('\n')))25 return []26 @api.onchange('serial_numbers')27 def _onchange_serial_numbers(self):28 self.show_apply = False29 self.show_backorders = False30 serial_numbers = self._get_serial_numbers()31 duplicate_serial_numbers = [serial_number for serial_number, counter in Counter(serial_numbers).items() if counter > 1]32 if duplicate_serial_numbers:33 self.serial_numbers = ""34 self.produced_qty = 035 raise UserError(_('Duplicate Serial Numbers (%s)') % ','.join(duplicate_serial_numbers))36 existing_serial_numbers = self.env['stock.production.lot'].search([37 ('company_id', '=', self.production_id.company_id.id),38 ('product_id', '=', self.production_id.product_id.id),39 ('name', 'in', serial_numbers),40 ])41 if existing_serial_numbers:42 self.serial_numbers = ""43 self.produced_qty = 044 raise UserError(_('Existing Serial Numbers (%s)') % ','.join(existing_serial_numbers.mapped('display_name')))45 if len(serial_numbers) > self.expected_qty:46 self.serial_numbers = ""47 self.produced_qty = 048 raise UserError(_('There are more Serial Numbers than the Quantity to Produce'))49 self.produced_qty = len(serial_numbers)50 self.show_apply = self.produced_qty == self.expected_qty51 self.show_backorders = self.produced_qty > 0 and self.produced_qty < self.expected_qty52 def _assign_serial_numbers(self, cancel_remaining_quantity=False):53 serial_numbers = self._get_serial_numbers()54 productions = self.production_id._split_productions(55 {self.production_id: [1] * len(serial_numbers)}, cancel_remaining_quantity, set_consumed_qty=True)56 production_lots_vals = []57 for serial_name in serial_numbers:58 production_lots_vals.append({59 'product_id': self.production_id.product_id.id,60 'company_id': self.production_id.company_id.id,61 'name': serial_name,62 })63 production_lots = self.env['stock.production.lot'].create(production_lots_vals)64 for production, production_lot in zip(productions, production_lots):65 production.lot_producing_id = production_lot.id66 production.qty_producing = production.product_qty67 for workorder in production.workorder_ids:68 workorder.qty_produced = workorder.qty_producing69 if productions and len(production_lots) < len(productions):70 productions[-1].move_raw_ids.move_line_ids.write({'qty_done': 0})71 productions[-1].state = "confirmed"72 def apply(self):73 self._assign_serial_numbers()74 def create_backorder(self):75 self._assign_serial_numbers(False)76 def no_backorder(self):...

Full Screen

Full Screen

all_7.js

Source:all_7.js Github

copy

Full Screen

1var searchData=2[3 ['getbaudrate',['getBaudrate',['../classserial_1_1_serial.html#a7a6ca1f8d8e68742e95b7f8dc8e9a1fa',1,'serial::Serial']]],4 ['getbytesize',['getBytesize',['../classserial_1_1_serial.html#ac735ef88a54659e2d0b3ae674c5f0a41',1,'serial::Serial']]],5 ['getbytetime',['getByteTime',['../classserial_1_1_serial.html#a8b7ad05b2521db6bbf184108f59e105e',1,'serial::Serial']]],6 ['getcd',['getCD',['../classserial_1_1_serial.html#a5a7c1a8e363b530147970155d0f6fe8d',1,'serial::Serial']]],7 ['getcts',['getCTS',['../classserial_1_1_serial.html#a97603438c9ded81a886f914b7a335d7f',1,'serial::Serial']]],8 ['getdata',['getData',['../classydlidar_1_1_y_dlidar_driver.html#ad787e714bc05e5a70a42b096e632c60f',1,'ydlidar::YDlidarDriver']]],9 ['getdeviceinfo',['getDeviceInfo',['../classydlidar_1_1_y_dlidar_driver.html#ab75303116c4ccb144ecc215e94114e1a',1,'ydlidar::YDlidarDriver']]],10 ['getdsr',['getDSR',['../classserial_1_1_serial.html#a91a00816bce6a163ea022b4cf8d4ce0e',1,'serial::Serial']]],11 ['getflowcontrol',['getFlowcontrol',['../classserial_1_1_serial.html#ad793526755625a59a0bf9d4cc0ea1755',1,'serial::Serial']]],12 ['gethealth',['getHealth',['../classydlidar_1_1_y_dlidar_driver.html#a9fe6f8b842a2aff2c3ae13f8423b03f4',1,'ydlidar::YDlidarDriver']]],13 ['getheartbeat',['getHeartBeat',['../classydlidar_1_1_y_dlidar_driver.html#a36b01c5124032be12ecbeffeefd38742',1,'ydlidar::YDlidarDriver']]],14 ['getmotorstate',['getMotorState',['../classydlidar_1_1_y_dlidar_driver.html#af5d460ababe4b8a34b02d33268f24d4d',1,'ydlidar::YDlidarDriver']]],15 ['getparity',['getParity',['../classserial_1_1_serial.html#a80e5d87b1e93b4c5a9d6f2cc7110b3c4',1,'serial::Serial']]],16 ['getport',['getPort',['../classserial_1_1_serial.html#a56eafe1694c92655d79993ce7139f0bf',1,'serial::Serial']]],17 ['getri',['getRI',['../classserial_1_1_serial.html#a29a1f68b9a238e9a6a833373855708ce',1,'serial::Serial']]],18 ['getsamplingrate',['getSamplingRate',['../classydlidar_1_1_y_dlidar_driver.html#a7b7812329013f119235abf74da397aaa',1,'ydlidar::YDlidarDriver']]],19 ['getscanfrequency',['getScanFrequency',['../classydlidar_1_1_y_dlidar_driver.html#a76efb701e137121b213f61028e3f235e',1,'ydlidar::YDlidarDriver']]],20 ['getsdkversion',['getSDKVersion',['../classydlidar_1_1_y_dlidar_driver.html#a542dc18ac8dbcda2a51657cf9bd44ae0',1,'ydlidar::YDlidarDriver']]],21 ['getstopbits',['getStopbits',['../classserial_1_1_serial.html#a81ee96ec2fdb80d1851430d9e2c4698b',1,'serial::Serial']]],22 ['gettimeout',['getTimeout',['../classserial_1_1_serial.html#a13023f118c75b27fa2f0280d2d1c2a20',1,'serial::Serial']]],23 ['grabscandata',['grabScanData',['../classydlidar_1_1_y_dlidar_driver.html#a6d6e04efa9d7e5d4aea41ee53d4ea8af',1,'ydlidar::YDlidarDriver']]]...

Full Screen

Full Screen

functions_5.js

Source:functions_5.js Github

copy

Full Screen

1var searchData=2[3 ['getbaudrate',['getBaudrate',['../classserial_1_1_serial.html#a7a6ca1f8d8e68742e95b7f8dc8e9a1fa',1,'serial::Serial']]],4 ['getbytesize',['getBytesize',['../classserial_1_1_serial.html#ac735ef88a54659e2d0b3ae674c5f0a41',1,'serial::Serial']]],5 ['getbytetime',['getByteTime',['../classserial_1_1_serial.html#a8b7ad05b2521db6bbf184108f59e105e',1,'serial::Serial']]],6 ['getcd',['getCD',['../classserial_1_1_serial.html#a5a7c1a8e363b530147970155d0f6fe8d',1,'serial::Serial']]],7 ['getcts',['getCTS',['../classserial_1_1_serial.html#a97603438c9ded81a886f914b7a335d7f',1,'serial::Serial']]],8 ['getdata',['getData',['../classydlidar_1_1_y_dlidar_driver.html#ad787e714bc05e5a70a42b096e632c60f',1,'ydlidar::YDlidarDriver']]],9 ['getdeviceinfo',['getDeviceInfo',['../classydlidar_1_1_y_dlidar_driver.html#ab75303116c4ccb144ecc215e94114e1a',1,'ydlidar::YDlidarDriver']]],10 ['getdsr',['getDSR',['../classserial_1_1_serial.html#a91a00816bce6a163ea022b4cf8d4ce0e',1,'serial::Serial']]],11 ['getflowcontrol',['getFlowcontrol',['../classserial_1_1_serial.html#ad793526755625a59a0bf9d4cc0ea1755',1,'serial::Serial']]],12 ['gethealth',['getHealth',['../classydlidar_1_1_y_dlidar_driver.html#a9fe6f8b842a2aff2c3ae13f8423b03f4',1,'ydlidar::YDlidarDriver']]],13 ['getheartbeat',['getHeartBeat',['../classydlidar_1_1_y_dlidar_driver.html#a36b01c5124032be12ecbeffeefd38742',1,'ydlidar::YDlidarDriver']]],14 ['getmotorstate',['getMotorState',['../classydlidar_1_1_y_dlidar_driver.html#af5d460ababe4b8a34b02d33268f24d4d',1,'ydlidar::YDlidarDriver']]],15 ['getparity',['getParity',['../classserial_1_1_serial.html#a80e5d87b1e93b4c5a9d6f2cc7110b3c4',1,'serial::Serial']]],16 ['getport',['getPort',['../classserial_1_1_serial.html#a56eafe1694c92655d79993ce7139f0bf',1,'serial::Serial']]],17 ['getri',['getRI',['../classserial_1_1_serial.html#a29a1f68b9a238e9a6a833373855708ce',1,'serial::Serial']]],18 ['getsamplingrate',['getSamplingRate',['../classydlidar_1_1_y_dlidar_driver.html#a7b7812329013f119235abf74da397aaa',1,'ydlidar::YDlidarDriver']]],19 ['getscanfrequency',['getScanFrequency',['../classydlidar_1_1_y_dlidar_driver.html#a76efb701e137121b213f61028e3f235e',1,'ydlidar::YDlidarDriver']]],20 ['getsdkversion',['getSDKVersion',['../classydlidar_1_1_y_dlidar_driver.html#a542dc18ac8dbcda2a51657cf9bd44ae0',1,'ydlidar::YDlidarDriver']]],21 ['getstopbits',['getStopbits',['../classserial_1_1_serial.html#a81ee96ec2fdb80d1851430d9e2c4698b',1,'serial::Serial']]],22 ['gettimeout',['getTimeout',['../classserial_1_1_serial.html#a13023f118c75b27fa2f0280d2d1c2a20',1,'serial::Serial']]],23 ['grabscandata',['grabScanData',['../classydlidar_1_1_y_dlidar_driver.html#a6d6e04efa9d7e5d4aea41ee53d4ea8af',1,'ydlidar::YDlidarDriver']]]...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf');2var serial = '0123456789ABCDEF';3var device = new stf.Device(serial);4device.connect(function(error) {5 if (error) {6 console.error('Error connecting to device: ' + error);7 return;8 }9 console.log('Connected to device');10 device.startApp('com.example.myapp', function(error) {11 if (error) {12 console.error('Error starting app: ' + error);13 return;14 }15 console.log('App started');16 device.takeScreenshot(function(error, image) {17 if (error) {18 console.error('Error taking screenshot: ' + error);19 return;20 }21 console.log('Screenshot taken');22 console.log('Image size: ' + image.length);23 device.disconnect(function(error) {24 if (error) {25 console.error('Error disconnecting from device: ' + error);26 return;27 }28 console.log('Disconnected from device');29 });30 });31 });32});

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('devicefarmer-stf-client');2var client = devicefarmer.createClient({3});4client.serial(function(err, devices) {5 if (err) {6 console.error(err);7 return;8 }9 console.log(devices);10});11var client = devicefarmer.createClient({12});13client.serial(function(err, devices) {14 if (err) {15 console.error(err);16 return;17 }18 console.log(devices);19});20var devicefarmer = require('devicefarmer-stf-client');21var client = devicefarmer.createClient({22});23client.serial(function(err, devices) {24 if (err) {25 console.error(err);26 return;27 }28 console.log(devices);29});30var client = devicefarmer.createClient({31});32client.serial(function(err, devices) {33 if (err) {34 console.error(err);35 return;36 }37 console.log(devices);38});39var devicefarmer = require('devicefarmer-stf-client');40var client = devicefarmer.createClient({41});42client.serial(function(err, devices) {43 if (err) {44 console.error(err);45 return;46 }47 console.log(devices);48});49var client = devicefarmer.createClient({50});51client.serial(function(err, devices) {52 if (err) {53 console.error(err);54 return;55 }56 console.log(devices);57});58var devicefarmer = require('devicefarmer-stf-client');59var client = devicefarmer.createClient({60});61client.serial(function(err, devices) {62 if (err) {63 console.error(err);64 return;65 }66 console.log(devices);67});

Full Screen

Using AI Code Generation

copy

Full Screen

1var serial = require('devicefarmer-stf-client').serial;2serial.listDevices(function(error, devices) {3 if (error) {4 console.error(error);5 } else {6 console.log(devices);7 }8});9var device = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var SerialPort = require('serialport');2var port = new SerialPort('/dev/ttyUSB0',{baudRate: 9600});3port.on('readable', function () {4 console.log('Data:', port.read());5});6port.write('main screen turn on', function(err) {7 if (err) {8 return console.log('Error on write: ', err.message);9 }10 console.log('message written');11});12port.on('close', function () {13 console.log('port closed');14});15port.close();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devicefarmer-stf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful