小编Chr*_*ian的帖子

在C中将struct复制到struct

我想将一个相同的结构复制到另一个结构中,然后将其用作第一个结构的比较.问题是,当我这样做时,我的编译器给了我一个警告!我应该以其他方式做到这一点还是我做错了:

在标题文件中:

extern struct RTCclk
{
uint8_t second;
uint8_t minute;
uint8_t hour;
uint8_t mday;
uint8_t month;
uint8_t year;
}
RTCclk;
Run Code Online (Sandbox Code Playgroud)

在C文件中:

struct RTCclk RTCclk;
struct RTCclk RTCclkBuffert;

void FunctionDO(void)
{
   ... // Some Code
   /* Copy first struct values into the second one */
   memcpy(&RTCclk, &RTCclkBuffert, sizeof RTCclk);
}
Run Code Online (Sandbox Code Playgroud)

c struct copy microchip

61
推荐指数
3
解决办法
16万
查看次数

TickGetDiv256()如何运作?

嗨,我想知道是否有人可以举例说明该TickGetDiv256();功能是如何 工作的.它来自Tick.c中的Microchip

我试图计算2个小时,如果满载发动机将停止.

我可以使用" threshold = tick + TICKS_PER_SECOND * 60;"功能.但我不知道它是否将是很好的用于这个的时间:threshold = tick + (TICKS_PER_SECOND * 60 * 60)*2;

亲切的问候

c microcontroller microchip

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

如何获得串口设备ID?

在此程序中,我首先尝试连接到availalbe端口。找到并连接后,我想读取连接的USB设备ID和供应商ID,该怎么做?

亲切的问候

