c# examples

General discussion of using Roboclaw motor controllers
Post Reply
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: c# examples

Post by Basicmicro Support »

There is not a full example but the C# RoboclawClassLib handles all the work if you are using C#.

http://downloads.ionmc.com/code/RoboclawClassLib.zip

Add a reference to the class library or add the whole project to your solution.
Create a Roboclaw instance with the appropriate comport settings.
Open() the board.

All the packet serial commands are wrapped in C# functions. Once you open the board you can use any of the functions as needed.

Note the class library also support CAN support on the MCP models so ignore the can specific functions when using with a Roboclaw board.
ianlee74
Posts: 9
Joined: Wed Nov 30, 2016 9:20 am
Re: c# examples

Post by ianlee74 »

@acidtech - is there any way to use this with multi-unit mode? It seems the functions are targeted for use with a single board.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: c# examples

Post by Basicmicro Support »

Its the same library Ion Studio uses, so yes you can use it with multi-unit mode.

The class library handles dealing with multiple Roboclaws on the same serial port behind the scenese. All you have to do is make sure you have different packet serial addresses set for each roboclaw that is on the same serial port and then create Roboclaw instances for each of them.

Remember that Roboclaws are TTL serial, not RS-232 so you will need to wire up a converter if using a regular serial port or you will need to use a USB to TTL adapter.

Also remember that with multi-unit mode you need 1 pullup(between 1k and 10k) on the RX line(eg the line conencted to all the S2 pins of the Roboclaws).
ianlee74
Posts: 9
Joined: Wed Nov 30, 2016 9:20 am
Re: c# examples

Post by ianlee74 »

Ah.. Ok. Needing multiple RoboClaw instances is what I was missing. Thanks.

Also, one annoying thing about IonStudio... Just having it open appears to lock the COM port even if I don't have it connected to the controller. So, in order to run this demo code I have to fully close IonStudio first. This is a nuisance when I need to go back & forth between the two.

Thanks!
Ian
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: c# examples

Post by Basicmicro Support »

Yes, unfortunately Ion Studio has to poll the comports where Roboclaws are to determine if any slave Roboclaws have been attached to a Roboclaw(eg using Relay mode) to keep the device list up to date even when not "connected" to the Roboclaw. We will be going back through that code as some point in the future to hopefully streamline it a bit more.

Post Reply