Python/SSC-32 Example

I couldn’t sleep, so got up and decided to fiddle with the SSC-32 and Python some more. I knew it had to be possible to read a response from the SSC-32 without having to depend on a serial port time out. I have done this many times with various languages. I defined a function to read characters from the SSC-32 until a CR is encountered and then return the result.

[code]#!/usr/bin/python

Import the Serial module

import serial;

Reads single characters until a CR is read

def Response(port):
ich = “”;
resp = “”;

    while (ich <> '\r'):
            ich = port.read(1);

            if (ich <> '\r'):
                    resp = resp + ich;
    return resp;

Open the port at 115200 Bps - defaults to 8N1

ssc32 = serial.Serial(’/dev/ttyS0’, 115200);

Send the version command

ssc32.write(“ver\r”);

Read the response

inp = Response(ssc32);

Show what we got back

print inp;

Close the port

ssc32.close();
[/code]
Notice the Response() function I defined at the top of the program. This function just reads a single character at a time from the serial port the SSC-32 is on until it reads a CR, and then stops and returns the result.

Python uses indenting to tell what statements are part of a block, so everything between the ‘while’ and the return statement is part of the ‘while’ block. Everything indented further than the ‘if’ is part of the ‘if’ block.

This program returns immediately after the last character of the SSC-32’s response has been read - when it reads a CR. There is no delay between sending the ‘ver’ command and getting the response now. :smiley:

Python and the Py-Serial addon is available for Windows, and GNU Linux and FreeBSD as well as most other operating systems. I can’t imagine it being any more difficult to talk to the SSC-32 from other languages, including Java. In fact, I think I will look into reproducing this example with Java. :slight_smile:

8-Dale

Here is my current Python code for controlling the SSC-32. I have written some new functions to encapsulate the serial module’s functionality and a couple conversion functions to enable writting code using degrees instead of raw uS. The new conversion functions allow wrtting code using degrees rather than raw uS. This code is written for WALTER.

[code]#!/usr/bin/python

Import the Serial module

import serial;

EOL = “\r”;
command = “”;
SSC32_Port = “/dev/ttyS0”;

LeftMChan = 0; # Left Motor channel
LeftMStop = 1520;

RightMChan = 1; # Right Motor channel
RightMStop = 1525;

PanChan = 2; # Pan servo channel
PanHome = 1530;
PanREnd = 2150;
PanLEnd = 900;

TiltChan = 3; # Tilt servo channel
TiltHome = 1430;
TiltUEnd = 500;
TiltDEnd = 1550;

Reads single characters until a CR is read

def Response (port):
ich = “”;
resp = “”;

while (ich <> '\r'):
	ich = port.read(1);
	
	if (ich <> '\r'):
		resp = resp + ich;
return resp;

Converts a servo position in degrees to uS for the SSC-32

def To_Degrees (uS):
result = 0;

result = (uS - 1500) / 10;

return result;

Converts an SSC-32 servo position in uS to degrees

def To_uS (degrees):
result = 0;

result = (degrees * 10) + 1500;

return result;

def Send_Command (port, cmd, sendeol):

result = port.write (cmd);

if (sendeol):
	port.write (EOL);

return result;

def Send_EOL (port):

result = port.write(EOL);

return result;

Open the port at 115200 Bps - defaults to 8N1

ssc32 = serial.Serial(SSC32_Port, 115200);

Motors All Stop - Left = Ch0, Right = Ch1

command = “#” + str(LeftMChan) + " P" + str(LeftMStop) + " #" + str(RightMChan) + " P" + str(RightMStop);
Send_Command (ssc32, command, True);

Home the PING Pan/Tilt Base

command = “#” + str(PanChan) + " P" + str(PanHome) + " #" + str(TiltChan) + " P" + str(TiltHome);
Send_Command (ssc32, command, True);

Send the version command

command = “ver”;
Send_Command (ssc32, command, False);
Send_EOL (ssc32);

Read the response

inp = Response(ssc32);

Show what we got back

print inp;

Close the port

ssc32.close();

Test the conversion functions

print "600 uS = “, To_Degrees(600), " degrees.”;
print "2400 uS = “, To_Degrees(2400), " degrees.”;
print "1500 uS = “, To_Degrees (1500), " degrees.”;

