HiTechnic NXC function error

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

HiTechnic NXC function error

Post by mattallen37 »

Ever since I tried to have the HT IR Link send messages to the RCX (HTRCXSetMessage), I have had issues getting it to work right. I always assumed I was doing something wrong out of inexperience. I just realized that only half of the messages are getting through (I think exactly every other one). However, writing the buffers myself to send the right messages seems to work every time. I use the Header 55FF00, then the Opcode f7 then all the rest that makes it work. This is what I think HTRCXSetMessage should do.

Using my homemade IR "tower" and a serial terminal program, I can see what is being transmitted. When I use my program, and write the registers myself, I get perfect results. For example, sending the IR Messages 0-3, it looks like this:

Code: Select all

85 255 0 247 8 0 255 247 8                                                      
85 255 0 247 8 1 254 248 7                                                      
85 255 0 247 8 2 253 249 6                                                      
85 255 0 247 8 3 252 250 5   
But when I try to send the IR Messages 0-3 using the HTRCXSetMessage function, it looks like this:

Code: Select all

85 255 0 247 8 0 255 247 8                                                      
85 255 0 255 0 1 254 0 255                                                      
85 255 0 247 8 2 253 249 6                                                      
85 255 0 255 0 3 252 2 253  
It looks to me, that the error is with the Opcode number being passed into the I2C buffer (probably 0x47). It should always be 0xf7, but as you can see, every other time, it is 0xff.

I am not sure exactly where the problem is, in BCC. No wonder I was only getting half of the messages.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: HiTechnic NXC function error

Post by afanofosc »

What you are seeing, I believe, is the 0x08 bit toggle for back to back identical opcodes. I may not be doing that exactly right but hopefully I am.

http://www-graphics.stanford.edu/~kekoa/rcx/#Protocol
Messages sent by PC seem to alternate between having 0x08 set and not set
This 0x08 bit is a sequence bit only in one special case
RCX never executes same exact opcode twice in a row
Second and beyond are dropped
But the same reply that was sent the first time is sent again
Toggle 0x08 bit to make sure same opcode twice in a row is accepted
0xF7 + 0x08 = 0xFF.

Maybe with the HiTechnic IRLink device there is sufficient time between sending each message that the toggle is not needed and may be causing problems? How many milliseconds go by between the messages you are sending?

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: HiTechnic NXC function error

Post by mattallen37 »

Ok, I can see why you did what you did, but it only gets half of them.

Using my code, it doesn't do that toggle thing, and the RCX receives every one of them. I don't have a number of milliseconds, but I am doing it as fast as it will allow. Actually, it is so fast that I can't visually see all of the numbers it receives because it doesn't update fast enough, but it isn't a certain group missing, like all the odd numbers. I will implement a datalogging program so I can confirm it gets them all. If I add a 200ms wait in the NXT program between each command, the RCX displays all of the numbers. One thing I find interesting though, is that every 11 sends (of 9 bytes), the IR Link takes a short "timeout" of some sort. I can see this in the terminal, as well as on the RCX.

I'll do a little datalogging, and see what happens.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: HiTechnic NXC function error

Post by mattallen37 »

Ok, I sent messages as fast as I could (wrote the I2C registers), and then waited for the flag in register 0x4F to = 0 (done sending the IR message). I then wrote it again immediately. I wrote the program to always use the Opcode 0xF7, and I increased the byte variable by one every time. The RCX's datalog looks perfect. Note, it started with a 1 stored in the IR Message buffer (I didn't clear it at the beginning of the program), that is why it starts with 1 in the datalog.

Code: Select all

