Red Lion / Crimson 3.0 Bit Masking a System Function

Join Date
May 2022
Location
Houston,Tx
Posts
2
Happy Friday,

I am trying to log scan errors related to Modbus Comms for a G306.

I am able to use the system function GetDeviceStatus(x) to return a binary or hex value that I can reference against the below info, but I would really like to just return nth bits from the integer returned... I can't seem to find a function in the manual that works. Any thoughts on how to bitmask/map or get_bit for this?

I see there is a TREAT AS feature for a tag, but it is grayed out when I reference a tag of any kind.



VALUE DESCRIPTION
0 - The device comms is initializing.
1 - The device comms is operating correctly.
2 - The device comms has one or more soft errors.
3 - The device comms has encountered a fatal error.


The following hexadecimal values encode further information about the device…

VALUE DESCRIPTION
0x0010 - At least one error exists in the automatic comms blocks.
0x0020 - At least one error exists in the gateway comms blocks.
0x0040 - Communications to this device are suspended.
0x0100 - Some level of response has been received from the device.
0x0200 - Some form of error has occurred during communications.
0x1000 - The primary write queue is nearly full.
0x2000 - The secondary write queue is nearly full.​

Thank you for your time
 
Nevermind figured out a better way.

I used a flag that calls the function as a GENERAL source and then I can use the Treat As.

Actually that doesn't help either... I need to look at values in BYTE chunks and return integer instead...
 
Last edited:
The device error state (0-3) is encoded in the bottom two bits of the returned value. So you could do something like this to isolate them:
Code:
errorState := GetDeviceStatus(0) & 0b11
To parse the remaining information, you could use a switch statement to assign specific actions to the different return values.
Code:
deviceInfo := GetDeviceStatus(0) & 0xFFFC  // clear the first two bits

switch(deviceInfo) {
   case 0x0010:
     // actions
     break;
   case 0x0020:
     // some other actions
      break;
   case 0x0040:
     // more actions
     break;

   // more case statements, etc

 }
 
Try a web search for 'programming in c bitwise operations'.

In the code below I wanted to split the colour code used in Crimson 3.1 in to separate values for blue, green and red. Crimson uses a 16 bit integer for a colour code, and each colour uses 5 bits. I created a bit mask for each colour, I did them in binary format because it makes it easy for me to see what will be masked. The value for the complete colour code is 'Anded' (&) with the mask to isolate one value, but the value for everything except the red has to be shifted to the right by 5 or 10 places. Which is what the >> is about.

Code:
int bluemask =  0b111110000000000;
blue = (tagValue & bluemask) >> 10;
Gets me the integer for the 5 bits of the 16 bits that represents the blue colour.

Code:
// receive the current colour for a tag and then write back the new colour
//
int tagIndex;
int tagValue;

int bluemask =  0b111110000000000;
int greenmask = 0b000001111100000;
int redmask =   0b000000000011111;
int red, green, blue;
float Floatred, Floatgreen, Floatblue;
float convFac = 8.2258;

int not_set; // choice of wether to use the new colour

// convert the received string in to a tag reference number
tagIndex = FindTagIndex(TagLabel);

// get the value of the tag
tagValue = GetIntTag(tagIndex);

// convert to Red, Green, Blue
// this ANDs together the start value and the mask and then shifts all the bits by x to the right
blue = (tagValue & bluemask) >> 10;
Floatblue = (float) blue * convFac + 0.5;
Internal.ColourPIcker.Blue = (int) Floatblue;
  
green = (tagValue & greenmask) >> 5;
Floatgreen = (float) green * convFac + 0.5;
Internal.ColourPIcker.Green = (int) Floatgreen;
     
red = tagValue & redmask;
Floatred = (float) red * convFac + 0.5;
Internal.ColourPIcker.Red = (int) Floatred;

// set the colour picker to the current tag colour
Internal.ColourPIcker.Colour = ColGetRGB(Internal.ColourPIcker.Red,Internal.ColourPIcker.Green,Internal.ColourPIcker.Blue);

not_set = ShowModal(System.ColourPicker);

// if they choose to use the new colour then transfer to the tag
if (not_set == 1) SetIntTag(tagIndex, Internal.ColourPIcker.Colour);
 

Similar Topics

How do you install update on Red Lion Crimson ver 3.1. Do I just need to run the exe file on the host server?
Replies
1
Views
107
Hi, I am trying to increase the size of the user login pop up using a Red Lion CR1000 7” HMI with Crimson 3.1 software. The login pop up is very...
Replies
2
Views
679
Hello, We are currently running a bunch of g310's connected to their SLC5 PLCs through ethernet. I've attempted to upgrade the program from 2.0...
Replies
1
Views
1,122
Hi I have been using Red Lion products for some time, I had a thought over the bank holiday weekend, As you do. It would be nice if whenever a...
Replies
4
Views
1,019
Well, I have yet another question for the great minds on this forum! We have a red lion HMI for one of our machines and every time I hook my...
Replies
11
Views
1,673
Back
Top Bottom