Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Convert short to binary and display alarm

Convert short to binary and display alarm 11 months 3 days ago #2358

  • tehlh
  • tehlh's Avatar
  • Offline
  • New Member
  • Posts: 6
  • Karma: 0
I am trying to display alarm via scripts in TeslaScada2. I am working with the CANbus J1939 protocol and convert to modbus rtu.

The CANbus J1939 is sending decimal (short 16) to TeslaScada2. I need to convert this short to binary. Can anyone check my scripts is it correct or not? Will it work? Is my declaration for binary correct? Below is my written scripts.


bool Y;

while (Tags.PGN65283_1 != 0) {

shorttobyte(Tags.PGN65283_1, Y);
readbool(Y);

}

if (Y == 0000000000000001) {
settagalarm("AVR Over Voltage Alarm", "hi", "1");
print("AVR Alarm - Over Voltage");

}
The administrator has disabled public write access.

Convert short to binary and display alarm 11 months 3 days ago #2359

  • fatkhrus
  • fatkhrus's Avatar
  • Offline
  • Administrator
  • Posts: 826
  • Thank you received: 123
  • Karma: -107
Hello,

That's very strange script. If you need to read bit from short value user readbit function from the library: teslascada.com/HTML/bitmap-operations.html
Don't use while operator if you're not using the same vaialble in the condition and in the body and this variable is not changed, because it could be the reason of crashing application.
And what are you trying to do with settagalarm function? If you want to turn on alarm you have to setup up in Tag properties condition when Y==1 alarm is ON.

Best regards,
Ruslan
The administrator has disabled public write access.

Convert short to binary and display alarm 11 months 3 days ago #2360

  • tehlh
  • tehlh's Avatar
  • Offline
  • New Member
  • Posts: 6
  • Karma: 0
Mr. Rusian,

Thank you for your reply. Appreciate it very much. If not using 'while' can I use 'for'?

To clarify further, from CANbus to modbus rtu the converter is sending decimal of short (16 bits) to TeslaScada. Therefore I need to convert the integer to 16 bits binary. Meaning from the integer values after converting to binary, each bit represent an alarm.

bit 1 = overvoltage alarm
bit 2 = undervoltage alarm
bit 3 = overfrequency alarm and this continue to bit 16.

In other words, I need to read each bit of the 16 bit binary and activate its respective alarm if it is '1'. In this case I am expecting the values of Y is in 16 bit binary (00000000 00000000 without alarm) and if there is alarm on bit 4 then the value will be 00000000 00000100.

The normal Tag properties cannot be use for 16 bit binary as I have tried. I need to convert the modbus short into binary (16 bit).

How do I write the script for readbit on bit 1, bit 2, bit 3 and so on?

Regards,
The administrator has disabled public write access.

Convert short to binary and display alarm 11 months 3 days ago #2362

  • fatkhrus
  • fatkhrus's Avatar
  • Offline
  • Administrator
  • Posts: 826
  • Thank you received: 123
  • Karma: -107
The easiest way for every bit crate tags: overvoltage_tag, undervoltage_tag and so on. And use expressions like this:
Tags.overvoltage_tag = reafbit(Tags.register, 0);
Tags.undervoltage_tag = readbit(Tags.register,1);

In tag properties enable alarms and setup them.

Best regards,
Ruslan
The administrator has disabled public write access.

Convert short to binary and display alarm 11 months 3 days ago #2363

  • tehlh
  • tehlh's Avatar
  • Offline
  • New Member
  • Posts: 6
  • Karma: 0
Mr. Rusian,

I have tried the easy way like you stated but it is not working. This is because CANbus J1939 standard transmission is in PGN and I am using a converter GW-7228 to convert it to modbus rtu short16 (integer). I attached the file for the values that is coming from the converter. So the original integer value must be converted to 16 bit binary and from there to extract out each bit from the 16 bit binary.

So the script to extract bit 1 is it like this, readbit (Y, 1); ?
The administrator has disabled public write access.

Convert short to binary and display alarm 11 months 3 days ago #2364

  • tehlh
  • tehlh's Avatar
  • Offline
  • New Member
  • Posts: 6
  • Karma: 0
Mr. Rusian,

Can you please explain what is input1 and input2 on the readbit command?

readbit(Input1, Input2) - used to read bit of the input value (Output = Input[Input2]).
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Go to top