print "-90 degrees = “, To_uS(-90), " uS.”;
print "90 degrees = “, To_uS(90), " uS.”;
print "0 degrees = “, To_uS(0), " uS.”;[/code]

You can run this Python code on any OS that has a Python interpreter and the Python Serial module available by just changing the SSC_Port to whatever you OS uses.

8-Dale

I have added the Wait_for_Servos routine to wait until a servo move has completed. I am also starting to use my own routines within other routines. My goal is to create a Python library with my routines so all that needs to be done is "import to include my routines in a Python script.

[code]#!/usr/bin/python

Import the Serial module

import serial;

EOL = “\r”;
command = “”;

Set the SSC-32 port - “COM1:” for Windows, “/dev/ttyS0” for Linux

SSC32_Port = “/dev/ttyS0”;

LeftMChan = 0;
LeftMStop = 1520;

RightMChan = 1;
RightMStop = 1525;

PanChan = 2;
PanHome = 1530;
PanREnd = 2150;
PanLEnd = 900;

TiltChan = 3;
TiltHome = 1430;
TiltUEnd = 500;
TiltDEnd = 1550;

Reads single characters until a CR is read

def Response (port):
ich = “”;
resp = “”;

while (ich <> '\r'):
	ich = port.read(1);
	
	if (ich <> '\r'):
		resp = resp + ich;
return resp;

Converts a servo position in degrees to uS for the SSC-32

def To_Degrees (uS):
result = 0;

result = (uS - 1500) / 10;

return result;

Converts an SSC-32 servo position in uS to degrees

def To_uS (degrees):
result = 0;

result = (degrees * 10) + 1500;

return result;

Wait for a servo move to be completed

def Wait_for_Servos (port):

ich = "";

while (ich <> "."):
	Send_Command (port, "Q", True);
	
	ich = port.read(1);

return;

Send EOL to the SSC-32 to start a command executing

def Send_EOL (port):

result = port.write(EOL);

return result;

Send a command to the SSC-32 with or without an EOL

def Send_Command (port, cmd, sendeol):

result = port.write (cmd);

if (sendeol):
	Send_EOL (port);

return result;

Open the port at 115200 Bps - defaults to 8N1

ssc32 = serial.Serial(SSC32_Port, 115200);

Motors All Stop - Left = Ch0, Right = Ch1

command = “#” + str(LeftMChan) + " P" + str(LeftMStop) + " #" + str(RightMChan) + " P" + str(RightMStop);
Send_Command (ssc32, command, True);

Wait_for_Servos (ssc32);

Home the PING Pan/Tilt Base

command = “#” + str(PanChan) + " P" + str(PanHome) + " #" + str(TiltChan) + " P" + str(TiltHome);
Send_Command (ssc32, command, True);

Wait_for_Servos (ssc32);

Send the version command

command = “ver”;
Send_Command (ssc32, command, False);
Send_EOL (ssc32);

Read the response

inp = Response(ssc32);

Show what we got back

print inp;

command = “#” + str(PanChan) + “P1900” + “#” + str(TiltChan) + “P750 T5000”
Send_Command (ssc32, command, True);

Wait_for_Servos (ssc32);

Close the port

ssc32.close();

Test the conversion functions

print "600 uS = “, To_Degrees(600), " degrees.”;
print "2400 uS = “, To_Degrees(2400), " degrees.”;
print "1500 uS = “, To_Degrees (1500), " degrees.”;

print "-90 degrees = “, To_uS(-90), " uS.”;
print "90 degrees = “, To_uS(90), " uS.”;
print "0 degrees = “, To_uS(0), " uS.”;[/code]

The new Wait_for_Servos () routine works perfectly.

8-Dale

Note, for Windows you will also need the pyWin32 library which is available at Source Forge. Then just change the port to “COM1” or whatever port you have the SSC-32 plugged into and start experimenting. :slight_smile:

8-Dale

how does python compare to VB C++ because i was thinking of going MRSD to make it easier to change micros ???

I don’t know, sorry. I’ve never used VB C++

Python is FREE and you can get it for Windows. :smiley: Python is an interpreted language, not compiled.

8-Dale

