获取汉字的十六进制编码

public static string Str2Hex(string s)
{
string result = string.Empty;

byte[] arrByte = System.Text.Encoding.GetEncoding(“GB2312”).GetBytes(s);
for (int i = 0; i < arrByte.Length; i++)
{
result += “0x” + System.Convert.ToString(arrByte[i], 16).ToUpper() + “,”; //Convert.ToString(byte, 16)把byte转化成十六进制string
}

return result;
}

防水 超声波测距模块 一体化超声波DYP-ME007Y-TX串口输出

在淘宝“高校基地”店买了一个http://item.taobao.com/item.htm?spm=a1z0k.6846101.1130973605.d4915209.SAObbz&id=36884805726,还有一种是PWM输出,这个代码比较多,就是最普遍的发送命令,然后等待信号,再计时,用声速推算距离,但是TX输出把我搞乱了。

终于在http://forum.arduino.cc/index.php?topic=88388.5;wap2找到了答案:

#include <SoftwareSerial.h>

// TX_PIN is not used by the sensor, since that the it only transmits!
#define PING_RX_PIN 6
#define PING_TX_PIN 7

SoftwareSerial mySerial(PING_RX_PIN, PING_TX_PIN);

long inches = 0, mili = 0;
byte mybuffer[4] = {0};
byte bitpos = 0;

void setup() {
Serial.begin(9600);

mySerial.begin(9600);
}

void loop() {
bitpos = 0;
while (mySerial.available()) {
// the first byte is ALWAYS 0xFF and I’m not using the checksum (last byte)
// if your print the mySerial.read() data as HEX until it is not available, you will get several measures for the distance (FF-XX-XX-XX-FF-YY-YY-YY-FF-…). I think that is some kind of internal buffer, so I’m only considering the first 4 bytes in the sequence (which I hope that are the most recent! 😀 )
if (bitpos < 4) {
mybuffer[bitpos++] = mySerial.read();
} else break;
}
mySerial.flush(); // discard older values in the next read

mili = mybuffer[1]<<8 | mybuffer[2]; // 0x– : 0xb3b2 : 0xb1b0 : 0x–
inches = 0.0393700787 * mili;
Serial.print(“PING: “);
Serial.print(inches);
Serial.print(“in, “);
Serial.print(mili);
Serial.print(“mili”);

delay(100);
}

说明:模块每次输出一帧,含4个8位数据,帧格式为:0XFF+H_DATA+L_DATA+SUM

1、0XFF: 为一帧开始数据,用于判断。

2、H_DARA:距离数据的高8位。

3、L_DATA:距离数据的低8位。

4、SUM: 数据和用于交验。其0XFF+H_DATA+L_DATA=SUM(仅低8位)

5、H_DATA与L_DATA合成16位数据,即以毫米为单位的距离值。

注意:模块检测最小距离为30cm,在30cm内有物体,将获得不准确信号。

以上代码中没有做SUM校验

Arduino Yún与DFR0265(IO Expansion Shield for Arduino V7)不兼容解决办法

IMG_0666

如图,因为Yun的网线口比之前的板子挨着引脚近,所以V7插不上去,研究一番,决定加一层排母,垫高一些再插扩展板。最终选择

1.http://item.taobao.com/item.htm?id=20747855300 1个;

2.http://item.taobao.com/item.htm?id=20747511841 2个;

3.http://item.taobao.com/item.htm?id=20747903210 1个;

4.http://item.taobao.com/item.htm?id=20802935165 1个。

另外还想把这些排母焊到一层板子上,不过单买一个洞洞板运费不划算,回头想好了再说。

BugNet Issue Tracker域帐号配置说明

网站安装时只需要修改web.config中的数据库连接,其他不变,主要是<authentication mode=”Forms”>保持不变。bugnet

1. 用默认的admin账号登录,初始密码是password,界面上有说明,登录后可以在系统设置中修改;

2. 添加一个域帐号作为切换到域帐号登录模式后的管理员账号,新建用户,Admin->User Accounts->Create New User->User Name的格式为domain\username,具体如ccppg\mengfanyong,其他随便填,密码勾选Random Password; 继续阅读“BugNet Issue Tracker域帐号配置说明”

儿童数字出版的方向是基于物联网的智能玩具群落

目前儿童数字出版的产品使用终端,以PC、平板电脑为主,前者体验最差,平板对于孩子来说,依然是极其缺乏想象力的东西。而有着悠久历史和深度认知的儿童玩具目前还停留在石器时代,未来一定是通过物联网技术,将玩具纳入到智能网络,加上数字出版平台的内容支撑,变成全新的儿童数字出版形态。

关于一次污染维权的小道消息

先看新闻:

污染十年为何难了? 武强县一化工厂遭村民围堵

2104037696

图为村民向记者指明厂区围墙的临时排水孔。 中国环境报记者姚伊乐摄

“不要有污染的金钱,只要有尊严地活着。”河北省衡水市武强县、沧州市献县和泊头市11个村的村民将写着这些字样的纸板悬挂在简易凉棚上。 继续阅读“关于一次污染维权的小道消息”

Asp.net mvc + .net EF database first 或 model first 时如何添加验证特性

在使用Entity Framework 的Database frist或model first时,怎么在model上添加验证的特性?

因为此时的Model是是VS 工具怎么生成的,直接加attribute到modle类上是太现实也不合理。一个比较合理做法,就是用 buddy class的方式来实现。

比如有一个Model类: Movie。那我们就可以添加一个局部类文件,局部类的内容如下:

using System.ComponentModel.DataAnnotations;
namespace Movies.Models
{
    [MetadataType(typeof(MovieMetadata))]
    public partial class Movie
    {
        private class MovieMetadata  //这个类名随便起,相当于把这个类里面的东西追加给Movie,这个追加是用[MetadataType]实现的
        {
            [Required(ErrorMessage="Titles are required")]
            public string Title { get; set; }

            [Required(ErrorMessage="The Price is required.")]
            [Range(5,100,ErrorMessage ="Movies cost between $5 and $100.")]
            public decimal Price { get; set; }
        }
    }
}

通过在这个局部类文件中添加需要的验证属性就可以了。

以上内容来自http://www.cnblogs.com/ITHelper/archive/2013/01/08/2851442.html

另外,对于有文件上传的时候,还可以写一个扩展的model,比如:

public class MovieViewModel
{
[FileExtensions(Extensions = “jpg,gif,png”, ErrorMessage = “jpg,gif,png”)]
public HttpPostedFileBase CoverImageFile { get; set; }

public Movie movie { get; set; }

}

这样,在给control生成强类型view的时候就用MovieViewModel。