doc-helmut wrote:I currently don't understand your remote commands, I am just trying to translate my code for a NXT which controls local IOs into a code which will control remote IOs on a remote NXT.
So the task still runf locally on the master, but the sensors and motors are attached to a remote NXT (slave).
But what does your MotorOff function do? For now, I'll assume it does the same as Coast. I think the following is what you want:
Code: Select all
#include "MyRS485MuxMaster lib 0.02.nxc"
inline void MotorOff(byte slave, byte port)
{
MuxCoast(slave, port);
}
char CmdRdy;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
task OUT_A_md() {
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
char speed ;
speed=100;
CmdRdy=false;
MotorOff(RS485MuxSlave1, OUT_A);
Wait(1);
while(!(MuxSensor(RS485MuxSlave1, S2))) {
if(MuxSensor(RS485MuxSlave1, S1)) speed=-100;
MuxOnFwd(RS485MuxSlave1, OUT_A, speed);
Wait(1);
if (MuxSensor(RS485MuxSlave1, S2)) { // dn pos = S1
MotorOff(RS485MuxSlave1, OUT_A);
speed=0;
Wait(50);
}
}
MuxCoast(RS485MuxSlave1, OUT_A);
CmdRdy=true;
Wait(1);
}
However, you will need my latest version (attached) in order to use that without modification. Also remember to setup the sensors on the slave (you can do it remotely using MuxSetSensorType, MuxSetSensorMode, and MuxSetSensor).
Included in the examples are some first attempts at user-data transmissions. So far sending user-data seems to work fine. In the master example, press the orange button to initiate the transfer (state of three NXT buttons). The master will send it's data (buttons states), and the slave will return it's own data (it's buttons states). This will have an effect on the Mux, but it should only effect the timing (present a slight delay in updates, so that the user-data can be transferred). This is all done automatically, so don't worry about it too much.
I also implemented an 8-bit checksum on all messages, to spot transmission errors (shouldn't ever happen on a wired connection, but you never know). So there are now 4 bytes overhead on all messages.
If an NXT detects an error in the checksum, it will discard the message as if it was sent to a different NXT.
If the slave NXT doesn't receive any valid communication for more than n number of ms (default 500), it will go into a timed out state (float the motors, and clear the active flag).