Variable 1: 1
Variable 1: 0
Variable 1: 1
Variable 1: 2
Variable 1: 3
Variable 1: 4
Variable 1: 5
Variable 1: 6
Variable 1: 7
Variable 1: 8
Variable 1: 9
Variable 1: 10
Variable 1: 11
Variable 1: 12
Variable 1: 13
Variable 1: 14
Variable 1: 15
Variable 1: 16
Variable 1: 17
Variable 1: 18
Variable 1: 19
Variable 1: 20
Variable 1: 21
Variable 1: 22
Variable 1: 23
Variable 1: 24
Variable 1: 25
Variable 1: 26
Variable 1: 27
Variable 1: 28
Variable 1: 29
Variable 1: 30
Variable 1: 31
Variable 1: 32
Variable 1: 33
Variable 1: 34
Variable 1: 35
Variable 1: 36
Variable 1: 37
Variable 1: 38
Variable 1: 39
Variable 1: 40
Variable 1: 41
Variable 1: 42
Variable 1: 43
Variable 1: 44
Variable 1: 45
Variable 1: 46
Variable 1: 47
Variable 1: 48
Variable 1: 49
Variable 1: 50
Variable 1: 51
Variable 1: 52
Variable 1: 53
Variable 1: 54
Variable 1: 55
Variable 1: 56
Variable 1: 57
Variable 1: 58
Variable 1: 59
Variable 1: 60
Variable 1: 61
Variable 1: 62
Variable 1: 63
Variable 1: 64
Variable 1: 65
Variable 1: 66
Variable 1: 67
Variable 1: 68
Variable 1: 69
Variable 1: 70
Variable 1: 71
Variable 1: 72
Variable 1: 73
Variable 1: 74
Variable 1: 75
Variable 1: 76
Variable 1: 77
Variable 1: 78
Variable 1: 79
Variable 1: 80
Variable 1: 81
Variable 1: 82
Variable 1: 83
Variable 1: 84
Variable 1: 85
Variable 1: 86
Variable 1: 87
Variable 1: 88
Variable 1: 89
Variable 1: 90
Variable 1: 91
Variable 1: 92
Variable 1: 93
Variable 1: 94
Variable 1: 95
Variable 1: 96
Variable 1: 97
Variable 1: 98
Variable 1: 99
Variable 1: 100
Variable 1: 101
Variable 1: 102
Variable 1: 103
Variable 1: 104
Variable 1: 105
Variable 1: 106
Variable 1: 107
Variable 1: 108
Variable 1: 109
Variable 1: 110
Variable 1: 111
Variable 1: 112
Variable 1: 113
Variable 1: 114
Variable 1: 115
Variable 1: 116
Variable 1: 117
Variable 1: 118
Variable 1: 119
Variable 1: 120
Variable 1: 121
Variable 1: 122
Variable 1: 123
Variable 1: 124
Variable 1: 125
Variable 1: 126
Variable 1: 127
Variable 1: 128
Variable 1: 129
Variable 1: 130
Variable 1: 131
Variable 1: 132
Variable 1: 133
Variable 1: 134
Variable 1: 135
Variable 1: 136
Variable 1: 137
Variable 1: 138
Variable 1: 139
Variable 1: 140
Variable 1: 141
Variable 1: 142
Variable 1: 143
Variable 1: 144
Variable 1: 145
Variable 1: 146
Variable 1: 147
Variable 1: 148
Variable 1: 149
Variable 1: 150
Variable 1: 151
Variable 1: 152
Variable 1: 153
Variable 1: 154
Variable 1: 155
Variable 1: 156
Variable 1: 157
Variable 1: 158
Variable 1: 159
Variable 1: 160
Variable 1: 161
Variable 1: 162
Variable 1: 163
Variable 1: 164
Variable 1: 165
Variable 1: 166
Variable 1: 167
Variable 1: 168
Variable 1: 169
Variable 1: 170
Variable 1: 171
Variable 1: 172
Variable 1: 173
Variable 1: 174
Variable 1: 175
Variable 1: 176
Variable 1: 177
Variable 1: 178
Variable 1: 179
Variable 1: 180
Variable 1: 181
Variable 1: 182
Variable 1: 183
Variable 1: 184
Variable 1: 185
Variable 1: 186
Variable 1: 187
Variable 1: 188
Variable 1: 189
Variable 1: 190
Variable 1: 191
Variable 1: 192
Variable 1: 193
Variable 1: 194
Variable 1: 195
Variable 1: 196
Variable 1: 197
Variable 1: 198
Variable 1: 199
Variable 1: 200
Variable 1: 201
Variable 1: 202
Variable 1: 203
Variable 1: 204
Variable 1: 205
Variable 1: 206
Variable 1: 207
Variable 1: 208
Variable 1: 209
Variable 1: 210
Variable 1: 211
Variable 1: 212
Variable 1: 213
Variable 1: 214
Variable 1: 215
Variable 1: 216
Variable 1: 217
Variable 1: 218
Variable 1: 219
Variable 1: 220
Variable 1: 221
Variable 1: 222
Variable 1: 223
Variable 1: 224
Variable 1: 225
Variable 1: 226
Variable 1: 227
Variable 1: 228
Variable 1: 229
Variable 1: 230
Variable 1: 231
Variable 1: 232
Variable 1: 233
Variable 1: 234
Variable 1: 235
Variable 1: 236
Variable 1: 237
Variable 1: 238
Variable 1: 239
Variable 1: 240
Variable 1: 241
Variable 1: 242
Variable 1: 243
Variable 1: 244
Variable 1: 245
Variable 1: 246
Variable 1: 247
Variable 1: 248
Variable 1: 249
Variable 1: 250
Variable 1: 251
Variable 1: 252
Variable 1: 253
Variable 1: 254
Variable 1: 255
Variable 1: 0
Variable 1: 1
Variable 1: 2
Variable 1: 3
Variable 1: 4
Variable 1: 5
Variable 1: 6
Variable 1: 7
Variable 1: 8
Variable 1: 9
Variable 1: 10
Variable 1: 11
Variable 1: 12
Variable 1: 13
Variable 1: 14
Variable 1: 15
Variable 1: 16
Variable 1: 17
Variable 1: 18
Variable 1: 19
Variable 1: 20
Variable 1: 21
Variable 1: 22
Variable 1: 23
Variable 1: 24
Variable 1: 25
Variable 1: 26
Variable 1: 27
Variable 1: 28
Variable 1: 29
Variable 1: 30
Variable 1: 31
Variable 1: 32
Variable 1: 33
Variable 1: 34
Variable 1: 35
Variable 1: 36
Variable 1: 37
Variable 1: 38
Variable 1: 39
Variable 1: 40
Variable 1: 41
Variable 1: 42
Variable 1: 43
Variable 1: 44
Variable 1: 45
Variable 1: 46
Variable 1: 47
Variable 1: 48
Variable 1: 49
Variable 1: 50
Variable 1: 51
Variable 1: 52
Variable 1: 53
Variable 1: 54
Variable 1: 55
Variable 1: 56
Variable 1: 57
Variable 1: 58
Variable 1: 59
Variable 1: 60
Variable 1: 61
Variable 1: 62
Variable 1: 63
Variable 1: 64
Variable 1: 65
Variable 1: 66
Variable 1: 67
Variable 1: 68
Variable 1: 69
Variable 1: 70
Variable 1: 71
Variable 1: 72
Variable 1: 73
Variable 1: 74
Variable 1: 75
Variable 1: 76
Variable 1: 77
Variable 1: 78
Variable 1: 79
Variable 1: 80
Variable 1: 81
Variable 1: 82
Variable 1: 83
Variable 1: 84
Variable 1: 85
Variable 1: 86
Variable 1: 87
Variable 1: 88
Variable 1: 89
Variable 1: 90
Variable 1: 91
Variable 1: 92
Variable 1: 93
Variable 1: 94
Variable 1: 95
Variable 1: 96
Variable 1: 97
Variable 1: 98
Variable 1: 99
Variable 1: 100
Variable 1: 101
Variable 1: 102
Variable 1: 103
Variable 1: 104
Variable 1: 105
Variable 1: 106
Variable 1: 107
Variable 1: 108
Variable 1: 109
Variable 1: 110
Variable 1: 111
Variable 1: 112
Variable 1: 113
Variable 1: 114
Variable 1: 115
Variable 1: 116
Variable 1: 117
Variable 1: 118
Variable 1: 119
Variable 1: 120
Variable 1: 121
Variable 1: 122
Variable 1: 123
Variable 1: 124
Variable 1: 125
Variable 1: 126
Variable 1: 127
Variable 1: 128
Variable 1: 129
Variable 1: 130
Variable 1: 131
Variable 1: 132
Variable 1: 133
Variable 1: 134
Variable 1: 135
Variable 1: 136
Variable 1: 137
Variable 1: 138
Variable 1: 139
Variable 1: 140
Variable 1: 141
Variable 1: 142
Variable 1: 143
Variable 1: 144
Variable 1: 145
Variable 1: 146
Variable 1: 147
Variable 1: 148
Variable 1: 149
Variable 1: 150
Variable 1: 151
Variable 1: 152
Variable 1: 153
Variable 1: 154
Variable 1: 155
Variable 1: 156
Variable 1: 157
Variable 1: 158
Variable 1: 159
Variable 1: 160
Variable 1: 161
Variable 1: 162
Variable 1: 163
Variable 1: 164
Variable 1: 165
Variable 1: 166
Variable 1: 167
Variable 1: 168
Variable 1: 169
Variable 1: 170
Variable 1: 171
Variable 1: 172
Variable 1: 173
Variable 1: 174
Variable 1: 175
Variable 1: 176
Variable 1: 177
Variable 1: 178
Variable 1: 179
Variable 1: 180
Variable 1: 181
Variable 1: 182
Variable 1: 183
Variable 1: 184
Variable 1: 185
Variable 1: 186
Variable 1: 187
Variable 1: 188
Variable 1: 189
Variable 1: 190
Variable 1: 191
Variable 1: 192
Variable 1: 193
Variable 1: 194
Variable 1: 195
Variable 1: 196
Variable 1: 197
Variable 1: 198
Variable 1: 199
Variable 1: 200
Variable 1: 201
Variable 1: 202
Variable 1: 203
Variable 1: 204
Variable 1: 205
Variable 1: 206
Variable 1: 207
Variable 1: 208
Variable 1: 209
Variable 1: 210
Variable 1: 211
Variable 1: 212
Variable 1: 213
Variable 1: 214
Variable 1: 215
Variable 1: 216
Variable 1: 217
Variable 1: 218
Variable 1: 219
Variable 1: 220
Variable 1: 221
Variable 1: 222
Variable 1: 223
Variable 1: 224
Variable 1: 225
Variable 1: 226
Variable 1: 227
Variable 1: 228
Variable 1: 229
Variable 1: 230
Variable 1: 231
Variable 1: 232
Variable 1: 233
Variable 1: 234
Variable 1: 235
Variable 1: 236
Variable 1: 237
Variable 1: 238
Variable 1: 239
Variable 1: 240
Variable 1: 241
Variable 1: 242
Variable 1: 243
Variable 1: 244
Variable 1: 245
Variable 1: 246
Variable 1: 247
Variable 1: 248
Variable 1: 249
Variable 1: 250
Variable 1: 251
Variable 1: 252
Variable 1: 253
Variable 1: 254
Variable 1: 255
Variable 1: 0
Variable 1: 1
Variable 1: 2
Variable 1: 3
Variable 1: 4
Variable 1: 5
Variable 1: 6
Variable 1: 7
Variable 1: 8
Variable 1: 9
Variable 1: 10
Variable 1: 11
Variable 1: 12
Variable 1: 13
Variable 1: 14
Variable 1: 15
Variable 1: 16
Variable 1: 17
Variable 1: 18
Variable 1: 19
Variable 1: 20
Variable 1: 21
Variable 1: 22
Variable 1: 23
Variable 1: 24
Variable 1: 25
Variable 1: 26
Variable 1: 27
Variable 1: 28
Variable 1: 29
Variable 1: 30
Variable 1: 31
Variable 1: 32
Variable 1: 33
Variable 1: 34
Variable 1: 35
Variable 1: 36
Variable 1: 37
Variable 1: 38
Variable 1: 39
Variable 1: 40
Variable 1: 41
Variable 1: 42
Variable 1: 43
Variable 1: 44
Variable 1: 45
Variable 1: 46
Variable 1: 47
Variable 1: 48
Variable 1: 49
Variable 1: 50
Variable 1: 51
Variable 1: 52
Variable 1: 53
Variable 1: 54
Variable 1: 55
Variable 1: 56
Variable 1: 57
Variable 1: 58
Variable 1: 59
Variable 1: 60
Variable 1: 61
Variable 1: 62
Variable 1: 63
Variable 1: 64
Variable 1: 65
Variable 1: 66
Variable 1: 67
Variable 1: 68
Variable 1: 69
Variable 1: 70
Variable 1: 71
Variable 1: 72
Variable 1: 73
Variable 1: 74
Variable 1: 75
Variable 1: 76
Variable 1: 77
Variable 1: 78
Variable 1: 79
Variable 1: 80
Variable 1: 81
Variable 1: 82
Variable 1: 83
Variable 1: 84
Variable 1: 85
Variable 1: 86
Here is the RCX program:

