How to use openPort method in wpt

Best JavaScript code snippet using wpt

device.ts

Source:device.ts Github

copy

Full Screen

1import { RawData } from '@waiting/idcard-reader-base'2import { error, info } from '@waiting/log'3import { dirname } from '@waiting/shared-core'4import { of, range, timer, Observable } from 'rxjs'5import {6 concatMap,7 defaultIfEmpty,8 filter,9 map,10 mergeMap,11 take,12 tap,13 timeout,14} from 'rxjs/operators'15import { Device } from './model'16export function connectDevice(device: Device, port: number): number {17 if (device && device.inUse) {18 device.deviceOpts.debug && info('Cautiton: connectDevice() device in use')19 return 020 }21 const openRet = device.apib.SDT_OpenPort(port)22 device.deviceOpts.debug && info(`open device port ret: ${openRet}`)23 return openRet === 144 ? port : 024}25export function disconnectDevice(device: Device): boolean {26 const ret = device.apib.SDT_ClosePort(device.openPort)27 device.deviceOpts.debug && info(`disconnectDevice at port: ${device.openPort}, ret: ${ret} `)28 device.inUse = false29 return ret === 14430}31export function resetDevice(device: Device, port?: number): void {32 if (port && port > 0) {33 const ret = device.apib.SDT_ResetSAM(port, 0)34 info(`reset ${port} ret: ${ret}`)35 }36 else {37 for (let i = 1; i <= 16; i += 1) {38 const ret = device.apib.SDT_ResetSAM(i, 0)39 info(`reset ${i} ret: ${ret}`)40 }41 for (let i = 1001; i <= 1016; i += 1) {42 const ret = device.apib.SDT_ResetSAM(i, 0)43 info(`reset ${i} ret: ${ret}`)44 }45 }46 device.deviceOpts.debug && info(`reset device at port: ${device.openPort}`)47 device.inUse = false48}49export function findDeviceList(50 deviceOpts: Device['deviceOpts'],51 compositeOpts: Device['compositeOpts'],52 apib: Device['apib'],53): Device[] {54 const arr: Device[] = []55 if (deviceOpts.port > 0) {56 // 仅USB接口57 const device = findDevice(deviceOpts.port, deviceOpts, compositeOpts, apib, true)58 if (device.openPort > 0) {59 arr.push(device)60 }61 }62 else {63 // 必须先检测usb端口64 for (let i = 1001; i <= 1016; i += 1) {65 const device = findDevice(i, deviceOpts, compositeOpts, apib, true)66 if (device.openPort > 0) {67 // device.simid = getSamid(device)68 arr.push(device)69 if (! deviceOpts.searchAll) {70 break71 }72 }73 }74 if (! deviceOpts.searchAll && arr.length) {75 return arr76 }77 // 检测串口78 for (let i = 1; i <= 16; i += 1) {79 const device = findDevice(i, deviceOpts, compositeOpts, apib, false)80 if (device.openPort > 0) {81 arr.push(device)82 if (! deviceOpts.searchAll) {83 break84 }85 }86 }87 }88 return arr89}90export function findDevice(91 openPort: Device['openPort'],92 deviceOpts: Device['deviceOpts'],93 compositeOpts: Device['compositeOpts'],94 apib: Device['apib'],95 useUsb: Device['useUsb'],96): Device {97 const device: Device = {98 apib,99 apii: null,100 deviceOpts,101 compositeOpts,102 inUse: false,103 openPort: 0,104 useUsb,105 }106 const port = connectDevice(device, openPort)107 if (port > 0) {108 device.inUse = true109 device.openPort = port110 deviceOpts.debug && info(`Found device at serial/usb port: ${port}`)111 disconnectDevice(device)112 }113 return device114}115/** 读取二代证基础信息 */116export function readDataBase(device: Device): Observable<RawData> {117 const path = dirname(device.deviceOpts.dllTxt)118 process.env.PATH = `${process.env.PATH};${path}`119 // const srcDir = path.replace(/\\/g, '/') + '/'120 // const targetPath = normalize(device.deviceOpts.imgSaveDir + '/').replace(/\\/g, '/')121 if (device.deviceOpts.debug) {122 info('starting reading readCard ')123 // info('IDCard_GetInformation() src path:' + srcDir)124 // info('IDCard_GetInformation() target path:' + targetPath)125 }126 const open = connectDevice(device, device.openPort)127 if (! open) {128 throw new Error(`打开端口失败 readDataBase() port: ${device.openPort}`)129 }130 const cardReady$ = findCard(device).pipe(131 mergeMap((found) => {132 if (found) {133 return of(selectCard(device)).pipe(134 timeout(1500),135 )136 }137 else {138 throw new Error('findCard() 未能找到指定设备')139 }140 }),141 tap((ready) => {142 if (! ready) {143 throw new Error('二代证无效,请确保证件处于机具读卡区域内')144 }145 }),146 )147 const ret$ = cardReady$.pipe(148 map(() => readCard(device)),149 tap((raw) => {150 if (device.deviceOpts.debug) {151 // info(`readDataBase bufLen: ${buf.byteLength}`)152 info('readDataBase ret')153 info(raw)154 }155 }),156 )157 return ret$158}159/** 检测卡是否可读取状态 */160export function findCard(device: Device): Observable<boolean> {161 const { findCardRetryTimes } = device.deviceOpts162 const findRet$ = range(0, findCardRetryTimes > 0 ? findCardRetryTimes + 1 : 1).pipe(163 concatMap((_, index: number) => {164 if (index > 0 && index >= findCardRetryTimes) {165 throw new Error(`findCard fail over ${findCardRetryTimes} times`)166 }167 // 移动中读取到卡 延迟执行选卡168 const delay$ = timer(index === 0 ? 0 : 1000)169 return delay$.pipe(170 mergeMap(() => of(_findCard(device))),171 )172 }),173 )174 const ret$ = findRet$.pipe(175 tap((ret) => {176 device.deviceOpts.debug && info(`findStatus: ${ret}`)177 }),178 filter(ret => ret === 159),179 take(1),180 defaultIfEmpty(0),181 map(ret => ret > 0),182 )183 return ret$184}185function _findCard(device: Device): number {186 try {187 const buf = Buffer.alloc(4)188 return device.apib.SDT_StartFindIDCard(device.openPort, buf, 1)189 }190 catch (ex) {191 device.deviceOpts.debug && error(ex)192 return 0193 }194}195/** 选卡 */196export function selectCard(device: Device): boolean {197 const buf = Buffer.alloc(4)198 const res = device.apib.SDT_SelectIDCard(device.openPort, buf, 1)199 return res === 144200}201function readCard(device: Device): RawData {202 const opts = {203 pucCHMsg: Buffer.alloc(1024), // 文字信息204 puiCHMsgLen: Buffer.from([1024]), // 文字信息长度205 pucPHMsg: Buffer.alloc(1024), // 照片信息206 puiPHMsgLen: Buffer.from([1024]), // 照片信息长度207 }208 // console.log(opts)209 const data: RawData = {210 err: 1,211 code: 0,212 text: opts.pucCHMsg,213 image: opts.pucPHMsg,214 imagePath: '',215 }216 try {217 data.code = device.apib.SDT_ReadBaseMsg(218 device.openPort,219 opts.pucCHMsg,220 opts.puiCHMsgLen,221 opts.pucPHMsg,222 opts.puiPHMsgLen,223 1,224 )225 }226 catch (ex) {227 console.error(ex)228 }229 if (data.code === 144) {230 data.err = 0231 }232 else {233 resetDevice(device, device.openPort)234 }235 return data236}237export function getSamid(device: Device): string {238 const buf = Buffer.alloc(128)239 const res = device.apib.SDT_GetSAMIDToStr(device.openPort, buf, 1)240 let samid = ''241 if (res === 144) {242 samid = buf.toString('utf8')243 const pos = samid.indexOf('\0')244 if (pos >= 0) {245 samid = samid.slice(0, pos)246 }247 }248 return samid...

Full Screen

Full Screen

xnuke.js

Source:xnuke.js Github

copy

Full Screen

...79 hasRootAccess = true80 break81 case 1:82 if (tools.brutessh.given) {83 await tools.brutessh.openPort(strHostName)84 await ns.nuke(strHostName)85 hasRootAccess = true86 }87 break88 case 2:89 if (tools.brutessh.given && tools.ftpcrack.given) {90 await tools.brutessh.openPort(strHostName)91 await tools.ftpcrack.openPort(strHostName)92 await ns.nuke(strHostName)93 hasRootAccess = true94 }95 break96 case 3:97 if (tools.brutessh.given && tools.ftpcrack.given && tools.relaysmtp.given) {98 await tools.brutessh.openPort(strHostName)99 await tools.ftpcrack.openPort(strHostName)100 await tools.relaysmtp.openPort(strHostName)101 await ns.nuke(strHostName)102 hasRootAccess = true103 }104 break105 case 4:106 if (tools.brutessh.given && tools.ftpcrack.given && tools.relaysmtp.given && tools.httpworm.given) {107 await tools.brutessh.openPort(strHostName)108 await tools.ftpcrack.openPort(strHostName)109 await tools.relaysmtp.openPort(strHostName)110 await tools.httpworm.openPort(strHostName)111 await ns.nuke(strHostName);112 hasRootAccess = true113 }114 break115 case 5:116 if (tools.brutessh.given && tools.ftpcrack.given && tools.relaysmtp.given && tools.httpworm.given && tools.sqlinject) {117 await tools.brutessh.openPort(strHostName)118 await tools.ftpcrack.openPort(strHostName)119 await tools.relaysmtp.openPort(strHostName)120 await tools.httpworm.openPort(strHostName)121 await tools.sqlinject.openPort(strHostName)122 await ns.nuke(strHostName)123 hasRootAccess = true124 }125 break126 }127 }128 return hasRootAccess;...

