Array Strange Behavior

Moderator: Benj

Post Reply
Raph
Posts: 6
Joined: Wed Dec 07, 2011 11:38 am
Has thanked: 3 times
Contact:

Array Strange Behavior

Post by Raph »

Hello,


I'm in front of a strange problem, let me explain it. I would love to send 32 numbers to as PC program via RS232, sounds easy.

My idea is to define an array of 32 value (INT) and put that array and the rs232 send macro in a loop that increase an index (from 0 to 31). I made a print screen of that part of my code that would be more clear I think.

Image

The whole Array values are :

Code: Select all

data_array_send[0] = 65
data_array_send[1] = 0
data_array_send[2] = 0
data_array_send[3] = 0
data_array_send[4] = 0
data_array_send[5] = 0
data_array_send[6] = 0
data_array_send[7] = 0
data_array_send[8] = 0
data_array_send[9] = 1
data_array_send[10] = 255
data_array_send[11] = 255
data_array_send[12] = 0
data_array_send[13] = 0
data_array_send[14] = 0
data_array_send[15] = 0
data_array_send[16] = 255
data_array_send[17] = 255
data_array_send[18] = 255
data_array_send[19] = 255
data_array_send[20] = 0
data_array_send[21] = 0
data_array_send[22] = 0
data_array_send[23] = 0
data_array_send[24] = 0
data_array_send[25] = 10
data_array_send[26] = 124
data_array_send[27] = 1
data_array_send[28] = 1
data_array_send[29] = 1
data_array_send[30] = 123
data_array_send[31] = 0
The strange part is that when I spy on my COM port with PuTTY I get thoses values.

Code: Select all

0
0
0
0
0
0
0
0
0
-512
0
0
0
0
0
0
48
52
0
0
0
0
0
0
0
0
0
0
0
-6144
-16104
12432
If I change the index into, for exemple, "30", I get the right value from the array (in that case "123"). "index" is define as INT, so I don't understand where the problem come from. I used similar "loop + array with incrementing index" before (mostly in C) and never seen a behavior like that and I see no "logical correlation" between what I send and what I receive.

So I wonder if anyone know how to solve this or if I made a mistake that I didn't noticed.

Have a nice day,


Raph

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Array Strange Behavior

Post by Benj »

Hello,

Could be something specific with Putty? What about using RealTerm this works nicely and can handle 255 as a value (shows it as 0xFF).

Raph
Posts: 6
Joined: Wed Dec 07, 2011 11:38 am
Has thanked: 3 times
Contact:

Re: Array Strange Behavior

Post by Raph »

Hi,

I don't think it's PuTTY, because as I said it work perfectly if I put a value between 0 and 31 instead of "index" (in the "TransToString" box), and it work well with another RS232 application.
But I tried another datalogger to listen to my COM port and it gave me the same results.

I don't know if the "ToString$()" fonction doesn't allow to have an array with a variable index as input.

I have attached my program if it can help.
Attachments
ONLY_RS232_PC_2012_04_05.fcf
(36.68 KiB) Downloaded 241 times

Raph
Posts: 6
Joined: Wed Dec 07, 2011 11:38 am
Has thanked: 3 times
Contact:

Re: Array Strange Behavior

Post by Raph »

I've just try to replace the routine with this C-Code, but it make no difference.

Code: Select all

//test loop
FCV_INDEX = 0;
for(FCV_INDEX=0;FCV_INDEX<32;FCV_INDEX++){
  FCI_TOSTRING(FCV_DATA_ARRAY_SEND[FCV_INDEX],FCV_TEMP,FCSZ_TEMP);
  FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
  FCD_RS2320_SendRS232Char(10);
  FCD_RS2320_SendRS232Char(13);
  delay_ms(5);
}
So for the time being, I use the "bruteforce" way ;) but I'll try to solve this later.

bruteforce way (so ugly, but it works):

Code: Select all

//temporary code
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[0],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[1],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[2],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[3],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[4],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------

FCI_TOSTRING(FCV_DATA_ARRAY_SEND[5],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[6],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[7],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[8],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[9],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[10],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[11],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[12],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[13],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[14],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[15],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[16],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[17],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[18],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[19],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[20],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[21],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[22],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[23],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[24],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[25],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[26],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[27],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[28],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[29],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[30],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
FCI_TOSTRING(FCV_DATA_ARRAY_SEND[31],FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232String(FCV_TEMP,FCSZ_TEMP);
FCD_RS2320_SendRS232Char(10);
FCD_RS2320_SendRS232Char(13);
delay_ms(5);
//-------------------------
If I find something I'll post it there.

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: Array Strange Behavior

Post by Mikat »

Hi.
At least I didn't find anything wrong at your code, but there is one thing which could clear the problem a little..
If you move the value in the array at temporary INT variable, and there to string.. That way it clears a bit is the problem at the ToString function, when used array and variable at pointer..
So you could test like this:
tempvar = array[index]
string = ToString (tempvar)
RS232SendString, string
If that works, the problem is at the ToString function, with array and variable at pointer..
Other thing what I have noticed for some version of Flowcode is that if the size of string is like [3] and then I put the string value 123, the display prints 1233333, but if the string size is [4] the display prints 123. I don't know is that fixed in ver5, but that is probably not the problem, if the code works fine with number at pointer..

Mika

Post Reply