Code: Select all

int LastMessage=300;
task main(){
  CreateDatalog (600);
  while(true){
    until (Message ()!= LastMessage);
    AddToDatalog (Message());
    SetUserDisplay(Message(),0);
    LastMessage = Message();
  }
}
And here is the program for the NXT:

Code: Select all

#include "Picaxe lib.nxc"
int i=0;
byte Data[2];
byte CheckSum=0;

int HTRCXIRData(byte port, byte DataIn[]){
  byte UserBytes;
  UserBytes=ArrayLen(DataIn);
  if(UserBytes>4)return -1;
  byte DataOut[];
  byte DataOutLen=3+5+(UserBytes*2);
  ArrayInit(DataOut, 0, DataOutLen);
  DataOut[0]=0x55;
  DataOut[1]=0xff;
  DataOut[2]=0x00;

  byte Ini=0;
  byte Outi=3;
  byte CheckSum=0;
  repeat(UserBytes){
    CheckSum+=DataIn[Ini];
    DataOut[Outi]=DataIn[Ini];
    Outi++;
    DataOut[Outi]=~DataIn[Ini];
    Outi++;
    Ini++;
  }
  DataOut[Outi]=CheckSum;
  Outi++;
  DataOut[Outi]=~CheckSum;
  Outi++;
  DataOut[Outi]=5+(UserBytes*2);
  Outi++;
  DataOut[Outi]=0x00;
  Outi++;
  DataOut[Outi]=0x01;

  byte Register=0x4D-5-(UserBytes*2);
  WritePicaxe(port, 0x02, Register, DataOut);
}

