Crimson 3.0 Arrays.

haakonk

Member
Join Date
Jan 2019
Location
norge
Posts
5
Hello.

I have a sensor that uses ASCII connected to the rs232 port on my red lion data station. Im using this program to get the data into a array.
// this Rx routine will allow you to display all of the bytes received in a transmission
// declare locals
int i;
int j;
int in = PortRead(2, 255);
// loop while there is data in the buffer, populating the array
while(in != -1) {
Array[i++] = in;
in = PortRead(2, 255);
}
// if something was received, build a string
if(i > 0) {
String = "";
for(j = 0; j <= i; j ++){
String += Array[j];
}
}

The values i get are decimal values, the first 4 bytes are 52 52 50 48, which is 4420 when i convert it to ascii and that is the sensor type. Is there a way to create a program that can translate the bytes received to ascii?

Coding is not something i do frequently, so any help or documentation on how to do it is appreciated.
 
https://www.theautomationstore.com/red-lion-crimson-3-0-function-library/

IntToChar


Which is a subroutine with 1 parameter
cstring Common.intToChar(int Param1)

Code:
//Converts an Integer into an ASCII character
//Created by Redlion and downloded from https://www.theautomationstore.com/red-lion-crimson-3-0-function-library/

//declare local string
cstring str;

//append character (integer) to string
return str += Param1;
 
Thank you Bryan.

I have managed to get it into a string now and read the data.

The sensor isnt using position based sytem on the bytes of the measuring data, the first 4 bytes are always the sensor type, byte 5 is a Tab, 6-7-8 the sensor ID, 9 is Tab, byte 10-16 is a value for speed, 17 Tab, byte 18-24 value for degrees and 25 is Tab.

So the first 9 bytes are always constant, but the sensor is only using 7 bytes per measuring value if the value is >= 100 (3 digits after the decimal is also constant), so lets say the speed is 9.000 cm/s the values for for the degrees will be stored in byte 16-22 in the array and not 18-24.

So what I am trying to do is to count where the Tabs are placed in the string (9 in ascii) and divide the measuring data somehow using that information.

I have been trying to use the FIND(STRING,CHAR,SKIP) function but with no luck.

My string is called "String" and the int tag where the value is returned is called "position"
Position := Find("String",4,1);
And just to test it I am trying to find the second 4 in the sensor type, but it is still returning -1.

Any ideas?

Edit: I realised the problem now, "String" should be written String... Its working now.
 
Last edited:
Code:
Position := Find("String",4,1);
By putting the "" marks around the word String you are searching the word String for a number 4 rather than actual string you want to search, and as there aren't any 4s in the word String you get -1. Remove the "" and it should be OK.
 

Similar Topics

Hi all, Is it possible to clear an entire String array without having to clear the contents of each element manually? I notice there's a FILL...
Replies
1
Views
1,079
Hi there, A few queries regarding arrays, as some languages allow for this. Does anyone know whether its possible to use strings as element...
Replies
3
Views
1,889
This question being asked on the basis of using Crimson 3.0 but probably applies to all similar software. Does the number of tags used in the...
Replies
2
Views
4,013
Using Red Lion PTV: I want to log various elements of an array. when i drag an array tag into the datalog contents box, it enters the array with...
Replies
3
Views
2,622
Hi folks, I have a couple of array tags which I am attempting to build a schedule application with. I have two spaciffic problems. 1. Using the...
Replies
5
Views
7,238
Back
Top Bottom