Full Screen

Full Screen

openport_vx.x.x.js

Source:openport_vx.x.x.js Github

copy

Full Screen

1// flow-typed signature: d40417572655088a63bb2f7963fbef7a2// flow-typed version: <<STUB>>/openport_v^0.0.5/flow_v0.77.03/**4 * This is an autogenerated libdef stub for:5 *6 * 'openport'7 *8 * Fill this stub out by replacing all the `any` types.9 *10 * Once filled out, we encourage you to share your work with the11 * community by sending a pull request to:12 * https://github.com/flowtype/flow-typed13 */14declare module 'openport' {15 declare module.exports: any;16}17/**18 * We include stubs for each file inside this npm package in case you need to19 * require those files directly. Feel free to delete any files that aren't20 * needed.21 */22declare module 'openport/openport' {23 declare module.exports: any;24}25declare module 'openport/test/openportTest' {26 declare module.exports: any;27}28// Filename aliases29declare module 'openport/openport.js' {30 declare module.exports: $Exports<'openport/openport'>;31}32declare module 'openport/test/openportTest.js' {33 declare module.exports: $Exports<'openport/test/openportTest'>;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.openPort(8080);3var wpt = require('wpt');4wpt.closePort();5var wpt = require('wpt');6wpt.getLocations(function (error, data) {7 if (error) {8 console.log(error);9 } else {10 console.log(data);11 }12});13var wpt = require('wpt');14wpt.getTesters(function (error, data) {15 if (error) {16 console.log(error);17 } else {18 console.log(data);19 }20});21var wpt = require('wpt');22wpt.getTesters(function (error, data) {23 if (error) {24 console.log(error);25 } else {26 console.log(data);27 }28});29var wpt = require('wpt');30wpt.getTesters(function (error, data) {31 if (error) {32 console.log(error);33 } else {34 console.log(data);35 }36});37var wpt = require('wpt');38wpt.getTesters(function (error, data) {39 if (error) {40 console.log(error);41 } else {42 console.log(data);43 }44});45var wpt = require('wpt');46wpt.getTesters(function (error, data) {47 if (error) {48 console.log(error);49 } else {50 console.log(data);51 }52});53var wpt = require('wpt');54wpt.getTesters(function (error, data) {55 if (error) {56 console.log(error);57 } else {58 console.log(data);59 }60});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');3 if (err) return console.error(err);4 console.log(data);5});6var wpt = require('webpagetest');7var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');8 if (err) return console.error(err);9 console.log(data);10});11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');13 if (err) return console.error(err);14 console.log(data);15});16var wpt = require('webpagetest');17var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');18 if (err) return console.error(err);19 console.log(data);20});21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');23 if (err) return console.error(err);24 console.log(data);25});26var wpt = require('webpagetest');27var wpt = new WebPageTest('www

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2wptoolkit.openPort('COM3', function(err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2 if (err) {3 console.log('Error: ' + err);4 } else {5 console.log(result);6 }7});8var request = require('request');9exports.openPort = function(url, callback) {10 var options = {11 qs: {12 },13 headers: {14 }15 };16 request(options, function(err, res, body) {17 if (err) {18 callback(err);19 } else {20 var data = JSON.parse(body);21 var result = data.data.runs[1].firstView;22 callback(null, result);23 }24 });25};26{

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wp = new wptools();3wp.openPort(function(err, port) {4 if(err) {5 console.log('error: ', err);6 } else {7 console.log('port: ', port);8 }9});10var wptools = require('wptools');11var wp = new wptools();12wp.closePort(function(err, port) {13 if(err) {14 console.log('error: ', err);15 } else {16 console.log('port: ', port);17 }18});19var wptools = require('wptools');20var wp = new wptools();21wp.isPortOpen(function(err, port) {22 if(err) {23 console.log('error: ', err);24 } else {25 console.log('port: ', port);26 }27});28var wptools = require('wptools');29var wp = new wptools();30wp.getPort(function(err, port) {31 if(err) {32 console.log('error: ', err);33 } else {34 console.log('port: ', port);35 }36});37var wptools = require('wptools');38var wp = new wptools();39wp.getPort(function(err, port) {40 if(err) {41 console.log('error: ', err);42 } else {43 console.log('port: ', port);44 }45});46var wptools = require('wptools');47var wp = new wptools();48wp.getPort(function(err, port) {49 if(err) {50 console.log('error: ', err);51 } else {52 console.log('port: ', port);53 }54});55var wptools = require('wptools');56var wp = new wptools();57wp.getPort(function(err, port) {58 if(err) {59 console.log('error: ', err);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2wptoolkit.openPort('COM3', function(err, data) {3 if (err) {4 console.log('Error opening port: ', err);5 } else {6 console.log('Port opened: ', data);7 }8});9openPort(portName, callback)10var wptoolkit = require('wptoolkit');11wptoolkit.openPort('COM3', function(err, data) {12 if (err) {13 console.log('Error opening port: ', err);14 } else {15 console.log('Port opened: ', data);16 }17});18var wptoolkit = require('wptoolkit');19wptoolkit.openPort('COM3', function(err, data) {20 if (err) {21 console.log('Error opening port: ', err);22 } else {23 console.log('Port opened: ',

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.openPort(function(err, data){4 if(err){5 console.log('error', err);6 } else {7 console.log('data', data);8 }9});10error { [Error: connect ECONNREFUSED] code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect' }11error { [Error: connect ECONNREFUSED] code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect'

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 wpt 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