void HTRCXIRDataDoneSending(byte port){
  byte Data[1];
  ReadPicaxe(port, 0x02, 0x4F, 1, Data);
  until(Data[0]==0){
    ReadPicaxe(port, 0x02, 0x4F, 1, Data);
    Wait(1);
  }
}

task main()
{
  SetSensorLowspeed(IN_1);
  HTRCXSetIRLinkPort(IN_1);

  while(true)
  {
    Data[0]=0xf7;
    Data[1]=i;
    HTRCXIRData(IN_1, Data);
    HTRCXIRDataDoneSending(IN_1);
    //Wait(200);
    //HTRCXSetMessage(i);
    i++;
  }
}
Sorry for the PICAXE references, but my PICAXE lib functions work perfectly for writing and reading I2C, so I use them for custom I2C messages for any sensor/device.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: HiTechnic NXC function error

Post by mattallen37 »

Here is the datalog created using the same RCX program.

Code: Select all

Variable 1: 0
Variable 1: 2
Variable 1: 4
Variable 1: 6
Variable 1: 8
Variable 1: 10
Variable 1: 12
Variable 1: 14
Variable 1: 16
Variable 1: 18
Variable 1: 20
Variable 1: 22
Variable 1: 24
Variable 1: 26
Variable 1: 28
Variable 1: 30
Variable 1: 32
Variable 1: 34
Variable 1: 36
Variable 1: 38
Variable 1: 40
Variable 1: 42
Variable 1: 44
Variable 1: 46
Variable 1: 48
Variable 1: 50
Variable 1: 52
Variable 1: 54
Variable 1: 56
Variable 1: 58
Variable 1: 60
Variable 1: 62
Variable 1: 64
Variable 1: 66
Variable 1: 68
Variable 1: 70
Variable 1: 72
Variable 1: 74
Variable 1: 76
Variable 1: 78
Variable 1: 80
Variable 1: 82
Variable 1: 84
Variable 1: 86
Variable 1: 88
Variable 1: 90
Variable 1: 92
Variable 1: 94
Variable 1: 96
Variable 1: 98
Variable 1: 100
Variable 1: 102
Variable 1: 104
Variable 1: 106
Variable 1: 108
Variable 1: 110
Variable 1: 112
Variable 1: 114
Variable 1: 116
Variable 1: 118
Variable 1: 120
Variable 1: 122
Variable 1: 124
Variable 1: 126
Variable 1: 128
Variable 1: 130
Variable 1: 132
Variable 1: 134
Variable 1: 136
Variable 1: 138
Variable 1: 140
Variable 1: 142
Variable 1: 144
Variable 1: 146
Variable 1: 148
Variable 1: 150
Variable 1: 152
Variable 1: 154
Variable 1: 156
Variable 1: 158
Variable 1: 160
Variable 1: 162
Variable 1: 164
Variable 1: 166
Variable 1: 168
Variable 1: 170
Variable 1: 172
Variable 1: 174
Variable 1: 176
Variable 1: 178
Variable 1: 180
Variable 1: 182
Variable 1: 184
Variable 1: 186
Variable 1: 188
Variable 1: 190
Variable 1: 192
Variable 1: 194
Variable 1: 196
Variable 1: 198
Variable 1: 200
Variable 1: 202
Variable 1: 204
Variable 1: 206
Variable 1: 208
Variable 1: 210
Variable 1: 212
Variable 1: 214
Variable 1: 216
Variable 1: 218
Variable 1: 220
Variable 1: 222
Variable 1: 224
Variable 1: 226
Variable 1: 228
Variable 1: 230
Variable 1: 232
Variable 1: 234
Variable 1: 236
Variable 1: 238
Variable 1: 240
Variable 1: 242
Variable 1: 244
Variable 1: 246
Variable 1: 248
Variable 1: 250
Variable 1: 252
Variable 1: 254
Variable 1: 0
Variable 1: 2
Variable 1: 4
Variable 1: 6
Variable 1: 8
Variable 1: 10
Variable 1: 12
Variable 1: 14
Variable 1: 16
Variable 1: 18
Variable 1: 20
Variable 1: 22
Variable 1: 24
Variable 1: 26
Variable 1: 28
Variable 1: 30
Variable 1: 32
Variable 1: 34
Variable 1: 36
Variable 1: 38
Variable 1: 40
Variable 1: 42
Variable 1: 44
Variable 1: 46
Variable 1: 48
Variable 1: 50
Variable 1: 52
Variable 1: 54
Variable 1: 56
Variable 1: 58
Variable 1: 60
Variable 1: 62
Variable 1: 64
Variable 1: 66
Variable 1: 68
Variable 1: 70
Variable 1: 72
Variable 1: 74
Variable 1: 76
Variable 1: 78
Variable 1: 80
Variable 1: 82
Variable 1: 84
Variable 1: 86
Variable 1: 88
Variable 1: 90
Variable 1: 92
Variable 1: 94
Variable 1: 96
Variable 1: 98
Variable 1: 100
Variable 1: 102
Variable 1: 104
Variable 1: 106
Variable 1: 108
Variable 1: 110
Variable 1: 112
Variable 1: 114
Variable 1: 116
Variable 1: 118
Variable 1: 120
Variable 1: 122
Variable 1: 124
Variable 1: 126
Variable 1: 128
Variable 1: 130
Variable 1: 132
Variable 1: 134
Variable 1: 136
Variable 1: 138
Variable 1: 140
Variable 1: 142
Variable 1: 144
Variable 1: 146
Variable 1: 148
Variable 1: 150
Variable 1: 152
Variable 1: 154
Variable 1: 156
Variable 1: 158
Variable 1: 160
Variable 1: 162
Variable 1: 164
Variable 1: 166
Variable 1: 168
Variable 1: 170
Variable 1: 172
Variable 1: 174
Variable 1: 176
Variable 1: 178
Variable 1: 180
Variable 1: 182
Variable 1: 184
Variable 1: 186
Variable 1: 188
Variable 1: 190
Variable 1: 192
Variable 1: 194
Variable 1: 196
Variable 1: 198
Variable 1: 200
Variable 1: 202
Variable 1: 204
Variable 1: 206
Variable 1: 208
Variable 1: 210
Variable 1: 212
Variable 1: 214
Variable 1: 216
Variable 1: 218
Variable 1: 220
Variable 1: 222
Variable 1: 224
Variable 1: 226
Variable 1: 228
Variable 1: 230
Variable 1: 232
Variable 1: 234
Variable 1: 236
Variable 1: 238
Variable 1: 240
Variable 1: 242
Variable 1: 244
Variable 1: 246
Variable 1: 248
Variable 1: 250
Variable 1: 252
Variable 1: 254
Variable 1: 0
Variable 1: 2
Variable 1: 4
Variable 1: 6
Variable 1: 8
Variable 1: 10
Variable 1: 12
Variable 1: 14
Variable 1: 16
Variable 1: 18
Variable 1: 20
Variable 1: 22
Variable 1: 24
Variable 1: 26
Variable 1: 28
Variable 1: 30
Variable 1: 32
Variable 1: 34
Variable 1: 36
Variable 1: 38
Variable 1: 40
Variable 1: 42
Variable 1: 44
Variable 1: 46
Variable 1: 48
Variable 1: 50
Variable 1: 52
Variable 1: 54
Variable 1: 56
Variable 1: 58
Variable 1: 60
Variable 1: 62
Variable 1: 64
Variable 1: 66
Variable 1: 68
Variable 1: 70
Variable 1: 72
Variable 1: 74
Variable 1: 76
Variable 1: 78
Variable 1: 80
Variable 1: 82
Variable 1: 84
Variable 1: 86
Variable 1: 88
Variable 1: 90
Variable 1: 92
Variable 1: 94
Variable 1: 96
Variable 1: 98
Variable 1: 100
Variable 1: 102
Variable 1: 104
Variable 1: 106
Variable 1: 108
Variable 1: 110
Variable 1: 112
Variable 1: 114
Variable 1: 116
Variable 1: 118
Variable 1: 120
Variable 1: 122
Variable 1: 124
Variable 1: 126
Variable 1: 128
Variable 1: 130
Variable 1: 132
Variable 1: 134
Variable 1: 136
Variable 1: 138
Variable 1: 140
Variable 1: 142
Variable 1: 144
Variable 1: 146
Variable 1: 148
Variable 1: 150
Variable 1: 152
Variable 1: 154
Variable 1: 156
Variable 1: 158
Variable 1: 160
Variable 1: 162
Variable 1: 164
Variable 1: 166
Variable 1: 168
Variable 1: 170
Variable 1: 172
Variable 1: 174
Variable 1: 176
Variable 1: 178
Variable 1: 180
Variable 1: 182
Variable 1: 184
Variable 1: 186
Variable 1: 188
Variable 1: 190
Variable 1: 192
Variable 1: 194
Variable 1: 196
Variable 1: 198
Variable 1: 200
Variable 1: 202
Variable 1: 204
Variable 1: 206
Variable 1: 208
Variable 1: 210
Variable 1: 212
Variable 1: 214
Variable 1: 216
Variable 1: 218
Variable 1: 220
Variable 1: 222
Variable 1: 224
Variable 1: 226
Variable 1: 228
Variable 1: 230
Variable 1: 232
Variable 1: 234
Variable 1: 236
Variable 1: 238
Variable 1: 240
Variable 1: 242
Variable 1: 244
Variable 1: 246
Variable 1: 248
Variable 1: 250
Variable 1: 252
Variable 1: 254
Variable 1: 0
Variable 1: 2
Variable 1: 4
Variable 1: 6
Variable 1: 8
Variable 1: 10
Variable 1: 12
Variable 1: 14
Variable 1: 16
Variable 1: 18
Variable 1: 20
Variable 1: 22
Variable 1: 24
Variable 1: 26
Variable 1: 28
Variable 1: 30
Variable 1: 32
Variable 1: 34
Variable 1: 36
Variable 1: 38
Variable 1: 40
Variable 1: 42
Variable 1: 44
Variable 1: 46
Variable 1: 48
Variable 1: 50
Variable 1: 52
Variable 1: 54
Variable 1: 56
Variable 1: 58
Variable 1: 60
Variable 1: 62
Variable 1: 64
Variable 1: 66
Variable 1: 68
Variable 1: 70
Variable 1: 72
Variable 1: 74
Variable 1: 76
Variable 1: 78
Variable 1: 80
Variable 1: 82
Variable 1: 84
Variable 1: 86
Variable 1: 88
Variable 1: 90
Variable 1: 92
Variable 1: 94
Variable 1: 96
Variable 1: 98
Variable 1: 100
Variable 1: 102
Variable 1: 104
Variable 1: 106
Variable 1: 108
Variable 1: 110
Variable 1: 112
Variable 1: 114
Variable 1: 116
Variable 1: 118
Variable 1: 120
Variable 1: 122
Variable 1: 124
Variable 1: 126
Variable 1: 128
Variable 1: 130
Variable 1: 132
Variable 1: 134
Variable 1: 136
Variable 1: 138
Variable 1: 140
Variable 1: 142
Variable 1: 144
Variable 1: 146
Variable 1: 148
Variable 1: 150
Variable 1: 152
Variable 1: 154
Variable 1: 156
Variable 1: 158
Variable 1: 160
Variable 1: 162
Variable 1: 164
Variable 1: 166
Variable 1: 168
Variable 1: 170
Variable 1: 172
Variable 1: 174
Variable 1: 176
Variable 1: 178
Variable 1: 180
Variable 1: 182
Variable 1: 184
Variable 1: 186
Variable 1: 188
Variable 1: 190
Variable 1: 192
Variable 1: 194
Variable 1: 196
Variable 1: 198
Variable 1: 200
Variable 1: 202
Variable 1: 204
Variable 1: 206
Variable 1: 208
Variable 1: 210
Variable 1: 212
Variable 1: 214
Variable 1: 216
Variable 1: 218
Variable 1: 220
Variable 1: 222
Variable 1: 224
Variable 1: 226
Variable 1: 228
Variable 1: 230
Variable 1: 232
Variable 1: 234
Variable 1: 236
Variable 1: 238
Variable 1: 240
Variable 1: 242
Variable 1: 244
Variable 1: 246
Variable 1: 248
Variable 1: 250
Variable 1: 252
Variable 1: 254
Variable 1: 0
Variable 1: 2
Variable 1: 4
Variable 1: 6
Variable 1: 8
Variable 1: 10
Variable 1: 12
Variable 1: 14
Variable 1: 16
Variable 1: 18
Variable 1: 20
Variable 1: 22
Variable 1: 24
Variable 1: 26
Variable 1: 28
Variable 1: 30
Variable 1: 32
Variable 1: 34
Variable 1: 36
Variable 1: 38
Variable 1: 40
Variable 1: 42
Variable 1: 44
Variable 1: 46
Variable 1: 48
Variable 1: 50
Variable 1: 52
Variable 1: 54
Variable 1: 56
Variable 1: 58
Variable 1: 60
Variable 1: 62
Variable 1: 64
Variable 1: 66
Variable 1: 68
Variable 1: 70
Variable 1: 72
Variable 1: 74
Variable 1: 76
Variable 1: 78
Variable 1: 80
Variable 1: 82
Variable 1: 84
Variable 1: 86
Variable 1: 88
Variable 1: 90
Variable 1: 92
Variable 1: 94
Variable 1: 96
Variable 1: 98
Variable 1: 100
Variable 1: 102
Variable 1: 104
Variable 1: 106
Variable 1: 108
Variable 1: 110
Variable 1: 112
Variable 1: 114
Variable 1: 116
Variable 1: 118
Variable 1: 120
Variable 1: 122
Variable 1: 124
Variable 1: 126
Variable 1: 128
Variable 1: 130
Variable 1: 132
Variable 1: 134
Variable 1: 136
Variable 1: 138
Variable 1: 140
Variable 1: 142
Variable 1: 144
Variable 1: 146
Variable 1: 148
Variable 1: 150
Variable 1: 152
Variable 1: 154
Variable 1: 156
Variable 1: 158
Variable 1: 160
Variable 1: 162
Variable 1: 164
Variable 1: 166
Variable 1: 168
Variable 1: 170
Variable 1: 172
Variable 1: 174
The only thing different, is I commented out these lines in the NXT program:

