使用线程读取采集卡数据,为何不能随所采集设备的信息变化而变化? 本帖最后由 liuhuan992 于 2009-08-08 16:03:50 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 此处为thread部分代码主窗体部分只有三个控件,一个是BUTTON,一个CHART,一个CHECKBOX,其中BUTTON的CLICK事件中创建了一个p8696therad的线程,procedure p8696therad.giveseries;begin form1.series1.add(strtofloat(strvalue)); ///绘图 form1.series1.RefreshSeries; end;procedure P8696therad.Execute;var deviceID:word; hdevice:integer; //设备句柄 breturnstatus:boolean; //返回状态值 readsizewords:integer; //接收字符串长度 nchannelcount:integer; //通道个数 inuserregion :array[0..1024] of word; //接收数据缓冲区数 VoltageValue:array[0..100] of Single; //将AD转换为电压值 VoltageVal:single; para:PCI8696_PARA_AD; retsizewords:integer; chStrValue:Array[0..50] of char; i:integer;begin deviceid:=0; hdevice:=pci8696_createdevice(deviceid); //创建设备 para.FirstChannel :=1; para.LastChannel :=1; para.Frequency :=1000; //1000采集频率 para.ADMode := PCI8696_ADMODE_SEQUENCE; //连续采集 para.TriggerMode := PCI8696_TRIGMODE_SOFT ; //使用内部触发, para.TriggerType := PCI8696_TRIGTYPE_EDGE; //边沿触发类型 para.TriggerDir :=PCI8696_TRIGDIR_POSITIVE; //正向触发 nchannelcount:=1; //通道数为1 para.ClockSource :=PCI8696_CLOCKSRC_IN; //内部时钟 para.GroundingMode := PCI8696_GNDMODE_SE; //模拟输入量接地方式单端 para.InputRange := PCI8696_INPUT_0_P5000mV; //模拟量使用输入范围0~5000mv para.Gains :=PCI8696_GAINS_1MULT ; //1倍增益 breturnstatus:=pci8696_initdeviceproad(hdevice,@para); if breturnstatus=false then ShowMessage('设备初始化失败!'); readsizewords:=1000 ; BRETURNSTATUS:=pci8696_startDevicePROAD(HDEVICE); if breturnstatus=false then showmessage('设备启动失败!'); form1.Chart1.Locked :=true; while form1.CheckBox1.Checked do begin pci8696_readdeviceproad_npt(hdevice,@inuserregion,readsizewords,@retsizewords); for i:=0 to retsizewords-1 do begin voltageval:=(5000.0/16384)*(inuserregion[i] XOR $2000 AND $3fff); strvalue:=format('0.00',[voltageval]); synchronize(giveseries); end; end; form1.chart1.Locked :=false; pci8696_stopdeviceproad(hdevice); pci8696_ReleaseDeviceproad(hdevice); pci8696_releasedevice(hdevice);end; 你在调试的时候,voltageval改变吗? 先谢过各位老大,此处问题我已找到,是我的 strvalue:=format('0.00',[voltageval]); 这个语句未正确使用,应为:strvalue:=formatfloat('0.00',[voltageval]);这样即可得出正确曲线. 如何用delphi连接mysql? 怎么在循環中進行刪除? 宏调用--调用另一FORM上的控件,使其动作(在线等) 请问在SQL SERVER中有没有和ORACLE中decode函数功能相同的函数? delphi7安装问题 DBGrid问题?急!!! 请问哪里有透明的label??? 关于SQL的问题 我用130如意通手机,如何在网上给全球通用户发短消息? 有谁用过Delphi的flash插件? delphi中关于treeview的使用 新做的五子棋游戏程序
主窗体部分只有三个控件,一个是BUTTON,一个CHART,一个CHECKBOX,
其中BUTTON的CLICK事件中创建了一个p8696therad的线程,
procedure p8696therad.giveseries;
begin
form1.series1.add(strtofloat(strvalue)); ///绘图
form1.series1.RefreshSeries; end;
procedure P8696therad.Execute;
var deviceID:word;
hdevice:integer; //设备句柄
breturnstatus:boolean; //返回状态值
readsizewords:integer; //接收字符串长度
nchannelcount:integer; //通道个数
inuserregion :array[0..1024] of word; //接收数据缓冲区数
VoltageValue:array[0..100] of Single; //将AD转换为电压值
VoltageVal:single;
para:PCI8696_PARA_AD;
retsizewords:integer;
chStrValue:Array[0..50] of char;
i:integer;begin
deviceid:=0;
hdevice:=pci8696_createdevice(deviceid); //创建设备
para.FirstChannel :=1;
para.LastChannel :=1;
para.Frequency :=1000; //1000采集频率
para.ADMode := PCI8696_ADMODE_SEQUENCE; //连续采集
para.TriggerMode := PCI8696_TRIGMODE_SOFT ; //使用内部触发,
para.TriggerType := PCI8696_TRIGTYPE_EDGE; //边沿触发类型
para.TriggerDir :=PCI8696_TRIGDIR_POSITIVE; //正向触发
nchannelcount:=1; //通道数为1
para.ClockSource :=PCI8696_CLOCKSRC_IN; //内部时钟
para.GroundingMode := PCI8696_GNDMODE_SE; //模拟输入量接地方式单端
para.InputRange := PCI8696_INPUT_0_P5000mV; //模拟量使用输入范围0~5000mv
para.Gains :=PCI8696_GAINS_1MULT ; //1倍增益 breturnstatus:=pci8696_initdeviceproad(hdevice,@para);
if breturnstatus=false then
ShowMessage('设备初始化失败!');
readsizewords:=1000 ;
BRETURNSTATUS:=pci8696_startDevicePROAD(HDEVICE);
if breturnstatus=false then
showmessage('设备启动失败!');
form1.Chart1.Locked :=true;
while form1.CheckBox1.Checked do
begin
pci8696_readdeviceproad_npt(hdevice,@inuserregion,readsizewords,@retsizewords);
for i:=0 to retsizewords-1 do
begin
voltageval:=(5000.0/16384)*(inuserregion[i] XOR $2000 AND $3fff);
strvalue:=format('0.00',[voltageval]); synchronize(giveseries);
end;
end; form1.chart1.Locked :=false;
pci8696_stopdeviceproad(hdevice);
pci8696_ReleaseDeviceproad(hdevice);
pci8696_releasedevice(hdevice);
end;
此处问题我已找到,
是我的 strvalue:=format('0.00',[voltageval]);
这个语句未正确使用,
应为:strvalue:=formatfloat('0.00',[voltageval]);
这样即可得出正确曲线.