Resolved NSLog to Serial port?

Discussion in 'iOS Programming' started by xArtx, Oct 15, 2013.

  1. xArtx, Oct 15, 2013
    Last edited: Oct 15, 2013

    xArtx macrumors 6502a

    Joined:
    Mar 30, 2012
    #1
    Hi Guys,
    I want to do a program to pre-compute a list of rotated point coordinates
    for a microcontroller that has no trig, and only integer math.
    The easiest way for me to go right now, would be to do it on an iOS device.
    In fact, the program is mostly already written for iPhone.

    I have an iOS sample that removes the prefix from NSLog console,
    so I was able to do some output once, and cut/paste it for a csv file.

    Is there a way to send NSLog directly through a Mac's serial port?
    I realise sending serial from the iOS device requires a jailbreak program,
    but also suspect that NSLog strings are sent to Xcode through a USB
    serial port from the test device.

    I can cut and paste into a Windows terminal, and send data to the chip that way,
    but directly from the Mac would be easier.
    Cheers, Art.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    You have access to a Mac. You can write the code to do this on iOS so can write Objective-C. Why can't you simply run that code on the Mac (as Mac OSX code)?
     
  3. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #3
    It does seem the logical way, but it is whatever other learning curve
    if any, I'd prefer to avoid.
    I can't even pretend to be interested in desktop computers from a programmer's point of view,
    but if it is that easy I should take a look.

    I thought there might be some simple setting, but I can also see why there
    might not be, since Xcode provides the console screen you'd normally be
    using a serial port for.
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    I think it's an unusual enough demand that there is no such setting...
     
  5. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #5
    I forgot it's a microcontroller at the receiving end.
    I'll read a spot of light from the iPhone screen or camera flash :)
    So long as it maintains framerate, sending the data is all it has to do at the time.
     
  6. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
  7. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #7
    Ok, thanks, redirecting stdout to file... the site also brings to light the
    reason why anyone else would care.

    For jailbroken iPhone direct serial port you need at least a MAX232 or
    similar powered level converter.
    To read from the camera flash you would also minimally need one chip.

    An App called iTorch Pro can strobe the camera flash accurately at a
    variable rate between 1 - 29 Hz.

    IT Crowd Season One DVD (Extras) reveals how to read the data they
    have embedded into one of their episodes this way.

    RS232 serial has less known standard baud rate 300 baud.

    I think developer iDevice serial port is a done deal,
    and additionally that nothing can be done about it.
    The bit banging routine sending the data isn't the real serial port the platform's hackers want though.



     
  8. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #8
    The original issue I'd say is resolved, thanks.
    There is some learning curve, but that is probably worth it.

    In this thread I mentioned I was creating a csv file with NSlog.
    I inserted the comma delimiters, etc, in the NSlog lines,
    stripped the NSlog headers, so it could be cut and pasted.
    It seems now, that an iOS device while connected to Xcode,
    with no funny business, could directly produce the csv file (as a file).

    Some unexpected learning.. I've got the serial USB dongle,
    but have to learn how to find out whether or not the Mac knows it's there, etc.
     
  9. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #9
    If you want formatted output, the C library function printf() is a better choice than NSLog. It does not included the prefix of each line. Remember that you need to add a "\n" at the end of each line.

    You can also use sprintf() to build your output in a (C) string, or fprintf() to write your output directly to a file. To use fprintf() you would need to use C functions to open the file.

    That code will be identical on both Mac and iOS, other than the pathnames you would write to.
     
  10. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #10
    What type of USB-to-serial adapter is it? There are two common chips used for this a Prolific PL2303, and an FTDI FT232.

    You can usually identify the chip using System Information.app > USB, and then look for a serial device (aka UART).

    Drivers for both chips are downloadable from the chip mfgrs and other places.

    At the Terminal command-line, try this command:
    Code:
    ls -l /dev/cu.*
    
    A "cu" device is the "calling unit" for a serial port, described here:
    http://stackoverflow.com/questions/8632586/macos-whats-the-difference-between-dev-tty-and-dev-cu
     
  11. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #11
    Thanks, it does recognise that it is a Prolific chip.
    I never installed the driver for Mac,
    so maybe the latest update already knows about this chip.

    Thanks Duncan, I should have known that. I have another project with "Dlog",
    which is just a redefined printf.

    I didn't end up pre-computing points...
    doing it for another platform might be cheating a bit for a demo.

    Got Hack-A-Day front page feature with this :)

    http://www.youtube.com/watch?v=1xq8xJqbkNA

    There is difficulty in sending the framebuffer to a character LCD not designed for graphics.
    Also, the 3D cube would have consumed the entire 2K chip,
    and been the only section of the demo.
     
  12. xArtx thread starter macrumors 6502a

    Joined:
    Mar 30, 2012
    #12
    That was dumb..
    Instead of sending the data over serial,
    I might as well format the string that is sent with log
    as a lookup table, or array declaration to paste directly into the other compiler.
     

Share This Page