Code: Select all

HTRCXIRData(IN_1, Data);
HTRCXIRDataDoneSending(IN_1);
And uncommented this line:

Code: Select all

HTRCXSetMessage(i);
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: HiTechnic NXC function error

Post by afanofosc »

We should get some input from John Barnes or some other RCX communication expert who might be able to explain what should or should not be done when sending RCX messages via the IRLink. I thought that I had implemented the code based on sample code he sent me so my hope is that I didn't deviate from his input. It's been too long now, though, for me to remember properly.

Here's a snippet from his original code:

Code: Select all

    temp = 10 + 2 * RCXcmnd[1] ;                // number of bytes to send
    ArrayInit(inI2Ccmd, 0, temp);               // initialise buffer
    inI2Ccmd[0] = 0x02;                         // write to IR Link
    inI2Ccmd[1] = 0x48 - 2 * RCXcmnd[1];        // start position in TX buffer
    inI2Ccmd[2] = 0x55;                         //
    inI2Ccmd[3] = 0xFF;                         //
    inI2Ccmd[4] = 0x00;                         // RCX message header
    inI2Ccmd[5] = RCXcmnd[3] | toggle;          // toggle to make RCX notice
    inI2Ccmd[6] = 255 - (RCXcmnd[3] | toggle);  // and inverse
    csum=RCXcmnd[3] | toggle;                   // initialise check sum
    toggle ^= 8;                                // flip the toggle for next time
    i=0;                                        // initialise for copy
    if (RCXcmnd[1] > 1)                         // put the rest of the command
       {                                        // if there's more than one byte
       while (i < RCXcmnd[1] - 1)
          {
          inI2Ccmd[2*i+7] = RCXcmnd[i+4];       // insert byte
          inI2Ccmd[2*i+8] = 255 - RCXcmnd[i+4]; // and inverse
          csum += RCXcmnd[i+4];
          i++
          }
       }
    inI2Ccmd[2*i+7] = csum;                     // put the check sum
    inI2Ccmd[2*i+8] = 255 - csum;
    inI2Ccmd[2*i+9] = 2 * RCXcmnd[1] + 5;       // put the TX buffer length
    inI2Ccmd[2*i+10] = 0x00;                    // mode 0 is RCX comm
    inI2Ccmd[2*i+11] = 0x01;                    // trigger transmit