C++ is a very low-level language. Very close to the operating system. For the uneducated its very daunting but very powerful. Also very dangerous as its one of the few languages that has enough access to the hardware to potentially damage it. If you master it thought the sky is the limit.

VB6 is a higher level language, very friendly and very much used. Its much slower than C++ as its not a true compiled language but its very much aimed at the less experienced programmer. In many cases the syntax is much like speaking English. With the use of ActiveX etc it is though very powerful.

VB.Net, C#.Net and all the new microsoft products level the field a bit.
They all compile to a common code that is then run as you executable. In fact both VB.Net and C#.Net a now more like Java than many would like.

The .Net Framework is very powerful and wide ranging but for the beginner it can be a minefield as there is so much there to learn.

One particular thing that has reared its head in both my work and robotics as my hobby is that under VB6, it was easy to write fairly efficient comms code. Sometimes it was a bit quirky but nothing to stop the game. .NET Framework 1.0 didn’t have a comms library but not a problem, there were plenty availableto download or you could re-use your old VB6 code.

Under .NET 2.0 Framework they have implemented a class called SerialPort which has a wealth of commands. Unfortunately it has been ‘updated’ and uses Unicode rather than 8 bit ASCII. This means not 8 bit Bytes can be sent. By default it sends 2 Bytes for each character. There is a work-around but it took some searching on Microsofts ever growing problems pages. Unfortunately it can only be fixed on the Windows platform. It cannot be fixed on the PocketPC, CE or Windows Mobile .Net platform.

Python was never intended to be a fully fledged language like VB etc as the IDE requires as much debugging as the language interpretter itself. It was initially a scripted language. Still very powerful as it could sit alongside pretty much any application without having to install too much extra software. There are I believe now IDE’s for Python but the level of syntax checking is not as much as VB etc…

If you want to try VB the the .NET Express products are good although certain functions are not available to the free version.

Sorry if its a bit lengthy but at the end of the day, there are so many languages now, each almost as capable as the other. I’ve seen some very powerful applications written in some of the so called simpler languages (and some really stupid ones in the most powerful). It becomes a matter of choice and cost…

BTW… one major advantage of Python, like Java it is one of the few that can work on any platform, i.e. Linux, Unix, Solaris MacOSX etc. If its say Microsoft then its Windows only…

I’ve done several years as a C programmer, but have not done much with C++. I used to have to deal with pointers 4 levels deep, which usually gave me a headache at the end of the day.

Actually, Python is a full features opject oriented interpreted language. However, you don’t have to use the object oriented features to do useful things with Python. Python can be used for simple scripting or full fledged applications, and I have used it in both ways. I wrote a 2500+ line Python application which is a sysadmin tool I used on FreeBSD that had a small command language built in to allow me to do common tasks easier and quicker as well as via scheduled jobs. I had it parsing out all the information from the FreeBSD Ports collection and was at the stage where I could stuff it all into a database when I stopped working on it.

Typically, the errors that Python throws out are more useful than a lot of the messages Microsoft development languages toss at you. :smiley: At least that has been my experience to date, but I have not spent much time (no more than necessary) with current MS languages.

I’ve considered trying out the newer Microsoft development languages several times, but then I come to my senses when I realize whatever I would create would not likely be very portable.

Yes, and that has usually been the problem I have with Microsoft development tools and why I cringe when I consider using them. I have to say though, what little I have checked out of things like VC# and VB looks quite nice and I would have to seriously consider them if I wanted to write code just for Windows.

I have in fact run my Python SSC-32 code on FreeBSD, Linux, and Windows with only one modification (changing the port string). Also, under Windows, the Python serial and parallel additions also require the pywin32 module. Under Linux and FreeBSD, only the serial and parallel modules themselves are required and I only use the serial module at present.

8-Dale

Hi folks,

My first post on the forum, hurray :slight_smile:

Anyways, I thought I’d just say thanks to linuxguy, as I hadn’t seen any. I am a dedicated user of linux, and will find your work helpful!

Yes, indeed, youe can get into big trouble fast with C/C++ if you are not careful. Pointers are a big stumbling block and problem point for many. I actually have used C++, but not VB. I had to deal with pointers four levels deep when I was programming professionally in C. That gave me big headaches more than once.

