I'm having a little issue to get my calc to talk to a Python program.

I'm using PyTICables, made by Kllrnohj, to get Python to use libticables and talk to the calc.

The Z80 program, compiled with SPASM and used ti83plus.inc with added "_SendAByte equ 4EE5h":


Code:
#include "ti83plus.inc"
#define B_CALL(xxxx)   rst 28h \ .dw xxxx
#define B_JUMP(xxxx)  call 50h \ .dw xxxx

.org 40339
.db t2ByteTok, tAsmCmp

main:
  B_CALL(_ClrLCDFull)
  res donePrgm,(iy+doneFlags); FDCB00AE
  B_CALL(_ClrLCDFull)           ;Clear the screen
  B_CALL(_GrBufClr)        ;Clear all values in the graph buffer
  B_CALL(_ClrLCDFull)           ;Clear the screen
 
  ;di
 
  xor a
  ld a,0000h
 
  B_CALL(_SendAByte)

  xor a
  ld a,0000h
 
  B_CALL(_SendAByte)
  xor a
  ld a,0000h
 
  B_CALL(_SendAByte)
  xor a
  ld a,0000h
 
  B_CALL(_SendAByte)

  ;ei
 
  ld hl,0000h              ;Load 0 to hl register
  ld (PENCOL),hl                   ;Load hl value to Pencol
  ld hl,0
  ld (penRow),hl
  ld hl,strdone
  B_CALL(_VPutS)         ;Put text on homescreen
  B_CALL(_GetKey)
  B_CALL(_ClrLCDFull) ; Clear screen
  B_CALL(_HomeUp)
  ret
 
strdone:
  .db "Sent, press any key...",0
 
strsend:
  .db 0000,0


The Python program:


Code:
import time
import ticables
c = ticables.Cable(ticables.CABLE_USB,1)
print "Opening connection..."
c.open()
testbuf = "#h\x00\x00"
print "Sending..."
err = c.send(testbuf)
# Check for success...
if err != 0:
        print "Error sending"
c.show()
#print "Resetting cable..."
#c.reset()

print "Recieving..."
while 1==1:
        data = c.recv(2)
        if data[0] != 0:
                print "ERROR: Recv failed with error code "+str(data[0])
                print "Retry in 2 seconds"
                time.sleep(2)
        else:
                print data


The magical error:

Code:

ticables-INFO: ticables library version 1.3.0
ticables-INFO: setlocale: en_US.utf8
ticables-INFO: bindtextdomain: /usr/share/locale
ticables-INFO: textdomain: libticables2
ticables-INFO: kernel: 2.6.32-23-generic
Opening connection...
ticables-INFO: Check for lib-usb support:
ticables-INFO:     usb support: available.
ticables-INFO: Check for lib-usb usability:
ticables-INFO:     usb filesystem (/dev/bus/usb/): mounted
ticables-INFO:  found TI-84 Plus Silver Edition on #1, version <1.10>
Sending...
(ii)Len: 4
(ii)Data: 35  104  0  0
Recieving...

(process:20571): ticables-WARNING **: usb_bulk_read (No error).

ERROR: Recv failed with error code 4
Retry in 2 seconds

(process:20571): ticables-WARNING **: usb_bulk_read (No error).

ERROR: Recv failed with error code 4
Retry in 2 seconds


Screenshot: (click to enlarge)


Any idea how to fix this? I'm a noob at Z80 programming and TI calc communication, so please don't assume I know everything! Smile
From a super-duper naive standpoint about how Kllrnohj implemented the library, it sounds to me like the library didn't successfully connect to the calculator (ie, find the link cable and initialize the connection to the endpoint). Are there other initialization functions?

Kllrnohj is gonna be your best bet on this, though.
Yeah, uh... hell if I know.

So PyTICables is a wrapper on top of libticables (I think 1, not 2). You'd have to check what error code 4 is in libticables.

Where did you find PyTICables anyway? I have no idea where the source to that is, or even the version I released. Does it have the source?

@Kerm: No, you can see it found a calulator in the call to open, and it thinks it sent correctly.

Does the data sent arrive on the calculator?
I'm going to guess that error 4 is a timeout. As BrandonW mentioned on IRC, _SendAByte only works over I/O, not DUSB.

It's hardly surprising that the computer sees nothing, since it's not being sent anything. Smile
Kllrnohj wrote:
Yeah, uh... hell if I know.

So PyTICables is a wrapper on top of libticables (I think 1, not 2). You'd have to check what error code 4 is in libticables.

Where did you find PyTICables anyway? I have no idea where the source to that is, or even the version I released. Does it have the source?
I can't find a release of it anywhere. O_O That includes http://www.cemetech.net/gcn, by the way.

Kllrnohj wrote:
@Kerm: No, you can see it found a calulator in the call to open, and it thinks it sent correctly.

Does the data sent arrive on the calculator?
Ah, ok.
The Tari wrote:
I'm going to guess that error 4 is a timeout. As BrandonW mentioned on IRC, _SendAByte only works over I/O, not DUSB.

It's hardly surprising that the computer sees nothing, since it's not being sent anything. Smile


Ah, right. I think I had to use the silverlink cable because the direct USB cable wasn't supported by ticables at the time.

And yeah, error 4 probably is a timeout. I really like that it logs a warning that there was no error, too, that's full of win.

KermMartian wrote:
I can't find a release of it anywhere. O_O That includes http://www.cemetech.net/gcn, by the way.


I found the source, actually, it's here on my server: http://kllrnohj.com/cemetech/gCn2/py_ticables/ticables_module.c
I enjoyed that as well; it seemed like one of those classic blooper screenshots that you see, along the lines of this one:
Ahh, that magical error, eh? Very Happy

I've compiled it myself, and used some interesting code found here: http://www.cemetech.net/forum/viewtopic.php?t=1174&view=previous (WARNING: 4 year old post!)
alberthrocks wrote:
Ahh, that magical error, eh? Very Happy

I've compiled it myself, and used some interesting code found here: http://www.cemetech.net/forum/viewtopic.php?t=1174&view=previous (WARNING: 4 year old post!)


Sweet, my 4 year old code still looks fairly sane and solid - I rock.

Are you compiling against tilp2's libticables 2? Does the version you are compiling against support direct usb? Does the sample snippet I had work? That should be a command the TI OS recognizes, although you'll notice I specifically talked about silverlink - I don't remember if I tested direct usb.
Yes, yes, no (if you're referring to the one that checks for readiness).

My own ASM program doesn't communicate via direct USB, so it will obviously fail.

Your program worked with some modifications - see here:
ticables_module.c:

Code:
--- ticables_module.c   2010-07-30 01:22:05.000000000 -0400
+++ ticables_module_fixed.c   2010-07-30 01:28:04.000000000 -0400
@@ -59,7 +59,6 @@
       case CABLE_USB: return Py_BuildValue("s", "Direct USB");
       case CABLE_VTI: return Py_BuildValue("s", "VTi");
       case CABLE_TIE: return Py_BuildValue("s", "TiEmu");
-      case CABLE_VTL: return Py_BuildValue("s", "virtual");
       default: break;
    }
    return Py_BuildValue("i", mnum);
@@ -241,7 +240,6 @@
    PyModule_AddIntConstant(m, "CABLE_SLV", CABLE_SLV);
    PyModule_AddIntConstant(m, "CABLE_VTI", CABLE_VTI);
    PyModule_AddIntConstant(m, "CABLE_TIE", CABLE_TIE);
-   PyModule_AddIntConstant(m, "CABLE_VTL", CABLE_VTL);
    PyModule_AddIntConstant(m, "CABLE_ILP", CABLE_ILP);
    PyModule_AddIntConstant(m, "CABLE_MAX", CABLE_MAX);
 }


setup.py:

Code:
--- setup.py   2010-07-30 01:26:34.000000000 -0400
+++ setup2.py   2010-07-30 01:28:21.000000000 -0400
@@ -6,7 +6,7 @@
                     include_dirs = ['/usr/include/tilp2'],
                     libraries = ['ticables2'],
                     library_dirs = ['/usr/lib'],
-                    sources = ['ticables_module.c'])
+                    sources = ['ticables_module_fixed.c'])
 
 setup (name = 'PackageName',
        version = '1.0',


It seems that CABLE_VTL has been removed from TiLP?
Albert, what if you put the calculator at the homescreen and send the normal device ping packet over direct USB?
Still doesn't work:


Code:
arthur@arthur-PC:~/pyticables/build/lib.linux-i686-2.6$ python test.py -p
ticables-INFO: ticables library version 1.3.0
ticables-INFO: setlocale: en_US.utf8
ticables-INFO: bindtextdomain: /usr/share/locale
ticables-INFO: textdomain: libticables2
ticables-INFO: kernel: 2.6.32-23-generic
Opening connection...
ticables-INFO: Check for lib-usb support:
ticables-INFO:     usb support: available.
ticables-INFO: Check for lib-usb usability:
ticables-INFO:     usb filesystem (/dev/bus/usb/): mounted
ticables-INFO:  found TI-84 Plus Silver Edition on #1, version <1.10>
Doing ping test, as requested with arg -p....
Sending...
(ii)Len: 4
(ii)Data: 35  104  0  0

(process:6595): ticables-WARNING **: usb_bulk_read (No error).

ERROR: Recv failed with error code 4
arthur@arthur-PC:~/pyticables/build/lib.linux-i686-2.6$


Modified my python code:

Code:
import sys
import time
import ticables
c = ticables.Cable(ticables.CABLE_USB,1)
print "Opening connection..."
check = c.open()
if check != 0:
   print "Error opening calc! Please connect it and then try again!"
   exit(1)
if (len(sys.argv) > 1 and sys.argv[1] == '-p'):
   print "Doing ping test, as requested with arg -p...."
   testbuf = "#h\x00\x00"
   print "Sending..."
   err = c.send(testbuf)
   # Check for success...
   if err != 0:
      print "Error sending"

   data = c.recv(4)

        if data[0] != 0:
                print "ERROR: Recv failed with error code "+str(data[0])
        else:
                print data
   exit()

c.show()
#print "Resetting cable..."
#c.reset()

print "Recieving..."
while 1==1:
   data = c.recv(2)
   if data[0] != 0:
      print "ERROR: Recv failed with error code "+str(data[0])
      print "Retry in 2 seconds"
      time.sleep(2)
   else:
      print data
Just an idea, but when python is available for the nspire....., would it be possible to enhance this somehow?

The Tari wrote:
I'm going to guess that error 4 is a timeout. As BrandonW mentioned on IRC, _SendAByte only works over I/O, not DUSB.

It's hardly surprising that the computer sees nothing, since it's not being sent anything. Smile

The receive fails because the calculator is not sending anything over USB. You either need to modify your calculator-side code to send something via USB or use an I/O link cable (silverlink, blacklink, greylink...).
The Tari wrote:
The Tari wrote:
I'm going to guess that error 4 is a timeout. As BrandonW mentioned on IRC, _SendAByte only works over I/O, not DUSB.

It's hardly surprising that the computer sees nothing, since it's not being sent anything. Smile

The receive fails because the calculator is not sending anything over USB. You either need to modify your calculator-side code to send something via USB or use an I/O link cable (silverlink, blacklink, greylink...).
Which post was that in reference to? If you were talking about the ping test, that was over DUSB but with the calc at the homescreen, where it would happily reply over DUSB.
Bluh?

Writing \x00\x00 to the thing via USB doesn't look like a valid packet that TI-OS will respond to to me. Could be horribly mistaken, though.
The Tari wrote:
Bluh?

Writing \x00\x00 to the thing via USB doesn't look like a valid packet that TI-OS will respond to to me. Could be horribly mistaken, though.
No, I believe you're write. There's some DUSB-specific information here:

http://merthsoft.calcg.org/linkguide/usb-protocol.txt

For the ping though, I was thinking of a packet type like $68 (ChkRdy), as detailed here:

http://merthsoft.calcg.org/linkguide/ti83+/packet.html
You mean *right*, right? Smile

What should I send then?
And I know that _SendAByte doesn't work on DirectUSB. Wink
KermMartian wrote:
The Tari wrote:
Bluh?

Writing \x00\x00 to the thing via USB doesn't look like a valid packet that TI-OS will respond to to me. Could be horribly mistaken, though.
No, I believe you're write. There's some DUSB-specific information here:

http://merthsoft.calcg.org/linkguide/usb-protocol.txt

For the ping though, I was thinking of a packet type like $68 (ChkRdy), as detailed here:

http://merthsoft.calcg.org/linkguide/ti83+/packet.html


ChkRdy IS the packet being sent, you both fail - it isn't \x00\x00. Did you miss the sending 4 bytes part?

But again, Tari is right that the protocols are completely different. So either use a silverlink or learn the USB protocol.
Kllrnohj wrote:
KermMartian wrote:
The Tari wrote:
Bluh?

Writing \x00\x00 to the thing via USB doesn't look like a valid packet that TI-OS will respond to to me. Could be horribly mistaken, though.
No, I believe you're write. There's some DUSB-specific information here:

http://merthsoft.calcg.org/linkguide/usb-protocol.txt

For the ping though, I was thinking of a packet type like $68 (ChkRdy), as detailed here:

http://merthsoft.calcg.org/linkguide/ti83+/packet.html


ChkRdy IS the packet being sent, you both fail - it isn't \x00\x00. Did you miss the sending 4 bytes part?

But again, Tari is right that the protocols are completely different. So either use a silverlink or learn the USB protocol.


I'm assuming that libticables can send the bytes with the DirectLink USB protocol...?
  
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