Can you tell me if it looks like all the bytes in the non-working messages look right in terms of command byte with toggle set, the inverse of the command, and the checksum? Maybe I am messing up the inverted byte or the checksum when I do the toggle?

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: HiTechnic NXC function error

Post by mattallen37 »

Well, I don't know how many people would benefit from you putting in the time and effort of fixing what seems to not work right. You don't need to just for me; I can use my own function(s) to send the messages.

Refer to my first post to to see the "command byte with toggle set, the inverse of the command, and the checksum". Yes, it is all right (according to how it is coded).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: HiTechnic NXC function error

Post by afanofosc »

So you are saying that these byte:

Code: Select all

85 255 0 247 8 0 255 247 8                                                      
85 255 0 255 0 1 254 0 255                                                      
85 255 0 247 8 2 253 249 6                                                      
85 255 0 255 0 3 252 2 253  
are all correct and valid based on the code that John Barnes provided me and the available RCX communication protocol docs. Is that right?

Can you run some tests with the attached NXC program that John sent me and let me know if the bytes you see look like what you get from the NXC API function?
IRLinkWrite.zip
(1.1 KiB) Downloaded 170 times
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: HiTechnic NXC function error

Post by mattallen37 »

I am saying, that those are from the HTRCXSetMessage command, and they are in compliance with what is said should be right. However, it is not right according to the RCX. The RCX only picked up on the ones that were 0xf7 (247), and disregarded the other ones (0xff, or 255).

