Electron在renderer.js中引用另一个b.js文件

1.在main.js中添加<script scr=’b.js’></script>

完成这步,在renderer.js中已经可以正常使用b.js中的变量,但是编码时无法提示

2.在renderer.js中添加 const bbbb = require(‘./b.js’)

至此,编码时的代码补全及变量提示已经正常

Linux下的C串口通信

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <unistd.h>

#define u_char unsigned char
#define u_int unsigned int
#define u_long unsigned long

#define xAppName    "rs232Cli"
#define xAppVer     "v1.0.0"

int main(int argc, char* argv[])
{
    if(argc <= 1)
    {
        printf("%s\n",xAppName);
        printf("%s\n",xAppVer);
        _exit(-1);
    }

    u_char xTTyPath[20] = { 0 };
    strcpy(xTTyPath,"/dev/");
    strcat(xTTyPath,argv[1]);
    int xSerialPort = open(xTTyPath, O_RDWR);

    printf("\033]0;%s %s - %s [115200-E-8-1]\007", xAppName, xAppVer, argv[1]);

    struct termios xTTy;
    if(tcgetattr(xSerialPort, &xTTy) != 0) {
        printf("Error %i from tcgetattr: %s\n", errno, strerror(errno));
        return 1;
    }

    //xTTy.c_cflag &= ~PARENB;      //清除奇偶校验位,禁用奇偶校验
    xTTy.c_cflag |= PARENB;         //设置校验位使能
    //xTTy.c_cflag |= PARODD;       //设置为奇检验(1)
    xTTy.c_cflag &= ~PARODD;        //设置为偶校验(0)
    xTTy.c_cflag &= ~CSTOPB;        //清除停止字段,通信中仅使用一个停止位
    xTTy.c_cflag &= ~CSIZE;         //清除所有设置数据大小的位 
    xTTy.c_cflag |= CS8;            //每字节8位
    xTTy.c_cflag &= ~CRTSCTS;       //禁用RTS/CTS硬件流控制
    xTTy.c_cflag |= CREAD | CLOCAL; //打开READ并忽略ctrl行(CLOCAL = 1)

    xTTy.c_lflag &= ~ICANON;
    xTTy.c_lflag &= ~ECHO;
    xTTy.c_lflag &= ~ECHOE;
    xTTy.c_lflag &= ~ECHONL;
    xTTy.c_lflag &= ~ISIG;
    xTTy.c_iflag &= ~(IXON | IXOFF | IXANY); //关闭s/w流量控制
    xTTy.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL); //禁用接收字节的任何特殊处理

    xTTy.c_oflag &= ~OPOST;     //防止对输出字节进行特殊解释
    xTTy.c_oflag &= ~ONLCR;     //防止换行转换为回车/换行
    //xTTy.c_oflag &= ~OXTABS;  //防止将制表符转换为空格
    //xTTy.c_oflag &= ~ONOEOT;  //阻止删除输出中的C-d字符(0x004)

    xTTy.c_cc[VTIME] = 10;      //最多等待1秒,收到任何数据后立即返回.
    xTTy.c_cc[VMIN] = 0;

    //将输入/输出波特率设置为115200
    cfsetispeed(&xTTy, B115200);
    cfsetospeed(&xTTy, B115200);

    //保存tty设置,同时检查错误
    if (tcsetattr(xSerialPort, TCSANOW, &xTTy) != 0) {
        printf("Error %i from tcsetattr: %s\n", errno, strerror(errno));
        return 1;
    }

    //写入串行端口
    unsigned char msg[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
    write(xSerialPort, msg, sizeof(msg));

    //为读取缓冲区分配内存,根据需要设置大小
    char read_buf [256];

    //通常情况下,您不会执行此memset()调用,但由于本例中我们只接收ASCII数据,因此我们将所有内容都设置为0,以便轻松调用printf().
    memset(&read_buf, '\0', sizeof(read_buf));

    //读取字节,read()的行为(例如,它会阻塞吗?阻塞多长时间?)取决于上面的配置设置,特别是VMIN和VTIME
    int num_bytes = read(xSerialPort, &read_buf, sizeof(read_buf));

    //n是读取的字节数.如果没有接收到字节,n可以是0,也可以是-1以发出错误信号.
    if (num_bytes < 0) {
        printf("Error reading: %s", strerror(errno));
        return 1;
    }

    printf("Read %i bytes. Received message: %s", num_bytes, read_buf);

    close(xSerialPort);
    return 0;
};

Electron编译时提示没有设置图标

default Electron icon is used  reason=application icon is not set

1.制作一个512x512的png文件
2.在项目的根目录下创建 build/icons 目录
3.将图标文件名改为 512x512.png 并复制到 icons 目录下
4.再次编译时就不会再提示 icon is not set 啦...
图标的推荐尺寸 : 16, 32, 48, 64, 128, 256 (or just 512)

