谢谢大家的回复,楼上朋友的方法对于量程是固定的变量来说,无疑是非常合适的,但是我这里忘了说,我这些变量的量程是需要在画面上来设定的,也就是说要做成通用型的,客户按照实际接的模拟量类型,需要在画面上修改量程。这个项目的目的是做成通用型的,而不是专用的项目型,所以变量的地址等都要求很灵活,给用户权限来更改。
用脚本来计算最终的输出值,同样,用脚本来判断这个输出值是否超出设定值,即是否有报警发生(报警变量,BIT型),这样,模拟量报警就变成了位报警了。更容易处理了。
谢谢大家的指导,目前这个功能在全局脚本中已经实现,代码共享如下:inti;char*cTagname[8]={"AI0-Test","AI1-Test","AI2-Test","AI3-Test","AI4-Test","AI5-Test","AI6-Test","AI7-Test"};char*cHRange[8]={"AI_CH0_HRange","AI_CH1_HRange","AI_CH2_HRange","AI_CH3_HRange","AI_CH4_HRange","AI_CH5_HRange","AI_CH6_HRange","AI_CH7_HRange"};char*cLRange[8]={"AI_CH0_LRange","AI_CH1_LRange","AI_CH2_LRange","AI_CH3_LRange","AI_CH4_LRange","AI_CH5_LRange","AI_CH6_LRange","AI_CH7_LRange"};char*cTagConverted[8]={"AI_CH0_Converted","AI_CH1_Converted","AI_CH2_Converted","AI_CH3_Converted","AI_CH4_Converted","AI_CH5_Converted","AI_CH6_Converted","AI_CH7_Converted"};floatAI[8],HiRange[8],LoRange[8],AIConverted[8];for(i=0;i<=7;i++){AI[i]=GetTagFloat(cTagname[i]);HiRange[i]=GetTagFloat(cHRange[i]);LoRange[i]=GetTagFloat(cLRange[i]);AIConverted[i]=(AI[i]/27648)*(HiRange[i]-LoRange[i])+LoRange[i];SetTagFloat(cTagConverted[i],AIConverted[i]);}return0;