Shop OBEX P1 Docs P2 Docs Learn Events
Sample code in C for controlling PSC serial — Parallax Forums

Sample code in C for controlling PSC serial

rockerboyrockerboy Posts: 14
edited 2007-11-16 20:57 in General Discussion
Hi,

Is there any sample code in C for controlling PSC serial available from Parallax?

Thanks,

Comments

  • FranklinFranklin Posts: 4,747
    edited 2007-11-12 06:27
    Probably not. All you need is to send to the PSC the strings it wants to hear. You can find those in the documentation.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • rockerboyrockerboy Posts: 14
    edited 2007-11-13 00:36
    Franklin said...
    Probably not. All you need is to send to the PSC the strings it wants to hear. You can find those in the documentation.

    Ok. But if I send it '!', 'S', 'C', etc using the below C code, the PSC is not responding.
    ·
    C Code...
    unsigned char c;
    c = '!';
    write(PSC_sd, &c, 1);
    c = 'S';
    write(PSC_sd, &c, 1);
    c = 'C';
    write(PSC_sd, &c, 1);
    c = 0x00;
    write(PSC_sd, &c, 1);
    c = 0x0F;
    write(PSC_sd, &c, 1);
    c = 0xE2;
    write(PSC_sd, &c, 1);
    c = 0x4;
    write(PSC_sd, &c, 1);
    c = '\n';

    write(PSC_sd, &c, 1);


    So, I was wondering what I could send it to make it behave similar to if I program it using BASIC with:
    Basic Code...
    ····
    ···· ramp = $F············ ' Ramp (speed)
    ···· servoAddr = 0········ ' Channel 0
    ···· position = 1250

    ··· SEROUT PSC,N2400,[noparse][[/noparse]"!SC",ServoAddr, Ramp,position.LOWBYTE, position.HIGHBYTE, CR]
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-13 01:14
    The problem is that we have no idea how your C system works and the specifics of how I/O works in your C implementation is crucial to getting this to work. You'll just have to sit down with your manuals to figure out how to properly open a serial device at 2400 Baud, 8 bits, non-inverted logic. We can't tell you how to do that.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-11-13 04:53
    Attached· are a few Javelin classes (Javelin java is almost like C) that you can
    open in any text editor.
    The Javelin uses the Uart object to open a serial channel. Like Mike said,
    you need to figure out how to open a serial port on your system.
    Apart from that, the remaining code should be useful.

    Edit: The javelin integers are 16bit signed. Keep that in mind when converting code
    to your system, as that may well use 32bit integers.

    regards peter

    Post Edited (Peter Verkaik) : 11/13/2007 5:20:21 AM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-11-16 20:57
    There is an example of C communication with the PSC in our Completed Projects Forum. Please see the link below. I hope this helps. Take care.

    http://forums.parallax.com/showthread.php?p=611904


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.