Shop OBEX P1 Docs P2 Docs Learn Events
program Modbus on C? — Parallax Forums

program Modbus on C?

p02osmajp02osmaj Posts: 14
edited 2014-03-28 16:15 in Learn with BlocklyProp
Hello everyone, first I'm spanish, so my english is not very good and if you want to correct me anything .. great for me :D

Ok, I want to do a program that control 8 servos of a robot, and I want to do it in C because is the only language that I know. I need to do a Modbus comunication, but I don't see any library about it (for Modbus).
I want to ask you if I can do it,
and if I can not: if I can do that part of program in SPIN (part of Modbus comunication), and programme in C the rest of the program that control the servos and so on.
I don't know if exist any "linker" to be able me to programme in two different languages an unique program.

Thank you ! ;)

Comments

  • PublisonPublison Posts: 12,366
    edited 2014-03-25 07:53
    Welcome to the forums!

    There are two objects in the OBEX for ModBus:

    http://obex.parallax.com/search/Modbus

    I'm not sure these will help as I do not know ModBus or C. :)
  • kwinnkwinn Posts: 8,697
    edited 2014-03-25 20:27
    ModBus is basically an asynchronous serial data protocol so no reason it cannot be done in C. If there is a C version of any of the serial objects then it should be relatively straight forward to convert the objects from the link in post 2 to C.
  • edited 2014-03-26 17:27
    A C language example ported from the http://obex.parallax.com/object/706 Spin files is attached. The example monitors the Propeller QuickStart board's capacitive touch sensors, and writes to the bus (as far as I can tell). I used spin2cpp to port it to C, and then manually modified it to make it more compatible with SimpleIDE and the Learn folder's libraries.

    Make sure to unzip first. Then, use SimpleIDE to open ModBus Slave Test.side. It should compile, but I do not have hardware to test it. If you do not have SimpleIDE, get it here:

    http://learn.parallax.com/propeller-c-set-simpleide

    To get more familiar with other Propeller C libraries and features, I recommend going through these tutorials:

    http://learn.parallax.com/propeller-c-tutorials

    Andy
  • edited 2014-03-26 17:46
    P.S. I'm assuming that you are controlling industrial servos through the Modbus.

    If these are hobby servos, you can also use the Propeller to control them directly. It would only take one of the Propeller chip's eight processors. Code running in that one processor would control all eight servos. An example of one servo is here:

    http://learn.parallax.com/propeller-c-simple-devices/standard-servo

    That example can be modified like this:

    ...
    servo_angle(14, 900); // P14 servo to 90-degrees
    servo_angle(15, 1200); // P15 servo to 120 degrees
    servo_angle(16, 300); // P16 servo to 30 degrees
    ...

    The servo library launches code into another processor that takes care of the servo signalling. The library also keeps track of which I/O pins are sending which signals.
  • p02osmajp02osmaj Posts: 14
    edited 2014-03-27 13:11
    Yes ! I have to control industrial servos!
    Industrial servos need one cog each one? or can be used one cog for all of them?
  • edited 2014-03-27 14:05
    If your propeller is on the Modbus, it looks like it just sends messages to something else on the bus, and that device takes care of the servo control.

    I do not know the control signal protocol for the servos you are using. If it is identical to the hobby servos (probably not), it would take just one processor. How many processors it would take depends on the signaling. I'm assuming it could all be fit into a single processor, but it might take some custom code, which can be time consuming to develop.

    Since you already have Modbus code, might as well give it a try first.

    Andy
  • p02osmajp02osmaj Posts: 14
    edited 2014-03-28 16:15
    Thank you all!

    The servors are Panasonic Minas Liqi
Sign In or Register to comment.