我通过Simulink将双数据类型的UDP数据包发送到RaspberryPi。我想用以下代码解码UDP数据包:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace CARICAD_App.Models
{
public class repeatViewModel
{
[Display(Name = "textinput")]
public string textinput { get; set; }
}
public class CON_consultantInfoVM
{
[DisplayName("Age Range")]
public Nullable<int> ageRange { get; set; }
public int id { get; set; }
[DisplayName("Image")]
public string image { get; set; }
[DisplayName("Consultant ID")]
public string consultID { get; set; }
[DisplayName("First Name")]
[Required]
public string firstName { get; set; }
...
public REF_country REF_country { get; set; }
public REF_nationality REF_nationality { get; set; }
public List<actVm> act { get; set; }
}
public class actVm
{
public Nullable<int> id { get; set; }
public string consultID { get; set; }
public string textinput { get; set; }
public string untypedinput { get; set; }
public string dateinput { get; set; }
public string textareainput { get; set; }
public string radioinput { get; set; }
public string selectinput { get; set; }
public string activities { get; set; }
public string hisotryInput { get; set; }
public string historydateinput { get; set; }
public string hisotrydescrip { get; set; }
public string historydateinputTo { get; set; }
public string historyLead { get; set; }
public bool historyCo { get; set; }
public List<string> multipleselectinput { get; set; }
}
}
我收到以下错误:
import struct
import socket
sock = socket.socket(socket.AF_INET,socket.SOCK_GRAM)
sock.bind(("",5002))
data,addr= sock.recvfrom(1024)
struct.unpack('d','data')
print data
提前感谢您的帮助!
答案 0 :(得分:0)
您必须检查要发送的是大字节序还是小字节序。 您可以为小端数据添加“ <”,为大端数据添加“>”。 取决于您要接收多少变量,“ d”的数量也应增加。 假设您收到2 struct.unpack('<'+'d','data')