NXC: rs485: error with EFW, no error with SFW
Posted: 09 Mar 2011, 11:44
this is a topic from our German Mindstorms forum.
the program gives error -32 or -2 with the EFW (1.31) , but no error with the SFW (disabled in the settings):
the program gives error -32 or -2 with the EFW (1.31) , but no error with the SFW (disabled in the settings):
devnull wrote:Ok, hier kommt es:
Zuerst der Master:
und jetzt noch der task main für den Slave (der Rest ist identisch):Code: Select all
#ifndef _HS_LIB_NXC #define _HS_LIB_NXC //******************************************************** // High speed communication library for NXC // Author: Daniele Benedettelli, 11 Jan 2008 // Contributors: John Hansen, John Barnes //******************************************************** // Connecting two NXTs using a 6-wire cable between their ports 4, // you can send strings and numbers at high speed // initialize the port 4 void SetHSPort() { // no argument, since the only high speed port is the number 4 SetSensorType(IN_4, SENSOR_TYPE_HIGHSPEED); SetHSState(HS_INITIALISE); SetHSFlags(HS_UPDATE); } // send a string void SendHSString(const string msg) { byte mlen = ArrayLen(msg); SetHSOutputBuffer(0, mlen, msg); SetHSOutputBufferOutPtr(0); SetHSOutputBufferInPtr(mlen); SetHSState(HS_SEND_DATA); SetHSFlags(HS_UPDATE); //send it } // send an integer void SendHSNumber(const int value) { string msg = NumToStr(value); SendHSString(msg); } // receive a string bool ReceiveHSString(string &s) { byte inPtr = 0; int timeout = 0; byte event = 0; string buffer; SetHSInputBufferInPtr(0); SetHSInputBufferOutPtr(0); while(event == 0) { inPtr = HSInputBufferInPtr(); timeout++; if (inPtr!=0) event = 1; if (timeout>MS_500) event = 2; } if (event == 1) { GetHSInputBuffer(0, inPtr, buffer); s = buffer; return true; } else { return false; } } // receiver an integer bool ReceiveHSNumber(int &n) { string buffer; if (ReceiveHSString(buffer)) { n = StrToNum(buffer); return true; } else return false; } #endif task main() { SetHSPort(); int val = 0; while (true) { SendHSNumber(val); val++; } }
Das Problem steckt (soweit ich es lokalisieren konnte) in der Funktion ReceiveHSString, und zwar im Befehl inPtr = HSInputBufferInPtr();Code: Select all
task main() { SetHSPort(); int val; bool check; while (true) { check = ReceiveHSNumber(val); NumOut(0,0,val,true); } }
Wenn ich diesen Befehl auskommentiere, dann kommt kein Fehler.
Mit der Lego-Firmware und ausgeschalteter Enhanced-FW-Compileroption funktioniert alles wie gewünscht, ich vermute mal dass der Compiler da Mist baut.