已关闭,此问题需要details or clarity。它目前不接受回答。
**想改善这个问题吗?**通过editing this post添加详细信息并澄清问题。
21小时前关门了。
Improve this question
我试图检查一个寄存器的值,特别是一个寄存器,有22位,每个需要单独查看。寄存器编号为40321,可以是40321.01、40321.02等,具体取决于您要查找的位。我需要能够显示在屏幕上,如果其中一位已成为活动。通常每个位都是0,但是在事件期间,该位将变为1,在这种情况下,我想为每个位显示特定的消息。
我原本认为每个case都是一个不同位的switch语句是可行的,但现在我认为if语句可以检查每个位的状态,然后根据答案移动到switch语句是可行的。我还没有能够得到该计划的工作虽然所以希望有人在这里有一个建议,我应该尝试。谢谢你,谢谢!
faultRegister = tag.read("Fault Register")
switch(faultRegister) {
case 40321.00:
tag.write("Fault Description", "The fault that has occured is: \n SHORT CIRCUIT DETECTED\n Please remove power, \n check wiring before resuming.")
break;
case 40321.01:
tag.write("Fault Description", "The fault that has occured is: \n DRIVE OVER TEMPERATURE \n Please remove power, \n increase air flow, add heatsink, \n or reduce duty cycle.")
break;
case 40321.02:
tag.write("Fault Description", "The fault that has occured is: \n OVER VOLTAGE \n Please remove power, \n DC bus above drive rating, \n Output shutdown.")
break;
case 40321.03:
tag.write("Fault Description", "The fault that has occured is: \n UNDER VOLTAGE \n Please remove power, \n DC bus below minimum rating, \n check for drooping or collapsing, \n improve power source, reduce acceleration.")
break;
case 40321.04:
tag.write("Fault Description", "The fault that has occured is: \n MOTOR TEMPERATURE SENSOR \n ACTIVE \n Please remove power, \n check wiring and input voltage, \n reset and retry.")
break;
case 40321.05:
tag.write("Fault Description", "The fault that has occured is: \n FEEDBACK ERROR OR ENCODER \n POWER ERROR \n Please remove power, \n allow drive to cool down, \n reset and retry.")
break;
case 40321.06:
tag.write("Fault Description", "The fault that has occured is: \n MOTOR PHASING ERROR \n Please remove power, \n allow drive to cool down, \n reset and retry.")
break;
case 40321.07:
tag.write("Fault Description", "The fault that has occured is: \n CURRENT OUTPUT LIMITED \n Please remove power, \n allow drive to cool down \n reset and retry.")
break;
case 40321.08:
tag.write("Fault Description", "The fault that has occured is: \n VOLTAGE OUTPUT LIMITED \n Please remove power, \n allow drive to cool down \n reset and retry.")
break;
case 40321.09:
tag.write("Fault Description", "The fault that has occured is: \n POSITIVE LIMIT SWITCH ACTIVE \n Please remove power, \n allow drive to cool down \n reset and retry.")
break;
case 40321.10:
tag.write("Fault Description", "The fault that has occured is: \n NEGATIVE LIMIT SWITCH ACTIVE \n Please remove power, \n allow drive to cool down \n reset and retry.")
break;
default:
tag.write("Fault Description", "Drive is operating without fault")
}
1条答案
按热度按时间blpfk2vs1#
您可以将数字存储在类型为
Number
的变量中,然后处理该值以找出每个位的值0/1
。一旦你有了这些信息,你就可以在处理过的信息上切换情况条件,寻址单个比特。
这里有一个演示,它将存储在
register
中的值作为22位值,并将返回一个数组,其中包含与寄存器中的位数一样多的值。一旦数组被返回,你就可以在它上面设置条件。例如,在演示中,我正在检查最高有效位是否设置为零。在这里,我使用
getIndividualBits
函数来帮助另一个函数,该函数将根据传递值中的第一个设置为1的位返回消息: