- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近开始尝试Electron和SerialPort,并在混合物中添加Angular(7+)时遇到了一点障碍。
所以这是问题所在:
我运行典型的 Angular CLI命令以生成应用程序。我将 Electron 和 Electron 重建作为dev依赖项添加。然后添加SerialPort作为依赖项。
在我的app.component.ts中-
import { Component, OnInit } from '@angular/core';
import * as SerialPort from 'serialport';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'electron-angular-serialport';
ngOnInit() {
SerialPort.list();
}
}
npm run electron-build
ERROR in ./node_modules/@serialport/bindings/lib/linux-list.js
Module not found: Error: Can't resolve 'child_process' in '/Users/22arwxpx/Documents/Coding/electron-angular-serialport/node_modules/@serialport/bindings/lib'
ERROR in ./node_modules/@serialport/bindings/lib/unix-write.js
Module not found: Error: Can't resolve 'fs' in '/Users/22arwxpx/Documents/Coding/electron-angular-serialport/node_modules/@serialport/bindings/lib'
ERROR in ./node_modules/@serialport/bindings/lib/unix-read.js
Module not found: Error: Can't resolve 'fs' in '/Users/22arwxpx/Documents/Coding/electron-angular-serialport/node_modules/@serialport/bindings/lib'
ERROR in ./node_modules/bindings/bindings.js
Module not found: Error: Can't resolve 'fs' in '/Users/22arwxpx/Documents/Coding/electron-angular-serialport/node_modules/bindings'
ERROR in ./node_modules/bindings/bindings.js
Module not found: Error: Can't resolve 'path' in '/Users/22arwxpx/Documents/Coding/electron-angular-serialport/node_modules/bindings'
ERROR in ./node_modules/@serialport/parser-byte-length/byte-length.js
Module not found: Error: Can't resolve 'stream' in '/Users/22arwxpx/Documents/Coding/electron-angular-serialport/node_modules/@serialport/parser-byte-length'
ERROR in ./node_modules/@serialport/parser-cctalk/cctalk.js
Module not found: Error: Can't resolve 'stream' in '/Users/22arwxpx/Documents/Coding/electron-angular-serialport/node_modules/@serialport/parser-cctalk'
ERROR in ./node_modules/@serialport/parser-delimiter/delimiter.js
Module not found: Error: Can't resolve 'stream' in '/Users/22arwxpx/Documents/Coding/electron-angular-serialport/node_modules/@serialport/parser-delimiter'
ERROR in ./node_modules/@serialport/parser-ready/ready.js
Module not found: Error: Can't resolve 'stream' in '/Users/22arwxpx/Documents/Coding/electron-angular-serialport/node_modules/@serialport/parser-ready'
ERROR in ./node_modules/@serialport/parser-regex/regex.js
Module not found: Error: Can't resolve 'stream' in '/Users/22arwxpx/Documents/Coding/electron-angular-serialport/node_modules/@serialport/parser-regex'
ERROR in ./node_modules/@serialport/stream/stream.js
Module not found: Error: Can't resolve 'stream' in '/Users/22arwxpx/Documents/Coding/electron-angular-serialport/node_modules/@serialport/stream'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! electron-angular-serialport@0.0.0 electron-build: `ng build --prod && electron .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the electron-angular-serialport@0.0.0 electron-build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/22arwxpx/.npm/_logs/2018-12-08T03_13_40_398Z-debug.log
最佳答案
简短答案:
npm install --save-dev @types/node
{
"compileOnSave": false,
.....
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"types": [
"node"
]
}
}
Take note of
types
andallowSyntheticDefaultImports
key.
(window as any).global = window;
import { Component } from '@angular/core';
import { } from 'electron';
import Serialport from 'serialport';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor() {
//check if platform is electron
let isElectron: boolean = window && window['process'] &&
window['process'].type;
if (isElectron) {
let serialport: typeof Serialport = window['require']('serialport');
let app: Electron.App = window['require']('electron').remote;
console.log(serialport, app, window['process']);
}
}
}
Note : You do not directly
require
orimport
native dependencies in angular. Instead we use window['require'] to require the module in our app. Theimport
statement above is just used to provide for typings information to typescript.
关于angular - 在Electron和Angular中使用SerialPort失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53679217/
我有一个 SerialPort 用于连接到虚拟 COM 端口。由于连接是持久的,我必须保留对 SerialPort 的引用,以便打开、关闭和管理端口。我还在我的类上实现了 IDisposable(不是
我正在尝试使用node.js串行端口模块在运行时获取设备的COM端口。 const SerialPort = require('serialport'); var fs = require('fs')
我目前有一个使用 VB6 代码制作的程序,该程序使用 MSCOMM 控件从串行端口拉回数据。这成功地从我的串行端口接收数据,其中连接了 Denso BHT-904B 设备。 我现在正尝试将此代码移至
从 SerialPort 对象外部看,写入缓冲区的大小以及是否已满似乎没有区别。 使用同步写入,write 方法会阻塞,直到所有数据都已发送且缓冲区为空。 使用异步写入,数据排队,程序继续运行。直到写
我正在用 C# 开发一个 .NET 4.0 WPF 应用程序,它通过 RS232 控制电机。我在退出应用程序时遇到问题,应用程序有时会在关闭端口时死锁。 在互联网上进行一些研究后,我注意到这是一个常见
这个问题的灵感来自这里的问题和答案: Passing a Command to a Comm Port Using C#'s SerialPort Class 这个问题本身回答了我遇到的一些问题,但也
假设我们有以下代码: SerialPort port = new SerialPort("COM2", 115200); port.Open(); // Thread.Sleep(5000); //
使用串行端口库的人注意到了这一点,还是只有我?我发现(非常)很少有人处于相同的情况,但我没有找到解决方案。 这是我使用 ruby serialport 得到的示例: ff d8 ff e0 00
我正在使用 Ruby 1.8.7 SerialPort gem 通过 FTDI232 USB 转串口转换器与 AVR 通信。我似乎遇到了 SerialPort 初始化新 SerialPort 的问题。
我正在开发需要与 COM 端口交互的程序。 从这个问答中学习:.NET SerialPort DataReceived event not firing , 我这样写我的代码。 namespace C
我正在监听串口 5 个字节的信息。轮询的完整答案需要 5 个字节。我的代码监听 serialport data_received 事件并检查 bytesToRead。有时,事件会触发并且 bytesT
我有一个 USB 电话连接到我的电脑上 我如何使用串口检测它所在的 COM? 最佳答案 遍历所有 COM 端口并尝试从每个端口获取一个标识。下面是一个最小的示例,应该对其进行扩展以进行更好的错误检查等
因为我是多线程应用程序的新手,所以我想在开始编写代码之前从更有经验的人那里得到一些建议... 我需要在串口事件中对串口接收到的数据进行排队,以便进一步处理。 所以我有以下事件处理程序: voi
我正在开发需要与 COM 端口交互的程序。 从这个问答中学习:.NET SerialPort DataReceived event not firing , 我这样写我的代码。 namespace C
偶尔,我的一些集成测试会因上述消息而失败。我正在使用下面的代码来准备端口。 for(int i = 0; i < 5; i++) {
我有两个设备想通过串行接口(interface)连接,但它们的连接不兼容。为了解决这个问题,我将它们都连接到我的 PC,并且我正在开发一个 C# 程序,它将 COM 端口 X 上的流量路由到 COM
我在尝试让串行端口接收正确消息时遇到了很多问题。它不断截断消息。这是我的代码,我将在代码之后尝试详细说明。 public SerialComms(SerialPort sp) { this.sp
我正在使用串行通信,我想知道是否应该保持 SerialPort 打开? 我正在创建一个命令队列,一次只会运行一个。我应该创建一个 SerialPort 并在每个命令中打开/关闭它,还是应该有另一个类来
我一直在尝试使用模块 Win32::SerialPort在 perl 5.10 (也许它与 5.14 有一些问题)。我必须向串行端口发出命令并获取它们的输出。我已经发现 write 将为我完成前面的部
我有一个 WPF 测试应用程序,用于评估基于事件的串行端口通信(与轮询串行端口)。问题是 DataReceived 事件似乎根本没有触发。 我有一个非常基本的 WPF 表单,其中包含用于用户输入的 T
我是一名优秀的程序员,十分优秀!