Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

C# beginner question

933 Views - Created 28/10/2020

28/10/2020

Posted by:
thermos

thermos Avatar

Hey, I'm new to electronics and microcontrollers.
I downloaded your ABE_Helper & IOPI from Github.
I'm using raspberry pi 3b+ with your IOPI Plus that has 16 channel relay switch connected to bus 1 and 16 channel relay switch connected to bus 2 they are both a low-level trigger.
What I want to do at the start of the application is to set the port direction to "input" because I want to modify the pin state, then I have to set port pullups to 0x00 so it will trigger the state, and then I just write 0xFF//0x00 to given port?

I wanted to test the logic and set half of the pins state to 0 and a half to 1..
private void OnBusConnected(object sender, EventArgs e)
{
var bus = (IOPi)sender;

//PORT A
bus.SetPortDirection(0, 0x00);
bus.SetPortPullups(0, 0x00);
bus.WritePort(0, 0xFF);

//PORT B
bus.SetPortDirection(1, 0x00);
bus.SetPortPullups(1, 0x00);
bus.WritePort(1, 0x00);
}

Is my logic correct? Because it does absolutely nothing. I tried to make it clear but please say if I have to clear something out.

28/10/2020

Posted by:
andrew

andrew Avatar

Location:
United Kingdom

andrew Twitter  andrew Website  

Hello

Are you using our .net core library with your C# project? If so then we have two demo files for reading the status of the ports on the IO Pi Plus and writing values to the outputs of each port.

The code you have posted is setting the ports to be outputs and turning all of the pins to a high state so they will be outputting 5V on each pin.

To use the ports as inputs you will need to set the port direction to 0xFF. bus.SetPortDirection(0, 0xFF); To read the value from a port you would use the ReadPort or ReadPin functions.

We have a series of tutorials in our knowledge base for the IO Pi Plus. It may be worth reading through the tutorials to get a better understanding of how the IO Pi Plus works. The tutorials use the Python programming language but the principles are the same across all of our supported programming languages.

The main difference between our python and .net core C# libraries is the naming convention for the functions. In Python, the functions are lowercase with underscores separating the words while in C# the functions are capitalised with no underscores so the set_pin_direction in Python becomes SetPinDirection in C#.

Sign in to post your reply

Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view, download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.