腾讯云 对象存储(COS) 踩坑

按官方SDK指引编译运行后报错

CosClientException:
   COSXML.CosException.CosClientException:
      Error: NameResolutionFailure --->
         System.Net.WebException: Error: NameResolutionFailure

调试后发现 cosXml 中的 Appid 为 null

CosXmlConfig config = new CosXmlConfig.Builder()
             .SetAppid("appid") //←←← 在config中追加Appid
             .SetRegion("COS_REGION")
             .Build();

修改并添加Appid后上传成功

200 OK
Content-Length: 0
Connection: keep-alive
Date: Sat, 06 May 2023 00:43:47 GMT
ETag: "644a534b4052646cd8e2fg2hijklm97n"
Server: tencent-cos
x-cos-hash-crc64ecma: 9876543210987654321
x-cos-request-id: AbCdEFGhIjKlMnOpQrStUVWxYzabCDEfGHIjKlMnOPQ=
x-cos-storage-class: STANDARD

以下代码摘自官方 示例代码二: 上传二进制数据

戳这里👉 查看SDK原文
using COSXML.Model.Object;
using COSXML.Auth;
using COSXML.Transfer;
using System;
using COSXML;

namespace COSSnippet
{
    public class TransferUploadObjectModel {

      private CosXml cosXml;

      TransferUploadObjectModel() {
        CosXmlConfig config = new CosXmlConfig.Builder()
                     .SetRegion("COS_REGION")
                     .Build();

        string secretId = "SECRET_ID";
        string secretKey = "SECRET_KEY";
        long durationSecond = 600;
        QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, secretKey, durationSecond);

        this.cosXml = new CosXmlServer(config, qCloudCredentialProvider);
      }

      /// 上传二进制数据
      public void TransferUploadBytes()
      {
        try
        {
          string bucket = "examplebucket-1250000000";
          string cosPath = "exampleObject";
          byte[] data = new byte[1024];
          PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, cosPath, data);
          // 发起上传
          PutObjectResult result = cosXml.PutObject(putObjectRequest);
          Console.WriteLine(result.GetResultInfo());
        }
        catch (COSXML.CosException.CosClientException clientEx)
        { //请求失败
          Console.WriteLine("CosClientException: " + clientEx);
        }
        catch (COSXML.CosException.CosServerException serverEx)
        { //请求失败
          Console.WriteLine("CosServerException: " + serverEx.GetInfo());
        }
      }

      static void Main(string[] args)
      {
        TransferUploadObjectModel m = new TransferUploadObjectModel();

        /// 高级接口上传二进制数据
        m.TransferUploadBytes();
      }
    }
}

wp提示php各种模块未被安装

如php-gd,curl,imagick,mbstring,zip,intl……

~$ sudo apt-cache search php-gd

php-gd – GD module for PHP [default]

php8.1-gd – GD module for PHP

~$ sudo apt-get install php8.1-gd

Reading package lists… Done

Building dependency tree… Done

Reading state information… Done

……

~$ sudo systemctl restart apache2

★其它模块安装类似,搜索>安装,如法炮制,最后重启apache

~$ sudo apt-cache search curl | grep php

~$ sudo apt-get install php8.1-curl

~$ sudo apt-cache search imagick | grep php

~$ sudo apt-get install php8.1-imagick

~$ sudo apt-cache search mbstring | grep php

~$ sudo apt-get install php8.1-mbstring

~$ sudo apt-cache search zip | grep php

~$ sudo apt-get install php8.1-zip

~$ sudo apt-cache search intl | grep php

~$ sudo apt-get install php8.1-intl

WordPress踩坑⁺⁵

安装的WP发送的文章,点开后直接404……

上传图片提示wp-content没有写入权限……

后台安装插件提示未能连接到FTP服务器……

修改新安装的主题提示没有写入权限……

WP健康检查提示PHP没有gd扩展……戳这里

⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾ⁿⁱ

基于Electron的Tcp通信尝试

aaaaa

function getConnection (connName)
{
var xClient = xNet.connect(8485,’192.168.50.212′, function () {
console.log( connName + ‘Connected:’);
console.log(‘ local= %s:%’, this.localAddress, this.localPort);
console.log(‘ remote= %s:%’, this._remoteAddress, this._remoteAddress);
this.setTimeout(500);
this.setEncoding (‘hex’);
this.on(‘data’, function (data) {
console.log(connName+” From Server: ” + data.toString());
this.end ();
});
this.on(‘end’, function () {
console.log(connName + ‘Client disconnection’);
});
this.on(‘error’, function (error) {
console.log(‘Socket Error:’ + JSON.stringify(error));
});
this.on(‘timeout’, function () {
console.log(‘Socket Timed Out’);
});
this.on(‘close’, function () {
console.log(‘Socket Closed’);
});
});
return xClient;
}