Thanks @dezsoe, thats what I needed! I sawed this before making this question but didnt realized that "bit" is used in the function and not "1 << bit".
If helps someone, this is my code to map port and pin to and int that can be used in the C# API:
- Code: Select all
/// <summary>
/// Maps port and pin output to bit identifier
/// </summary>
/// <param name="port">Target pin port</param>
/// <param name="pin">Target pin</param>
public static int MapPinToAxbbOutputBit(int port, int pin)
{
switch (port)
{
case 1:
switch (pin)
{
case 1:
return 26;
case 2:
return 47;
case 3:
return 31;
case 4:
return 32;
case 5:
return 29;
case 6:
return 30;
case 7:
return 27;
case 8:
return 2;
case 9:
return 22;
case 10:
return 21;
case 11:
return 20;
case 12:
return 19;
case 13:
return 18;
case 14:
return 17;
case 15:
return 10;
case 16:
return 11;
case 17:
return 25;
}
break;
case 3:
switch (pin)
{
case 1:
return 38;
case 2:
return 34;
case 3:
return 48;
case 4:
return 4;
case 5:
return 43;
case 6:
return 42;
case 7:
return 16;
case 8:
return 15;
case 9:
return 5;
case 14:
return 35;
case 16:
return 3;
case 17:
return 33;
}
break;
}
#if DEBUG
Debugger.Break(); //Break in DEBUG mode if available
#endif
return 0;
}
/// <summary>
/// Maps port and pin input to bit identifier
/// </summary>
/// <param name="port">Target pin port</param>
/// <param name="pin">Target pin</param>
public static int MapPinToAxbbInputBit(int port, int pin)
{
switch (port)
{
case 2:
if (pin >= 1 && pin <= 6)
return pin;
break;
case 3:
if (pin >= 10 && pin <= 13)
return pin - 3;
if (pin == 15)
return 11;
break;
}
#if DEBUG
Debugger.Break(); //Break in DEBUG mode if available
#endif
return 0;
}
/// <summary>
/// Sets the sate of the output pins to high level.
/// </summary>
/// <param name="Num">Integer number in which every bit represents one output pin.(0-63)</param>
/// <returns>ReturnVal, UC error code.</returns>
[DllImport("UC100.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int SetOutputBit(int Num);
public static int SetOutputBit(int port, int pin)
{
return SetOutputBit(MapPinToAxbbOutputBit(port, pin));
}
/// <summary>
/// Sets the sate of the output pins to low level.
/// </summary>
/// <param name="Num">Integer number in which every bit represents one output pin.(0-63)</param>
/// <returns>ReturnVal, UC error code.</returns>
[DllImport("UC100.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int ClearOutputBit(int Num);
public static int ClearOutputBit(int port, int pin)
{
return ClearOutputBit(MapPinToAxbbOutputBit(port, pin));
}
Whit this code its possible to call:
- Code: Select all
UC100.ReturnVal ret = (UC100.ReturnVal)UC100.SetOutputBit(TargetPort, TargetPin); //Set bit
Just one last thing (for now hahahaha): in your map you uses the bit input starting in 1 and in reality it starts in 0. According to my tests, if I use "(UC100.ReturnVal)UC100.GetOutput(ref outs)" and checks for bit 1 in "outs" it gives you the state of pin 2 of port 2.