Read serial port data from a Digi ConnectPort and send

This is the place for queries that don't fit in any of the other categories.

Read serial port data from a Digi ConnectPort and send

Postby Fayezbee » Wed Mar 26, 2014 11:17 am

Hi all,

I am extremely new to Python but discovered that I need it in order to programme my Digi ConnectPort TS1W MEI gateway. What I want to do is read from the serial port periodically then send this data wirelessly to the nearest access point. What I have started with is trying to open, read, write and close the serial port, and I have found the following sample code online:

Code: Select all
  try:
    serfd = os.open( '/com/0', os.O_RDWR | os.O_NONBLOCK)
  except:
    ( ... handle port in use or invalid name ... )

  try:
    data = os.read( serfd, max_bytes)
 
  except OSError, e:
    if( e.errno == errno.EAGAIN):  # EAGAIN just means NO data ready, try again
      ( ... handle NO data received or response timeout here ... )
 
    else: # other errors
      ( ... handle port faults - likely fatal ... )
      traceback.print_exc() # make sure you show the user what error was

  try:
    count = os.write( serfd, data)
  except:
    ( ... handle port faults - likely fatal ... )

   try:
    os.close( serfd)
  except:
    pass # ignore errors here


Would anyone be able to give me any tips on how to complete the script that I would need to carry out the simple process that I've mentioned? Or if anyone could point to the place I could find some helpful sample code, as my Google searches have not yet proved to be very fruitful. Cheers
Last edited by Yoriz on Wed Mar 26, 2014 1:03 pm, edited 1 time in total.
Reason: First post lock.
Fayezbee
 
Posts: 3
Joined: Wed Mar 26, 2014 11:08 am

Re: Read serial port data from a Digi ConnectPort and send

Postby Yoriz » Wed Mar 26, 2014 12:56 pm

Hi welcome to the forum, please if you have not already, read the new users read this link in my signature.
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Yoriz
 
Posts: 1671
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Read serial port data from a Digi ConnectPort and send

Postby Fayezbee » Thu Mar 27, 2014 3:23 pm

Ok, so I've got something interesting:

https://www.dropbox.com/sh/1yq4x09xi5w4dsm/CuuZCIjwRT

But it doesn't work. Error message states:

Code: Select all
Traceback (most recent call last):
File “WEB/python/serial_loopback.py”, line 28,
in ? import serial.
Import Error: No module named serial.

when I ran the command:

python serial_loopback.py


Any ideas anyone?
Fayezbee
 
Posts: 3
Joined: Wed Mar 26, 2014 11:08 am

Re: Read serial port data from a Digi ConnectPort and send

Postby stranac » Thu Mar 27, 2014 4:02 pm

You need to install pyserial.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

Re: Read serial port data from a Digi ConnectPort and send

Postby Fayezbee » Thu Mar 27, 2014 4:31 pm

But do you have any idea how I might do that using the gateway hardware? I'm assuming that's what you meant by your answer.
Fayezbee
 
Posts: 3
Joined: Wed Mar 26, 2014 11:08 am


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot] and 4 guests