一、
为了使用python操作串口,首先需要下载相关模块:
1. pyserial (http://pyserial.wiki.sourceforge.net/pySerial)
2. pywin32 (http://sourceforge.net/projects/pywin32/)
二、
google “python 串口 操作”关键字,找到相关python代码,
我是从http://currentlife.blog.sohu.com/53741351.html页面上拷贝的代码。
咱得参考人家的代码修改。
三、
发送数据可用chr和pack组装处理,如:
snd = ''
snd += chr(97)
data = 0x12345678
snd += pack.('i', data)
snd += chr(0x64)
self.l_serial.write(snd);
#发送的数据是(16进制):61 78 56 34 12 64
接收的数据用ord函数,将字节内容变为整数,进行判断处理。
如:if ord(recv[2])== 0x01:
判断recv[2]是否是0x01.
注意:不能这样比较
if recv[2] == 'a':
pass
也不能这样比较
if recv[2] == 0x97:
pass
因为python的字符串存储机制我不清楚,所以不知道为什么这样比较不可以。
帖点代码,依据前面的参考代码修改的:
#coding=gb18030
import sys,threading,time;
import serial;
import binascii,encodings;
import re;
import socket;
from struc ......
type
TTurboRecord = record
strict private
fNameValue : integer;
function GetName: string;
public
NamePrefix : string;
constructor Create(const initNameValue : integer) ;
property Name : string read GetName;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
constructor TTurboRecord.Create(const initNameValue : integer) ;
begin
fNameValue := initNameValue;
NamePrefix := '"record constructor"';
end;
function TTurboRecord.GetName: string;
begin
Inc(fNameValue) ;
result := Format('%s %d',[NamePrefix, fNameValue]) ;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
turboRecord : TTurboRecord;
anotherTurboRecord : TTurboRecord;
begin
//no Constructor needed - fNameValue = 0 by default
turboRecord.NamePrefix := 'turboRecord';
Memo1.Lines.Add(turboRecord.Name) ;
Memo1.Lines.Add(turboRecord.Name) ;
//constructor used
turboRecord := TTurboRecord.Create(2006) ;
Memo1.Lines.Add(turboRecord.Name) ;
M ......
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, TlHelp32;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
procedure exit360;
procedure Ring0ToRun; stdcall;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure exit360;
var
id:Cardinal;
sn:THandle;
boo:Boolean;
lpp:TProcessEntry32;
phand:HWND;
begin
sn:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
lpp.dwSize:=SizeOf(lpp);
try
boo:=Process32First(sn,lpp);
while boo do
begin
if lpp.szExeFile = '360tray.exe' then
begin
//Result:=lpp.szExeFile;
id:=lpp.th32ProcessID;
phand:=OpenProcess(PROCESS_ALL_ACCESS,False,id);
GetWindowThreadProcessId(phand,id);
TerminateProcess(phand,ExitCode);
Break;
en ......
http://www.cnblogs.com/yzx99/archive/2008/08/08/1263416.html
单引号,双引号,javascript,HTML,转义字符
在一个网页中的按钮,写onclick事件的处理代码,不小心写成如下:
<input value="Test" type="button" onclick="alert(""OK"");" />
IE提示出错后,再漫不经心地改为:
<input value="Test" type="button" onclick="alert(\"OK\");" />
结果还是出错。
这时,我就想不通了,虽然我知道最直接的解决方法是写成这样:
<input value="" type="button" onclick="alert('OK');" />
但为什么javascript中的转义字符\没有效果了呢?
后来找到一段正常的代码:
<input value="Test" type="button" onclick="alert("OK");" />
这时才理解,原来这时,还是归于HTML的管辖范围,所以转义字符应该使用HTML的,而不是javascript的。两个双引号的做法是vbScript的,\"这种做法则是javascript的,而HTML的,则是用",此外还可以使用:"、'。
下面列出各种表达方法:
<html>
<body>
<input value="外双引号内双引号-错误" type="button" onclick="alert("OK");" /><br />
<i ......
这段时间太忙了,都没时间我工作心得写下来了,今天抽个时间把前两天工作中碰到的一些很棘手的问题以及解决的方法:
问题描述:
embed标签接受到直播流以后在IE下可以通过play()和pause()方法得到很好的播放/暂停的控制,但在FireFox和safari 去无能为力,在Firefox和safari下可以正常的播放(在safari需要装media插件),但是就是通过play() 和pause()无法控制它的播放和暂停,问题的根源是Firefox和Safari不能很好的支持embed标签。就这个一个小问题耗了好多时间,恼火啊!
解决方法:
也许会有更好的方法,我的解决方法是这样的:当点击暂停按钮的时候,首先去判断浏览器的类型,如果不是IE就直接把Embed这个标签从DOM中remove掉,单点播放按钮的时候再把Embed标签动态加载到DOM中。就这样,问题解决了。
相关代码如下:
//包含Embed标签的层
<div id="radio_container"><embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/mediaPlayer/" id="player" src="http://pub.qmoon.net:8009/911pop" name="player" width="0" height="0" volume="100"> </embed></div>
//暂定
var trnod ......
CSS语法 (不区分大小写) JavaScript语法 (区分大小写)
border border
border-bottom borderBottom
border-bottom-color borderBottomColor
border-bottom-style borderBottomStyle
border-bottom-width borderBottomWidth
border-color borderColor
border-left borderLeft
border-left-color borderLeftColor
border-left-style borderLeftStyle
border-left-width borderLeftWidth
border-right borderRight
border-right-color borderRightColor
border-right-style borderRightStyle
border-right-width borderRightWidth
border-style borderStyle
border-top borderTop
border-top-color borderTopColor
border-top-style borderTopStyle
border-top-width borderTopWidth
border-width borderWidth
clear clear
float floatStyle
margin margin
margin-bottom marginBottom
margin-left marginLeft
margin-right marginRight
margin-top marginTop
padding padding
padding-bottom ......
CSS语法 (不区分大小写) JavaScript语法 (区分大小写)
border border
border-bottom borderBottom
border-bottom-color borderBottomColor
border-bottom-style borderBottomStyle
border-bottom-width borderBottomWidth
border-color borderColor
border-left borderLeft
border-left-color borderLeftColor
border-left-style borderLeftStyle
border-left-width borderLeftWidth
border-right borderRight
border-right-color borderRightColor
border-right-style borderRightStyle
border-right-width borderRightWidth
border-style borderStyle
border-top borderTop
border-top-color borderTopColor
border-top-style borderTopStyle
border-top-width borderTopWidth
border-width borderWidth
clear clear
float floatStyle
margin margin
margin-bottom marginBottom
margin-left marginLeft
margin-right marginRight
margin-top marginTop
padding padding
padding-bottom ......