Program()
    {

        // Get a list of serial port names. 
        string[] ports = SerialPort.GetPortNames();

        // Search for the right port. 
        foreach (string port in ports)
        {
            _serialPort = new SerialPort(port, 250000, Parity.None, 8, StopBits.One);
            _serialPort.Handshake = Handshake.None;
            _serialPort.ReadTimeout = 300;
            _serialPort.WriteTimeout = 300;

            try
            {
                _serialPort.Open();
                break;
            }
            catch (Exception e)
            {
                Console.WriteLine("Serial port " + port + ": " + e.Message);
            }
        }
        /* ENTER CODE TO GET ID HERE */

        Console.WriteLine("Using: " + _serialPort.PortName);
        Console.WriteLine("Device ID: …
Run Code Online (Sandbox Code Playgroud)

c# serial-port

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

Python,将数据添加到服务器上的文件怎么样?

我每隔6秒将值附加到一个日志文件中.每30秒我将此日志作为文件传输到服务器.但是,我只想将收集的数据附加到我服务器上的文件中,而不是传输整个文件.我无法弄清楚如何打开服务器文件,然后附加值.我的代码到目前为止:

session = ftplib.FTP(authData[0],authData[1],authData[2])
session.cwd("//"+serverCatalog()+"//") # open server catalog
file = open(fileName(),'rb')

with open(fileName(), 'rb') as f:
     f = f.readlines()
         for line in f:
             collected = line

           # In some way open server file, write lines to it
           session.storbinary('STOR ' + fileName(), open(fileName(), 'a'), 1024)
           file.close()
           session.quit()
Run Code Online (Sandbox Code Playgroud)

相反,我是否必须打开并附加服务器文件,然后将其发回?不要问我为什么不将记录的数据直接发送到数据库;)

以上是我的问题,完全解决方案

session.cwd("//"+serverCatalog()+"//") # open server catalog
localfile = open("logfile.txt",'rb')
session.storbinary('APPE serverfile.txt', localfile)
localfile.close()
Run Code Online (Sandbox Code Playgroud)

python append ftplib

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

C#UL和>>运营商

这个含义在文字中意味着什么?

(SomeVariable * 330UL >> 10)
Run Code Online (Sandbox Code Playgroud)

是吗:SomeVariable times 3.3 shift right 10 bit ??

c# operators

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

在c中执行while循环条件

下面的两个代码snipe是​​否完全相同?

do
{
    Delay_us(1);
    status = fetchStatus();
}while(!status);
Run Code Online (Sandbox Code Playgroud)

第二个snipet - >

do
{
    Delay_us(1);
}while(status = fetchStatus(), !status);
Run Code Online (Sandbox Code Playgroud)

哪个更好?

c pic while-loop conditional-statements

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

如何将数组中的元素移动到C中的变量中

我有一个数组(用零和一个填充) - > ArrayWithContent [5] = {1,0,0,1,1}; 现在我希望将其转换为变量,以便我可以读出它的总值.

0001 0011 = 19

for(i=0; i<5; i++)
{
    OneValue = ArrayWithContent[i]; 
    Variable = OneValue;
    Variable >>= 1;             // Send the zero or one to right.... continue to fill it up
}
Run Code Online (Sandbox Code Playgroud)

显示变量的内容我现在希望它显示值19.

我知道我做错了,正确的方法是什么?指针和地址?

c arrays for-loop bit-manipulation

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

我的struct中声明的变量可以具有不同的大小

为什么我问这是因为发生了以下情况:

在标题中定义:

typedef struct PID
{
// PID parameters
uint16_t Kp; // pGain
uint16_t Ki; // iGain
uint16_t Kd; // dGain

// PID calculations OLD ONES WHERE STATICS
int24_t pTerm;
int32_t iTerm;
int32_t dTerm;
int32_t PID;

// Extra variabels
int16_t CurrentError;

// PID Time
uint16_t tick;

}_PIDObject;
Run Code Online (Sandbox Code Playgroud)

在C源:

static int16_t PIDUpdate(int16_t target, int16_t feedback)
{
      _PIDObject PID2_t;

  PID2_t.Kp = pGain2; // Has the value of 2000

      PID2_t.CurrentError = target - feedback; // Has the value of 57

      PID2_t.pTerm = PID2_t.Kp …
Run Code Online (Sandbox Code Playgroud)

c size struct pic

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

更改字符串javascript中的变量

我有一个字符串看起来像:某些+东西+ - +更多

我如何更换+号?

我试过以下没有成功:

temps = "some+thing+-+More";
temps = temps.replace("/+" /g, "blank");
temps = temps.replace("+" /g, "blank");
temps = temps.replace(/+/g, "blank");
Run Code Online (Sandbox Code Playgroud)

javascript

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

为什么我的错误指针无效?

/* DECLARED FUNCTIONS */
char *DetectDevice(void);

int main(int argc, char *argv[])
{
    char *PathToDevice;
    PathToDevice = DetectDevice();

...

    if(close(fd) == -1)
    {
        printf("Error Closing Port");
    }else
    {
        printf("whihi!");
        free(PathToDevice);
    }

    return 0;
}

char *DetectDevice(void)
{   
    char *Usbs = malloc(1024);
    Usbs = "/dev/ttyUSB1";
    return Usbs;
}
Run Code Online (Sandbox Code Playgroud)

错误消息:*glibc检测到* ./test:free():无效指针:0xbec1b504

顺便说一下...这个程序是在覆盆子pi上编译的!

c linux gcc

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

C#服务作为debian中的守护进程,具有单一服务

我似乎无法找到一种方法让一个C#服务作为debian中的"服务"运行.我究竟做错了什么?

我跟着这个帖子从MSDN创建一个样本窗口服务:http://msdn.microsoft.com/en-us/library/zt39148a(v=vs.80).aspx

我可以在我的Windows机器上运行该服务,启动和停止服务,并看到它写入MyNewLog.

然后我将它(.exe文件)复制到我的debian机器并尝试使用(作为root)mono-service MyNewService.exe运行它

Syslog告诉我,服务已经开始了!

我没有错误,我在系统中看不到任何新创建的日志文件.我究竟做错了什么?

如果有帮助,这里是代码:Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;

namespace MyNewService
{
static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main()
    {
        System.ServiceProcess.ServiceBase[] ServicesToRun;
        ServicesToRun = new System.ServiceProcess.ServiceBase[]
        { 
            new MyNewService() 
        };
        System.ServiceProcess.ServiceBase.Run(ServicesToRun);
    }
}
}
Run Code Online (Sandbox Code Playgroud)

Service.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;

namespace MyNewService
{
public partial class MyNewService …
Run Code Online (Sandbox Code Playgroud)

c# mono service debian daemon

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