I ran the program you send me, and here is what the terminal picked up.

Code: Select all

85 255 0 33 222 129 126 162 93                                                  
85 255 0 233 22 129 126 106 149                                                 
85 255 0 225 30 1 254 226 29                                                    
85 255 0 233 22 129 126 106 149                                                 
85 255 0 225 30 1 254 226 29                                                    
85 255 0 233 22 129 126 106 149                                                 
85 255 0 225 30 1 254 226 29                                                    
85 255 0 233 22 129 126 106 149                                                 
85 255 0 225 30 1 254 226 29                                                    
85 255 0 233 22 129 126 106 149                                                 
85 255 0 225 30 1 254 226 29                                                    
85 255 0 41 214 65 190 106 149  
I also ran it with an RCX turned on and in range, and here is what the terminal picked up (using the same NXT program, but no RCX program was running).

Code: Select all

85 255 0 33 222 129 126 162 93                                                  
85 255 0 222 33 94 0 0 233 22 129 126 106 149                                   
85 255 0 22 233 22 233                                                          
85 255 0 225 30 1 254 226 29                                                    
85 255 0 30 225 30 225                                                          
85 255 0 233 22 129 126 106 149                                                 
85 255 0 22 233 22 233                                                          
85 255 0 225 30 1 254 226 29                                                    
85 255 0 30 225 30 225                                                          
85 255 0 233 22 129 126 106 149                                                 
85 255 0 22 233 22 233                                                          
85 255 0 225 30 1 254 226 29                                                    
85 255 0 30 225 30 225                                                          
85 255 0 233 22 129 126 106 149                                                 
85 255 0 22 233 22 233                                                          
85 255 0 225 30 1 254 226 29                                                    
85 255 0 30 225 30 225                                                          
85 255 0 233 22 129 126 106 149                                                 
85 255 0 22 233 22 233                                                          
85 255 0 225 30 1 254 226 29                                                    
85 255 0 30 225 30 225                                                          
85 255 0 41 214 65 190 106 149                                                  
85 255 0 214 41 214 41
The RCX did indeed respond exactly as the comments in the program say it should (running the motor forwards and reverse 5 times), so obviously the toggling was okay in this case. Note the extra lines; those are from the RCX, acknowledging that it got the commands. Also note that the IR responses from the RCX are indeed the NOT of the Opcode (as they should be).

I am wondering if maybe you need to toggle the 0x08 bit only for commands that the RCX responds to (it does not respond to a set message command).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: HiTechnic NXC function error

Post by afanofosc »

I have checked the FakeSpirit.pas source code for how it builds RCX messages. It looks like the Remote (d2) opcode, the SetMessage (f7) opcode, and the Uart (c2) opcode do not use the toggle bit. I'll see if I can fix that.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests