I've got a small chunk of libticables ported to a python module (send/receive are coded, reset, check, probe, etc... aren't Wink ) The rest shouldn't take TOO long, as it is much simpler stuff (for example, check is a small function, and something like show_handle is pretty much worthless)

Anyway, here is the source:

http://www.kllrnohj.com/cemetech/gCn2/py_ticables/ticables_module.c

To compile it you need to make a setup.py script, then do "python setup.py build" (the compiled module will be in build/lib*), mine is as follows:


Code:
from distutils.core import setup, Extension

ticables = Extension('ticables',
                    define_macros = [('MAJOR_VERSION', '1'),
                                     ('MINOR_VERSION', '0')],
                    include_dirs = ['/usr/include/tilp2'],
                    libraries = ['ticables2'],
                    library_dirs = ['/usr/lib'],
                    sources = ['ticables_module.c'])

setup (name = 'PackageName',
       version = '1.0',
       description = 'TiCables linking module (beta)',
       author = 'Kllrnohj',
       author_email = 'kllrnohj@gmail.com',
       url = '',
       long_description = '''
Beta of libticables. Only partially implemented
''',
       ext_modules = [ticables])


Note: Change include_dirs (location of ticables.h) and library_dirs (location of libticables.so) for your system (i have yet to try this in windows)

Here is a small example that does a simple RDY?/ACK send/recv over the silverlink cable on port 1 for an 83+/84+


Code:
import ticables
c = ticables.Cable(4,1) #SilverLink, Port1
c.open() #open the connection
buf = "#h\x00\x00" #similar to "uint8_t buf[] = {0x23,0x68,0x00,0x00}" - 0x23 = PC->83+/84+, 0x68 = RDY? command
err = c.send(buf) #err = 0 on success
data = c.recv(4) #4 = length, data will be (err, buf), err = 0, buf = "sV\x00\x08" on success


I need to port the rest (or most) of the ticables.h functions over, then create a python wrapper script to make it easier to use send/recv (for example, make it so it can send/recv a list instead of a string - which is much harder to do from the C side as far as I can tell...)

If you find any errors please send me the code you were trying to run AND all the output's (including all of the ticables outputs)
Good Idea Excellent job! The moment school is over and I move into my new apartment, I'll get going on this. Smile
Updated: http://www.kllrnohj.com/cemetech/gCn2/py_ticables/ticables_module.c

its now a bit eaiser to setup the cable. instead of


Code:
c = ticables.Cable(4,1)


you can do


Code:
c = ticables.Cable(ticables.CABLE_SLV, 1)


the full list of constants that are defined are the same as those in ticables.h:


Code:
CABLE_NUL
CABLE_GRY
CABLE_BLK
CABLE_PAR
CABLE_SLV
CABLE_USB
CABLE_VTI
CABLE_TIE
CABLE_VTL
CABLE_ILP
CABLE_MAX


I've also ported over the following functions (these are all I plan on porting - and others, such as probe, i plan on doing python side):


Code:
    class Cable(__builtin__.object)
     |  CableHandle objects
     |
     |  Methods defined here:
     |
     |  __init__(...)
     |      x.__init__(...) initializes x; see x.__class__.__doc__ for signature
     |
     |  check(...)
     |      Check the link cable status.
     |
     |  get_delay(...)
     |      Return the delay
     |
     |  get_timeout(...)
     |      Return the timeout
     |
     |  model(...)
     |      Return the link cable name
     |
     |  model_num(...)
     |      Return the link cable ID number
     |
     |  open(...)
     |      Open the connection
     |
     |  port(...)
     |      Return the link cable port
     |
     |  recv(...)
     |      Receive data
     |
     |  reset(...)
     |      Reset link cable status (flush buffers, set ready).
     |
     |  send(...)
     |      Send data
     |
     |  set_delay(...)
     |      Set the delay
     |
     |  set_timeout(...)
     |      Set the timeout
     |
     |  show(...)
     |      Show informations stored in the handle.


And here is a small prototype function to convert a list to a string


Code:
def list_to_string(L):
     if (type(L) <> list):
             return ""
     ret = ""
     for i in L:
             ret += chr(i)
     return ret


and then the string to list conversion


Code:
def string_to_list(s):
     if (type(s) <> str):
             return []
     ret = []
     for i in s:
             ret.append(ord(i))
     return ret


please, PLEASE, try this out and let me know if you get any errors (and what they are) - debugging is always needed Very Happy
I hope you guys dont mind, but I feel like Kllrnohj is much better with Python than I am, and so I will hand my portion of this project over to him. I still accomplished my major goal of ensuring that it would be cross platform, and I will still compile the OS X build for you guys.

Keep up the good work.
elfprince13 wrote:
I hope you guys dont mind, but I feel like Kllrnohj is much better with Python than I am, and so I will hand my portion of this project over to him. I still accomplished my major goal of ensuring that it would be cross platform, and I will still compile the OS X build for you guys.

Keep up the good work.


wasn't THIS (meaning the python libticables module) your portion of the project? Razz

when Kerm finally gets a calc side gcn and the protocol gets locked down, i wouldn't mind having some help implementing that in Python though, if you wanna help still....
Good stuff. I plan to start that as soon as my summer vacation gets underway.
Heh, I never did get around to making the python wrapper for it to make it easier to use...oh well, so be it Very Happy

Hmm...think maybe I should submit this to ticalc? or do you think no one would care enough?
we do have a lot of Python programmers in the community, but most people wont use it.
You might as well; you nevre know when someone might have a use for it.
*UPDATE*: The new tilibs* release has DirectUSB support. This module (without any changes) fully supports it and should work just fine with a simple recompile to link against the new libs (it is dynamicly linked, but aparantly its no longer libticables.so.0 but libticables.so.1, so either a sym link or a recompile will work)
does this have to be compiled on each persons computer or can it be distributed as an .exe making it easier on us
read the first post Neutral
i know, but i do not feel like compiling and am sure many people do not have python, therefor they need it
for now you have to compile.

for later releases we will be using freeze/py2exe/py2app depending on your platform
gscm wrote:
does this have to be compiled on each persons computer or can it be distributed as an .exe making it easier on us


this is just a library, not a program. It is currently just a proof-of-concept, and servers no real function yet. The plan is for this to become a part of the GCN computer side client, in which case yes, there will be an .exe release for Win32. Elf will probably also provide a Mac binary. *nix users will likely have to compile, as it is not statically linked to libticables

So far this has just been tested on linux, mainly because there is no reason to test it on anything else yet, as there is no program that uses it.
oh ok then i will wait impatiantly for dcs 6 and the program
Laughing Same here. I hope it goes well for you, Kllrnohj.
Sorry for necro, but I wonder how you can close the current device so that it can be re-used without unplugging?
c.close() doesn't seem to exist and if I do c.reset() it still says that the calc is busy.
Sorunome wrote:
Sorry for necro, but I wonder how you can close the current device so that it can be re-used without unplugging?
c.close() doesn't seem to exist and if I do c.reset() it still says that the calc is busy.
Are you using libticables? I know how to close down a connection to a USB device with libusb, and re-open it, but no idea how to do it with libticables. Someone like Lionel or Jonimus would know.
KermMartian wrote:
Sorunome wrote:
Sorry for necro, but I wonder how you can close the current device so that it can be re-used without unplugging?
c.close() doesn't seem to exist and if I do c.reset() it still says that the calc is busy.
Are you using libticables? I know how to close down a connection to a USB device with libusb, and re-open it, but no idea how to do it with libticables. Someone like Lionel or Jonimus would know.
I was using until you mentioned on IRC that libticables has its own ti protocol, thanks anyways Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement