With CALCNet becoming so accessible to the less able programmer in the form of DCSB libs, I was pondering how easy it is to create a computer-side program for use with CALCNet? I am aware that the gCn client works with "bridges," and was wondering how I could actually go about making one for my own programs. I'm sure this information would be a lot of use to others too.
Ask and you shall receive! I have published an example bridge for globalCALCnet that includes almost everything you need. It connects to the metahub, identifies itself as a fake calculator, and begin accepting incoming messages. It also includes code to send messages out again, and has a logging library and an ASCII-to-calculator encoding conversion library. All you need to do is fill in the hub name and the application logic.

http://www.cemetech.net/programs/index.php?mode=file&id=909
Quick question, do you connect your calculator to the computer-side program using the global CALCnet client or do you use the bridge program?
ElectronicsGeek wrote:
Quick question, do you connect your calculator to the computer-side program using the global CALCnet client or do you use the bridge program?
The bridge program connects to gcnhub.cemetech.net and pretends to be a calculator. gcnclients also connect to the gCn hub with their own (real) calculators, and the bridge you create communicates with those calculators. The gCnClient program connects real calculators to globalCALCnet, and any gCn bridge you create (including Python ones) connects directly to the hub.
I'm finding the bridge extremely useful so far, thank you very much Kerm.

Quick question:

How can I turn the data from the calculator into readable ASCII text.

I have tried this:

Code:
cleanstr(thismsg)[:14]


However, it fails to create the desired result. Any ideas?
That's not what cleanstr() is for. Smile Take a look at the encode/decode convenience functions and see if they help at all. You'll probably want to use cleanstr() in conjunction with those.
Apparently calcdecode is not defined. Any reason why?
ElectronicsGeek wrote:
Apparently calcdecode is not defined. Any reason why?
Did you include the module for it properly? I can give you specific code for that when I get home later.
Kerm, have you sorted the code yet?

Thanks.
ElectronicsGeek wrote:
Kerm, have you sorted the code yet?

Thanks.
Did you try my answer above?
I think I used:


Code:
import calcencoder


But it said it wasn't defined.
You'd need something like:

Code:
from calcencoder import CalcEncoder
# ...
CalcEncoder.calcencode(stuff)
# ...
CalcEncoder.calcdecode(stuff)

If that doesn't work:
1) Make sure you're running your bridge from the same directory as calcencoder.py
2) You might need to add an __init__() method to the CalcEncoder class and instantiate it first.
Ah, I see. Thank you very much Kerm.
I'm having a few problems with the import.

The Error

Code:
Traceback (most recent call last):
  File "gcnskel.py", line 11, in <module>
    from calcencoder import CalcEncoder
ImportError: cannot import name CalcEncoder


------------------
(program exited with code: 1)
Press return to continue


CalcEncoder's Code:


Code:
def __init__(self):
   class CalcEncoder:
                # ....stuff.....
      # Encode ASCII into calculator-formatted strings
      def calcencode(self,input):
                    #stuff....

      # Decode calculator-formatted strings into ASCII
      def calcdecode(self,input):
                    #stuff....


Finally the import in my version of the gCn skeleton:


Code:
from calcencoder import CalcEncoder


Apologies for the massive post...
The CalcEncoder class's code should look something like this:


Code:
class CalcEncoder:
    # all the constants like x2t and t2x...
    def __init__(self):
        pass
    def calcencode(self,input):
        #stuff
    def calcdecode(self,input):
        #stuff
Don't copy-paste this, though, as I used spaces instead of tabs. Smile
Slight necropost here, but I have a question regarding gcnskel.py .

My question regards the function outtoclient:

Code:
def outtoclient(type,seq,contents,sid):
   gcnlock.acquire()
   msgindex = 0;
   thisoutmsg = chr(type) + chr(seq) + contents
   outmsghdr = chr(0xAA)+chr(0xAA)+chr(0xAA)+chr(0xAA)+chr(0xAA)+\
               chr(len(thisoutmsg)&0x00ff)+chr((len(thisoutmsg)>>8)&0x00ff)
   outmsghdr = outmsghdr + thisoutmsg
   log_info("Forwarding '"+outmsghdr+"' to '"+calc5to10(sid)+"'")
   thismsg = chr(255)+chr(137)+sid+outmsghdr+chr(42)
   thismsg = chr(len(thismsg)&0x00ff)+chr((len(thismsg)>>8)&0x00ff)+\
             'f'+thismsg
   clientsocket.sendall(thismsg)
   gcnlock.release()


I was generally wondering how one goes about using this function, such as how one might call it and what I should put as the parameters.

Thanks a lot Smile

Code:
def outtoclient(type,seq,contents,sid):
If you take a look at the body of the function, you can see how it works. It packs type, seq, and contents into a message, with one byte for type, one byte for seq, and len(contents) bytes for contents. It then constructs a message containing that body and sends it over gCn to the target with address sid. You can use the type and seq bytes for whatever you want, or you could just re-write this function to only pack the data in the contents parameter into the message.
So in essence, type and seq can be any byte and sid is the calculator's ID when it joins gCn?
ElectronicsGeek wrote:
So in essence, type and seq can be any byte and sid is the calculator's ID when it joins gCn?
That is correct. You will also get an SID from a calculator sending a request to your bridge, of course.
Having a slight problem with data transmission. Would you say my computer side code is off or is it the calc side code?

Calc Side:

Code:
sum(19,1
sum(18
Disp Str9
sum(19,0


Computer Side:

Code:
outtoclient(0x44,0x44,"Hello World",calc5)


This combination is returning BASIC Ex Err:UND (Code 519).

Cheers.
  
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