Delphi 之前解析串口数据
//串口接收数据
procedure TfrmClientMain.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
i:integer;
ss,ffnn:string;
rbuf:array of byte;
begin
//setlength(rbuf,0);
memo1.Lines.Add('长度:'+inttostr(bufferlength));
setlength(rbuf,BufferLength);
move(buffer^,pchar(rbuf)^,BufferLength);
ss:='接收:';
for i:=0 to bufferlength-1 do
begin
ss:=ss+inttohex(rbuf[i],2)+' '; //接受数据
//showmessage(ss);
end;
memo1.Lines.Add(ss);
//showmessage(inttohex(rbuf[1],1));
if inttohex(rbuf[1],2)='43' then
begin
DataStream:=TMemoryStream.Create;
DataAll:=0;
PkAll:=0;
PkNo:=0;
RadioNo1:='';
SayAddr; //发送读收音机编号命令
end;
if inttohex(rbuf[1],2)='A1' then
begin
GetRadioNo(rbuf); //读收音机编号
SayDataAll; //发送读数据总量命令
end;
if inttohex(rbuf[1],2)='A4' then
begin
GetDataAll(rbuf); //读数据总量
if dataall=0 then
begin
memo1.Lines.Add('卡的内容为空,请拔卡!');
end else
begin
SayPkNo; //发送第0个数据包号
end;
end;
if inttohex(rbuf[1],2)='D4' then
begin
GetPk(rbuf); //接收数据包
if PkNo=PkAll then //当最后一个包接收完毕
begin
memo1.Lines.Add('总数据量:'+inttostr(DataAll)+'流的大小:'+inttostr(datastream.size));
if DataAll=DataStream.Size then
begin
ffnn:=SaveFileName;
DataStream.SaveToFile(SourceFileDir+ffnn); //写文件
DataStream.Free;
AScanSThread:=TScanSThread.CreateIt(ffnn);
//SayFormat; //发送格式化命令
end else
begin
DataStream:=TMemoryStream.Create;
DataAll:=0;
PkAll:=0;
PkNo:=0;
RadioNo1:='';
SayAddr; //重新在进行一遍
end;
end else
begin
SayPkNo; //发送读取下一个包命令
end;
end;
end;
procedure TfrmClientMain.GetRadioNo(buf:array of byte);
var
i:integer;
begin
RadioNo1:=BytetoStrings(buf[2])+BytetoStrings(buf[3])+BytetoStrings(buf[4])+BytetoStrings(buf[5]);
memo1.Lines.Add('收音机编号:'+RadioNo1);
end;
procedure TfrmClientMain.SayDataAll;
var
sbuf:array[1..7] of byte;
begin
sbuf[1]:=byte($35);
sbuf[2]:=byte($A4); {命令号}
sbuf[3]:=byte($00);
sbuf[4]:=byte($00);
sbuf[5]:=byte($00);
sbuf[6]:=byte($00);
sbuf[7]:=byte($58);
senddata(sbuf);{调用发送函数}
end;
procedure TfrmClientMain.GetDataAll(buf:array of byte); //取得数据
var
s:string;
begin
//showmessage('###@@@!!!:'+inttohex(buf[3],2));
s:=inttohex(buf[2],2)+inttohex(buf[3],2);//+inttohex(buf[4],2); 根据090810ctc-r-100新协议修改
DataAll:=strtoint(HexStrToDecStr(s));
memo1.Lines.Add('数据总量:'+inttostr(dataall));
if (dataall mod 128)=0 then
begin
pkall:=DataAll div 128;
end else
begin
pkall:=DataAll div 128+1;
end;
memo1.Lines.Add('包数:'+inttostr(pkall));
end;
Delphi 之前解析串口数据的更多相关文章
- delphi XE3解析JSON数据
测试数据如下: Memo1.text中的数据: { "date":"周二(今天, 实时:12℃)", "dayPictureUrl":&qu ...
- Delphi中使用ISuperObject解析Json数据
Java.Php等语言中都有成熟的框架来解析Json数据,可以让我们使用很少的代码就把格式化好的json数据转换成程序可识别的对象或者属性,同时delphi中也有这样的组件来实现此功能,即Isuper ...
- python 3下对stm32串口数据做解析
1.最近有个想做一个传感器数据实时显示的上位机,常规的数据打印太频繁了,无法直观的看出数据的变化. python下的上位机实现起来简单一点,网上找了一些python界面Tkinter相关资料和pyth ...
- python 下串口数据的读取,解析,和保存-
#!/usr/bin/python # -*-coding: utf-8 -*- import serial import threading import binascii from datetim ...
- 教程-Delphi MSComm 实时串口通讯
Delphi MSComm 实时串口通讯 MSComm控件具有丰富的与串口通信密切相关的属性,提供了对串口进行的多种操作,进而使串行通信变得十分简便.MSComm的控件属性较多,常用的属性如下:1) ...
- C# ---- 串口数据YSI实例
原文:C# ---- 串口数据YSI实例 C#----串口数据接收发送中,发送接收数据已经可以模拟了. 本次YSI实例过程中 主要是:类型转换问题 .计算校验码 一.不同设备不同的规则,本次实例代码如 ...
- jQuey知识点三 解析json数据
1.解析简单数据 @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="vie ...
- C#SerialPort如何读取串口数据并显示在TextBox上
SerialPort中串口数据的读取与写入有较大的不同.由于串口不知道数据何时到达,因此有两种方法可以实现串口数据的读取.一.线程实时读串口:二.事件触发方式实现. 由于线程实时读串口的效率不是十分高 ...
- Android(Linux)实时监控串口数据
之前在做WinCE车载方案时,曾做过一个小工具TraceMonitor,用于显示WinCE系统上应用程序的调试信息,特别是在实车调试时,用于监控和显示CAN盒与主机之间的串口数据.因为需要抢占市场先机 ...
随机推荐
- 如何用crontab运行一个图形化界面的程序
crontab是linux中定时任务的 执行crontab -e可以编辑定时列表(export DISPLAY=:0 指定显示器或者export DISPLAY=localhost:0) 15 13 ...
- LAMP环境搭建教程
原文:LAMP环境搭建教程 学习PHP脚本编程语言之前,必须先搭建并熟悉开发环境,开发环境有很多种,例如LAMP.WAMP.MAMP等.这里我介绍一下LAMP环境的搭建,即Linux.Apache.M ...
- MyBatis实现SaveOrUpdate
这篇文章主要讲如何通过xml方式实现SaveOrUpdate,但是仍然建议在Service中实现. 例子 <insert id="saveOrUpdate" > < ...
- php set_include_path
string set_include_path ( string $new_include_path ) 为当前脚本设置 include_path 运行时的配置选项. Example #2 添加到in ...
- poj 1325 Machine Schedule 二分匹配,可以用最大流来做
题目大意:机器调度问题,同一个任务可以在A,B两台不同的机器上以不同的模式完成.机器的初始模式是mode_0,但从任何模式改变成另一个模式需要重启机器.求完成所有工作所需最少重启次数. ======= ...
- echo "hello" | nc -4t -w1 localhost 8001
TCP4: echo "hello" | nc -4t -w1 localhost 8001 UDP4: echo "hello" | nc -4u -w1 l ...
- 《c程序设计语言》读书笔记--首次输入不能是空符;最多10个字符
#include <stdio.h> #define Num 10 int main() { int wor = 0; int arr[Num] = {0}; int c,count = ...
- dataguru试听课程
http://www.dataguru.cn/article-5447-1.html#userconsent#
- find a filename from a filehandle in Perl
my $filename='/tmp/tmp.txt';open my $fh, '>', $filename;my $fd = fileno $fh;print readlink(" ...
- MSAA, UIA brief explanation
MSAA, UIA brief explanation 2014-07-24 Reference [1] MSAA, UIA brief explanation [2] Testing Tools [ ...