My completely biased :slight_smile: opinion is that if I can’t transport my code between platforms with very minimal changes required to make it work, the development software, or at least the components, will not be useful to me. For instance, there is the QT framework by Trolltech, which has versions for all major platforms - it’s the base for KDE (K Desktop Environment), very popular and the most Windows like environment (and different in all the right places) for Linux/*NIX. If I ever do any serious development for Windows, it will be with something like QT or similar.

8-Dale

Welcome! :smiley:

I am glad you find my work useful. :smiley: There will be more!

8-Dale

Since this thread saw some recent posts, I just want to add C++ is not a low level language at all! It is a very high level language, which happens to also interpret as well as inline some lower level items as well.

Having just done a 12 hour, 350+ line project for an assembly programing tutorial (the program does really simple string parcing stuff), this bothered me a little more than it should. :blush: The same thing in C99 (between ANSI C and C++) took me 5 minutes and less than 20 lines.

I can call an assembly routine from Java or Ada too (and if I do enough work to manually index the memory addresses break things exactly the same way), that doesn’t make them any lower level languages. I actually like the way C++ lets you use pointers and other lower-level concepts instead of trying to force you to use classes since OOP isn’t the be all and end all of programing, and makes the language much more flexible, faster, and useful.

Anyway…sorry for the hijack/ rant.

I have done a little programing in assembler and know that it is pretty much as low level as it gets. :confused:

Howdy folks!

I went away with the initial python code you were using, and created a multi-threaded TCP relay server (or whatever it needs to be called!). Basically it’ll listen on a port, receive commands, and pass them on to the SSC32. At the same time, there’s a thread devoted to polling the SSC32 for return values, which if found, are sent to all clients connected to the server.

It’s a bit of a weird model, but it was fun coding it :slight_smile: This is a first pass towards a greater goal. I eventually intend to create an RPC system with a nice API for the SSC32, so that for instance, you call getAnalogReading(‘A’) returns a value, but over a transparent network layer.

I’ll post a link to the code as soon as I have met the critiria for being allowed to :slight_smile:

UPDATE: Here it is: midget.evilbyte.org/pyssc32/

Any comments/criticism is welcome, and if anyone is willing to try it on windows, I’d be curious to know how it goes!

Cheers!

Its all a matter perspective. You are right in that relative to the hardware and how assembly works it is very high level but relative to the Operating System its as low as it can get. You can’t execute a lower level of code without removing or disabling the O.S. Its what the O.S. was written with.

In this perspective VB and C# are orbital.

We are going way off topic here, and this is a sticky. I’d prefer to keep this just about Python/SSC-32 and my Python/SSC-32 code as much as possible. :smiley:

8-Dale

Actually, I believe it bores down to how you use it. C++ was built to maintain as much functionality of C as possible without syntax changes, whilst adding higher-level (Object-Oriented) functionality.

For this reason, you can do (almost) anything in C++ that you can in C, and much more. Both C and C++ can inline assembly. C++ just offers higher-level features, but it cant be said that it’s “as low as it can get”. That would be binary executable code.

Considering my original statement was made because cbradsmith asked a question comparing VB, C++ and Python, I thought my answer, although long-winded was a reasonable, non-technical answer to what you expert programmers know only too well is an extremely complex and somewhat company political problem.

Within the context of the question, even after re-reading the thread, I think I was as accurate as was needed. It couild have been punctuated and spelt better and a spell check might have helped.

Yes there are lower level languages, but the question didnt encompass them.

My apologies linuxguy for hi-jacking your thread…

Hello, I’ve put together some code for controlling the SSC32 with Python

It has 2 “functions”:

  1. “interactive” gets key presses and executes predefined commands (eg, press 8 on numpad to start moving forward sequence)
  2. “shell mode” standard terminal where you can enter commands manually to SSC32, the little difference is when issuing an analog voltage check (eg, VA) it can return the actual voltage measured or the 8 bit binary value.

I’ve implemented a time function as well to monitor time between keypresses in “interactive” mode (you can save them to a file and run previously recorded movements)

Any toughts/improvements are more than welcome since this is my first ever python script :laughing: (tested under windows)

**I’ve added a modified version that can read and playback previously recorded keystrokes. **
Any ideea on how can I define some functions that gets called at “#do whatever you want to do when…]” code ? :slight_smile:

#!/usr/bin/python
# Lynxmotion SSC32 Python interface
# by rakware @2008, mail stuff to cacatpunctro at yahoo dot com
# serial module from http://pyserial.wiki.sourceforge.net/pySerial
# _Getch class from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892
# please change the com port to suit your needs.
# WARNING! : code provided "AS IS", use at your own risk.

import time
import serial

class _Getch:
    def __init__(self):
        try:
            self.impl = _GetchWindows()
        except ImportError:
            self.impl = _GetchUnix()

    def __call__(self): return self.impl()


class _GetchUnix:
    def __init__(self):
        import tty, sys

    def __call__(self):
        import sys, tty, termios
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch


class _GetchWindows:
    def __init__(self):
        import msvcrt

    def __call__(self):
        import msvcrt
        return msvcrt.getch()


getch = _Getch()

ser = serial.Serial(port='COM1', baudrate=115200, timeout=None)
ser.open()
ser.isOpen()

#to do: add SerialException with error message if port could not be open

print 'Lynxmotion SSC32 Python interface'
print 'Connected to: ', ser.portstr
print "Press 'ESC' to quit or 'F1' to enter shellmode"

while 1:
	char = getch()
	if char == chr(27): #27 is ESC

		ser.close()
		movementr.close()
		movementa.close()
		runtimew.close()
		runtimer.close()
		exit()
	elif char == chr(13):
		print
	elif char == chr(59): #59 is F1
		print "Type 'quit' to return"
		while 1:
			firmware = ''
			ser.write('ver\r\n')
			time.sleep(0.05)
			while ser.inWaiting() > 0:
				firmware += ser.read()
			if firmware == '': firmware = 'ver'
	
			input = raw_input(firmware.strip() + ' >>>')

			if input == 'quit':
				print "Press 'ESC' to quit or 'F1' to enter shellmode"
				break

			elif input == 'va':
				ser.write(input + '\r\n')
				out = ''
				time.sleep(0.05)
				while ser.inWaiting() > 0:
					out += ser.read()
			
				if out != '':
					#print round(ord(out) *5/256.0, 3)
					print ord(out)

			elif input == 'vb':
				ser.write(input + '\r\n')
				out = ''
				time.sleep(0.05)
				while ser.inWaiting() > 0:
					out += ser.read()
			
				if out != '':
					#print round(ord(out) *5/256.0, 3)
					print ord(out)

			elif input == 'vc':
				ser.write(input + '\r\n')
				out = ''
				time.sleep(0.05)
				while ser.inWaiting() > 0:
					out += ser.read()
			
				if out != '':
					#print round(ord(out) *5/256.0, 3)
					print ord(out)

			elif input == 'vd':
				ser.write(input + '\r\n')
				out = ''
				time.sleep(0.05)
				while ser.inWaiting() > 0:
					out += ser.read()
			
				if out != '':
					#print round(ord(out) *5/256.0, 3)
					print ord(out)

			elif input == 'va vb':
				ser.write(input + '\r\n')
				out = ''
				time.sleep(0.05)
				while ser.inWaiting() > 0:
					out += ser.read()
			
				if out != '':
					print ord(out:1]), ord(out[1:2])

			elif input == 'va vb vc':
				ser.write(input + '\r\n')
				out = ''
				time.sleep(0.05)
				while ser.inWaiting() > 0:
					out += ser.read()
			
				if out != '':
					print ord(out:1]), ord(out[1:2]), ord(out[2:3])

			elif input == 'va vb vc vd':
				ser.write(input + '\r\n')
				out = ''
				time.sleep(0.05)
				while ser.inWaiting() > 0:
					out += ser.read()
			
				if out != '':
					print ord(out:1]), ord(out[1:2]), ord(out[2:3]), ord(out[3:4])

			elif input != '':
				ser.write(input + '\r\n')
				out = ''
				time.sleep(0.05)
				while ser.inWaiting() > 0:
					out += ser.read()
				if out != '':
					print out

	elif char == chr(60):
		movementr = open("movement.txt", "r")
		savedmovement = movementr.read()
		print 'starting playback from', movementr
		for fileLine in savedmovement.split('\r\n'):
			if fileLine[2:] != '':
				time.sleep(float(fileLine[2:]))
   				#print fileLine[2:], fileLine:1]
				if fileLine:1] == '8':
					ser.write('a\r\n') #do whatever you want to do when reads key 8
					out = ''
					print out
				elif fileLine:1] =='4':
					ser.write('b\r\n') #do whatever you want to do when reads key 4
					out = '' #can be removed if no serial output is to be received
					time.sleep(0.05) #can be removed if no serial output is to be received
					while ser.inWaiting() > 0: #can be removed if no serial output is to be received
						out += ser.read() #can be removed if no serial output is to be received

					if out != '': #can be removed if no serial output is to be received
						print out #can be removed if no serial output is to be received
		print 'end of playback'

	elif char == chr(56):
		#to do: stop current movement go to idle
		ser.write('a\r\n') #do whatever you want to do when you press key 8
		out = ''
		time.sleep(0.05)
		while ser.inWaiting() > 0:
			out += ser.read()
		print out
		print char,

		#print str(round(time.clock(), 2))
		currentclock = str(round(time.clock(), 2))

		runtimew = open("runtime.txt", "w")
		runtimew.write(str(round(time.clock(), 2)))

		runtimer = open("runtime.txt", "r")
		savedclock = runtimer.read()

		if savedclock == '': savedclock = '0.00'
		timebetweenkeys = float(currentclock) - float(savedclock)
		print timebetweenkeys #time between key presses
		
		runtimew = open("runtime.txt", "w")
		runtimew.write(str(round(time.clock(), 2)))
		
		movementa = open("movement.txt", "a")
		movementa.write(str(char))
		movementa = open("movement.txt", "a")
		movementa.write(' ')
		movementa = open("movement.txt", "a")
		movementa.write(str(timebetweenkeys))
		movementa = open("movement.txt", "a")
		movementa.write('\r\n')


	elif char == chr(52):
		#to do: stop current movement go to idle
		ser.write('a\r\n') #do whatever you want to do when you press key 4
		out = ''
		time.sleep(0.05)
		while ser.inWaiting() > 0:
			out += ser.read()
		print out
		print char,

		#print str(round(time.clock(), 2))
		currentclock = str(round(time.clock(), 2))

		runtimew = open("runtime.txt", "w")
		runtimew.write(str(round(time.clock(), 2)))

		runtimer = open("runtime.txt", "r")
		savedclock = runtimer.read()

		if savedclock == '': savedclock = '0.00'
		timebetweenkeys = float(currentclock) - float(savedclock)
		print timebetweenkeys #time between key presses
		
		runtimew = open("runtime.txt", "w")
		runtimew.write(str(round(time.clock(), 2)))
		
		movementa = open("movement.txt", "a")
		movementa.write(str(char))
		movementa = open("movement.txt", "a")
		movementa.write(' ')
		movementa = open("movement.txt", "a")
		movementa.write(str(timebetweenkeys))
		movementa = open("movement.txt", "a")
		movementa.write('\r\n')

Hey, new to the forum as am using the SSC-32 for a project to control various servos for a robotic arm. I had originally written a program in Python that would control a USB servo device, however we saw too many benefits to the SSC-32 to be ignored. Now that I’m using this serial board, I’m attempting to at least get the read out as you described above, and a little background I’m using a USB-Serial interface.

As such, I found my USB-Serial(SSC-32) to be connected at /dev/TTYUSB0 and set it as such in the program you described, here is a copy of what I ran below. The problem that I am encountering is that once I run the below script in terminal, nothing happens. The terminal appears suspended and I can keyboard interrupt out of it, but I’m not getting any output. Do you know what the problem may be?

**Sorry to resurrect this old thread, it’s just one of the only threads I could find on beginning Python for Serial SSC-32 on Google

#!/usr/bin/python

Import the Serial module

import serial;

Reads single characters until a CR is read

def Response(port):
ich = “”;
resp = “”;

    while (ich <> '\r'):
            ich = port.read(1);

            if (ich <> '\r'):
                    resp = resp + ich;
    return resp;

Open the port at 115200 Bps - defaults to 8N1

ssc32 = serial.Serial(’/dev/ttyUSB0’, 115200);

Send the version command

ssc32.write(“ver\r”);

Read the response

inp = Response(ssc32);

Show what we got back

print inp;

Close the port

ssc32.close();