小编Noe*_*oel的帖子

使用strftime将python datetime转换为epoch

我有一段时间在UTC,从那里我想要自纪元以来的秒数.

我使用strftime将其转换为秒数.以2012年4月1日为例.

>>>datetime.datetime(2012,04,01,0,0).strftime('%s')
'1333234800'
Run Code Online (Sandbox Code Playgroud)

2012年4月1日UTC的纪元是1333238400但是这个上面返回1333234800,相差1小时.

所以看起来strftime正在考虑我的系统时间并在某个地方应用时区转换.我以为datetime纯粹是天真的?

我怎么能绕过那个?如果可能的话,避免导入其他库,除非标准.(我有可移植性问题).

python datetime utc strftime epoch

193
推荐指数
5
解决办法
27万
查看次数

Gnuplot - 使用png终端重新编程

我正在尝试在Gnuplot中使用带有png终端的replot.

如果我执行以下操作,我会在一个图表上得到两个图表,没有任何问题:

plot sin(x)/x
replot sin(x)
Run Code Online (Sandbox Code Playgroud)

现在,如果对png终端类型执行相同操作,则生成的png文件仅包含第一个图.

set terminal png
set output 'file.png'
plot sin(x)/x
replot sin(x)
Run Code Online (Sandbox Code Playgroud)

我在最后错过了什么来获得我的png文件中的第二个情节?

gnuplot

13
推荐指数
1
解决办法
1万
查看次数

二进制串口读取c中丢失的字节

我正在将二进制数据从 arduino 发送到运行此代码的串行端口。在十六进制模式下使用cutecom可以清楚地读取我对该串行端口的期望。如下所示。

00000000: 24 04 85 ab 47 43 04 04   24 04 85 ab 47 43 04 04 
00000010: 24 04 85 ab 47 43 04 04   24 04 85 ab 47 43 04 04 
Run Code Online (Sandbox Code Playgroud)

到这里没有问题。我不认为我需要提供 arduino 代码。

我正在尝试用 c 读同样的东西。然而下面的代码只打印这个:

24 85 ab 47 43 24 85 ab 47 43 24 85 ab 47 43
Run Code Online (Sandbox Code Playgroud)

由于某些原因,它跳过了 04。有什么想法吗?

#include <stdio.h>
#include <fcntl.h>   /* File Control Definitions           */
#include <termios.h> /* POSIX Terminal Control Definitions */
#include <unistd.h>  /* …
Run Code Online (Sandbox Code Playgroud)

c serial-port

4
推荐指数
1
解决办法
2889
查看次数

C 到 Python 管道 - 如何检测读者访问

我正在使用 C 程序写入命名管道并使用 Python 程序读取它。

如果我停止 Python 程序(阅读器),那么编写器会自行停止,尽管这是在 while(1) 循环中。为什么会发生这种情况?是无声的崩溃吗?

第二个问题,如果我想检测读取器何时断开连接,我应该怎么做。我的理想情况是检测断开连接然后继续空闲(即停止发送任何内容)并在读者回来后恢复。

下面的玩具代码。

作家 (C):

#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
  
int main()
{
    int fd;
  
    // FIFO file path
    char * myfifo = "/tmp/myfifo";
  
    // Creating the named file(FIFO)
    // mkfifo(<pathname>, <permission>)
    mkfifo(myfifo, 0666);
  
    char arr1[80];
    while (1)
    {
        // Open FIFO for write only
        fd = open(myfifo, O_WRONLY);
  
        // Take an input from user.
        fgets(arr1, 80, stdin);
  
        // Write the input on FIFO …
Run Code Online (Sandbox Code Playgroud)

c python named-pipes

1
推荐指数
1
解决办法
38
查看次数

标签 统计

c ×2

python ×2

datetime ×1

epoch ×1

gnuplot ×1

named-pipes ×1

serial-port ×1

strftime ×1

utc ×1